def unassign(self, username): if self.baseid == BASE_GROUPNAME and self.__parent__: # for viewers group, critical that we unassign all groups for user other_groups = filter( lambda g: g is not self, self.__parent__.groups.values() ) for group in other_groups: if username in group.keys(): group.unassign(username) msg = '%s removed from workgroup roster in workspace "%s"' % ( username, self.context.Title(), ) else: msg = 'Removed user %s from group %s in workspace "%s"' % ( username, self.baseid, self.context.Title(), ) log_status(msg, self.context) username = self.applyTransform(username) if username not in self.keys(): raise ValueError('user %s is not group member' % username) self._group.unassign(username) self.refresh() # need to invalidate keys -- membership modified.
def _log(self, msg, level=logging.INFO): """ Log with prefix to application log. Prefix includes view name, site name, context path, username Timestamps are not in prefix, included by logging framework. Example prefix: WorkspaceMembership: [mysite] /mysite/a/b ([email protected]) -- """ log_status(msg, self.context, level=level)
def add(self, username): msg = '' username = self.applyTransform(username) if username not in self.site_members: raise RuntimeError('User %s unknown to site' % username) if username not in self.keys(): self._group.assign(username) user = self.site_members.get(username) fullname = user.getProperty('fullname', '') basemsg = u'Added user %s (%s) to' % ( username, fullname, ) if not self.__parent__: msg = '%s workspace "%s".' % ( basemsg, self.context.Title(), ) else: msg = '%s %s role group in "%s".' % ( basemsg, self.title, self.context.Title() ) if self.__parent__: if username not in self.__parent__: msg = ( 'User %s not allowed in "%s" ' 'without workgroup membership' % ( username, self.baseid )) log_status(msg, self.context, level=logging.ERROR) raise RuntimeError(msg) else: # viewers/base group: parent_workspace = workspace_for(self.context.__parent__) if parent_workspace: parent_roster = WorkspaceRoster(parent_workspace) parent_roster.add(username) if msg: log_status(msg, self.context) self.refresh(username) # invalidate keys -- membership modified.
def _log(self, msg, level=logging.INFO): log_status(msg, self.context, level=level)