def test_workspace_for(self): from collective.teamwork.utils import workspace_for path = 'project1/team1/stuff' content = self.portal.unrestrictedTraverse(path) workspace_expected = self.portal['project1']['team1'] assert self.same(workspace_for(content), workspace_expected) assert self.same(IWorkspaceContext(content), workspace_expected)
def test_workspace_for(self): from collective.teamwork.utils import workspace_for path = "project1/team1/stuff" content = self.portal.unrestrictedTraverse(path) workspace_expected = self.portal["project1"]["team1"] assert self.same(workspace_for(content), workspace_expected) assert self.same(IWorkspaceContext(content), workspace_expected)
def test_utility_view(self): from collective.teamwork.utils import make_request from collective.teamwork.utils import WorkspaceUtilityView from collective.teamwork.utils import workspace_for, project_for request = make_request() path = 'project1/team1/stuff' content = self.portal.unrestrictedTraverse(path) view = WorkspaceUtilityView(content, request) assert isinstance(view(), str) # calling returns string label assert self.same(view.workspace(), workspace_for(content)) assert self.same(view.workspace(), IWorkspaceContext(content)) assert self.same(view.project(), project_for(content)) assert self.same(view.project(), IProjectContext(content))
def test_utility_view(self): from collective.teamwork.utils import make_request from collective.teamwork.utils import WorkspaceUtilityView from collective.teamwork.utils import workspace_for, project_for request = make_request() path = "project1/team1/stuff" content = self.portal.unrestrictedTraverse(path) view = WorkspaceUtilityView(content, request) assert isinstance(view(), str) # calling returns string label assert self.same(view.workspace(), workspace_for(content)) assert self.same(view.workspace(), IWorkspaceContext(content)) assert self.same(view.project(), project_for(content)) assert self.same(view.project(), IProjectContext(content))
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.