Ejemplo n.º 1
0
 def test_get_workspaces(self):
     from collective.teamwork.utils import get_workspaces
     project1 = self.portal['project1']
     # test without context, without site
     workspaces = get_workspaces()
     assert len(workspaces) == 5
     # test sort order, items closest to root first
     assert self.same(workspaces[0], project1)
     assert all(
         map(lambda o: IWorkspaceContext.providedBy(o), workspaces)
         )
     # after first two workspaces, remainder are not projects
     assert all(
         map(lambda o: not IProjectContext.providedBy(o), workspaces[2:])
         )
     _path = lambda o: o.getPhysicalPath()
     assert len(_path(workspaces[2])) > len(_path(workspaces[0]))
     # test without context, passing site
     found = get_workspaces()
     assert len(found) == len(workspaces)
     for workspace in found:
         assert workspace in workspaces
     # test with context
     contained_workspaces = get_workspaces(project1)
     assert len(contained_workspaces) == 3
Ejemplo n.º 2
0
 def _workspace_end(self):
     if HAS_WORKSPACES:
         workspaces = get_workspaces(self.context)
         for workspace in reversed(workspaces):
             end = getattr(aq_base(workspace), "end", None)
             if isinstance(end, datetime.date):
                 return end
     return None
Ejemplo n.º 3
0
def all_workspace_users(site):
    """return a set of all workspace users"""
    r = set()
    all_workspaces = get_workspaces(site)
    for workspace in all_workspaces:
        roster = IWorkspaceRoster(workspace)
        r.update(roster.keys())
    return r
Ejemplo n.º 4
0
 def _workspace_end(self):
     if HAS_WORKSPACES:
         workspaces = get_workspaces(self.context)
         for workspace in reversed(workspaces):
             end = getattr(aq_base(workspace), 'end', None)
             if isinstance(end, datetime.date):
                 return end
     return None
Ejemplo n.º 5
0
def all_workspace_users(site):
    """return a set of all workspace users"""
    r = set()
    all_workspaces = get_workspaces(site)
    for workspace in all_workspaces:
        roster = IWorkspaceRoster(workspace)
        r.update(roster.keys())
    return r
Ejemplo n.º 6
0
    def test_get_workspaces(self):
        from collective.teamwork.utils import get_workspaces

        project1 = self.portal["project1"]
        # test without context, without site
        workspaces = get_workspaces()
        assert len(workspaces) == 5
        # test sort order, items closest to root first
        assert self.same(workspaces[0], project1)
        assert all(map(lambda o: IWorkspaceContext.providedBy(o), workspaces))
        # after first two workspaces, remainder are not projects
        assert all(map(lambda o: not IProjectContext.providedBy(o), workspaces[2:]))
        _path = lambda o: o.getPhysicalPath()
        assert len(_path(workspaces[2])) > len(_path(workspaces[0]))
        # test without context, passing site
        found = get_workspaces()
        assert len(found) == len(workspaces)
        for workspace in found:
            assert workspace in workspaces
        # test with context
        contained_workspaces = get_workspaces(project1)
        assert len(contained_workspaces) == 3
Ejemplo n.º 7
0
 def test_get_projects(self):
     from collective.teamwork.utils import get_projects, get_workspaces
     from zope.component.hooks import getSite
     assert self.same(getSite(), self.portal)
     assert len(get_projects()) < len(get_workspaces())
     assert len(get_projects()) == len(get_projects(self.portal))
     assert len(get_projects()) == 2
     isproject = lambda o: IProjectContext.providedBy(o)
     for project in get_projects():
         assert isproject(project)
     found = get_projects()
     for project in filter(isproject, self.portal.objectValues()):
         assert project in found
Ejemplo n.º 8
0
    def test_get_projects(self):
        from collective.teamwork.utils import get_projects, get_workspaces
        from zope.component.hooks import getSite

        assert self.same(getSite(), self.portal)
        assert len(get_projects()) < len(get_workspaces())
        assert len(get_projects()) == len(get_projects(self.portal))
        assert len(get_projects()) == 2
        isproject = lambda o: IProjectContext.providedBy(o)
        for project in get_projects():
            assert isproject(project)
        found = get_projects()
        for project in filter(isproject, self.portal.objectValues()):
            assert project in found
Ejemplo n.º 9
0
def handle_workspace_removal(context, event):
    """Handler for IObjectRemovedEvent on a workspace"""
    site = getSite()
    if site is None:
        return  # in case of recursive plone site removal, ignore
    pasgroups = ISiteMembers(site).groups
    roster = WorkspaceRoster(context)
    for group in roster.groups.values():
        groupname = group.pas_group()[0]
        if groupname in pasgroups:
            pasgroups.remove(groupname)
    # remove group names for nested workspaces (also, by implication,
    #   removed from the PAS group manager plugin).
    for workspace in get_workspaces(context):
        handle_workspace_removal(workspace, event=event)
Ejemplo n.º 10
0
def handle_workspace_removal(context, event):
    """Handler for IObjectRemovedEvent on a workspace"""
    site = getSite()
    if site is None:
        return  # in case of recursive plone site removal, ignore
    pasgroups = ISiteMembers(site).groups
    roster = WorkspaceRoster(context)
    for group in roster.groups.values():
        groupname = group.pas_group()[0]
        if groupname in pasgroups:
            pasgroups.remove(groupname)
    # remove group names for nested workspaces (also, by implication,
    #   removed from the PAS group manager plugin).
    for workspace in get_workspaces(context):
        handle_workspace_removal(workspace, event=event)
Ejemplo n.º 11
0
 def unassign(self, username, role=None):
     username = self.applyTransform(username)
     recursive = role is None or role == 'viewers'
     groups = self.groups.values() if recursive else [self.groups.get(role)]
     if recursive:
         contained = get_workspaces(self.context)
         for workspace in contained:
             roster = interfaces.IWorkspaceRoster(workspace)
             if username in roster:
                 # though sub-optimal, a roster check avoids race condition
                 # on flat workspace enumeration vs. recursive walking.
                 roster.unassign(username)
     for group in groups:
         if username in group.keys():
             group.unassign(username)
     self.refresh(username)
Ejemplo n.º 12
0
 def unassign(self, username, role=None):
     username = self.applyTransform(username)
     recursive = role is None or role == 'viewers'
     groups = self.groups.values() if recursive else [self.groups.get(role)]
     if recursive:
         contained = get_workspaces(self.context)
         for workspace in contained:
             roster = interfaces.IWorkspaceRoster(workspace)
             if username in roster:
                 # though sub-optimal, a roster check avoids race condition
                 # on flat workspace enumeration vs. recursive walking.
                 roster.unassign(username)
     for group in groups:
         if username in group.keys():
             group.unassign(username)
     self.refresh(username)
Ejemplo n.º 13
0
def handle_workspace_pasted(context, event, original_path):
    """handle IObjectAddedEvent after a copy/paste opertion"""
    create_workspace_groups_roles(context)
    for workspace in get_workspaces(context):
        create_workspace_groups_roles(workspace)
Ejemplo n.º 14
0
def handle_workspace_pasted(context, event, original_path):
    """handle IObjectAddedEvent after a copy/paste opertion"""
    create_workspace_groups_roles(context)
    for workspace in get_workspaces(context):
        create_workspace_groups_roles(workspace)