Ejemplo n.º 1
0
 def __init__(self,
              context,
              parent=None,
              groupid=u'',
              title=u'',
              description=u'',
              namespace=u'',
              roles=(),
              members=None,
              **kwargs):
     if not IWorkspaceContext.providedBy(context):
         raise ValueError('Could not adapt: context not a workspace')
     schema = interfaces.IWorkspaceGroup
     if schema.providedBy(parent):
         self.__parent__ = parent
     self.context = context
     self.adapts_project = IProjectContext.providedBy(context)
     valid_setattr(self, schema['baseid'], _decode(groupid))
     valid_setattr(self, schema['title'], _decode(title))
     valid_setattr(self, schema['description'], _decode(description))
     valid_setattr(self, schema['namespace'], _decode(namespace))
     self.portal = getSite()
     self.site_members = members or interfaces.ISiteMembers(self.portal)
     groups = Groups(self.portal)
     groupname = self.pas_group()[0]
     if groupname not in groups:
         groups.add(groupname)  # edge-case: may cause write-on-read
     self._group = GroupInfo(groupname, members=self.site_members)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
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.º 4
0
 def __init__(self,
              context,
              parent=None,
              groupid=u'',
              title=u'',
              description=u'',
              namespace=u'',
              roles=(),
              members=None,
              **kwargs):
     if not IWorkspaceContext.providedBy(context):
         raise ValueError('Could not adapt: context not a workspace')
     schema = interfaces.IWorkspaceGroup
     if schema.providedBy(parent):
         self.__parent__ = parent
     self.context = context
     self.adapts_project = IProjectContext.providedBy(context)
     valid_setattr(self, schema['baseid'], _decode(groupid))
     valid_setattr(self, schema['title'], _decode(title))
     valid_setattr(self, schema['description'], _decode(description))
     valid_setattr(self, schema['namespace'], _decode(namespace))
     self.portal = getSite()
     self.site_members = members or interfaces.ISiteMembers(self.portal)
     groups = Groups(self.portal)
     groupname = self.pas_group()[0]
     if groupname not in groups:
         groups.add(groupname)  # edge-case: may cause write-on-read
     self._group = GroupInfo(groupname, members=self.site_members)
Ejemplo n.º 5
0
 def test_interfaces(self):
     """Test any interface bindings configured on content"""
     from collective.teamwork.content import Workspace, Project
     from collective.teamwork.content.interfaces import IProject
     from collective.teamwork.content.interfaces import IWorkspace
     from collective.teamwork.interfaces import IWorkspaceContext
     from collective.teamwork.interfaces import IProjectContext
     assert issubclass(IProject, IProjectContext)
     assert issubclass(IProject, IWorkspaceContext)
     assert issubclass(IProject, IWorkspace)
     assert issubclass(IWorkspace, IWorkspaceContext)
     assert IWorkspaceContext.providedBy(Project('project'))
     assert IWorkspaceContext.providedBy(Workspace('team'))
     assert IProjectContext.providedBy(Project('project'))
     assert IWorkspace.providedBy(Project('project'))
     assert IWorkspace.providedBy(Workspace('team'))
     assert IProject.providedBy(Project('project'))
Ejemplo n.º 6
0
 def __init__(self, context, request):
     if not IWorkspaceContext.providedBy(context):
         raise ValueError('Context not a workspace')
     self.context = context
     self.request = request
     self.portal = getSite()
     self._members = ISiteMembers(self.portal)
     self._roster = IWorkspaceRoster(self.context)
     self._mtool = getToolByName(self.portal, 'portal_membership')
     self._secmgr = None
Ejemplo n.º 7
0
 def __init__(self, context, request):
     if not IWorkspaceContext.providedBy(context):
         raise ValueError('Context not a workspace')
     self.context = context
     self.request = request
     self.portal = getSite()
     self._members = ISiteMembers(self.portal)
     self._roster = IWorkspaceRoster(self.context)
     self._mtool = getToolByName(self.portal, 'portal_membership')
     self._secmgr = None
Ejemplo n.º 8
0
 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))
Ejemplo n.º 9
0
 def getAllLocalRolesInContext(self, object):
     rolemap = {}
     workspace = None
     for obj in self._parent_chain(object):
         for provider in self._getAdapters(obj):
             iter_roles = provider.getAllRoles()
             for principal, roles in iter_roles:
                 if workspace:
                     # seen previous workspace, don't inherit some roles
                     roles = filter_roles(roles)
                 rolemap.setdefault(principal, set()).update(roles)
         if IWorkspaceContext.providedBy(obj):
             workspace = obj  # mark ws as seen before looking at parents
     return rolemap
Ejemplo n.º 10
0
 def getAllLocalRolesInContext(self, object):
     rolemap = {}
     workspace = None
     for obj in self._parent_chain(object):
         for provider in self._getAdapters(obj):
             iter_roles = provider.getAllRoles()
             for principal, roles in iter_roles:
                 if workspace:
                     # seen previous workspace, don't inherit some roles
                     roles = filter_roles(roles)
                 rolemap.setdefault(principal, set()).update(roles)
         if IWorkspaceContext.providedBy(obj):
             workspace = obj  # mark ws as seen before looking at parents
     return rolemap
Ejemplo n.º 11
0
 def __init__(self, context, request):
     _WS_KEY = '_teamwork_workspace_%s' % context.getId()
     self.context = context
     self.request = request
     self.secmgr = None  # too early to get security manager in ctor
     self.annotations = IAnnotations(request)
     self.workspace = self.annotations.get(_WS_KEY, _marker)
     if self.workspace is _marker:
         if not IContentish.providedBy(context):
             # site root or plone.schemaeditor.interfaces.ISchemaContext
             self.annotations[_WS_KEY] = self.workspace = None
             return
         if IWorkspaceContext.providedBy(context):
             self.annotations[_WS_KEY] = self.workspace = self.context
         else:
             self.annotations[_WS_KEY] = self.workspace = queryAdapter(
                 self.context,
                 IWorkspaceContext,
                 )
Ejemplo n.º 12
0
 def __init__(self, context, request):
     _WS_KEY = '_teamwork_workspace_%s' % context.getId()
     self.context = context
     self.request = request
     self.secmgr = None  # too early to get security manager in ctor
     self.annotations = IAnnotations(request)
     self.workspace = self.annotations.get(_WS_KEY, _marker)
     if self.workspace is _marker:
         if not IContentish.providedBy(context):
             # site root or plone.schemaeditor.interfaces.ISchemaContext
             self.annotations[_WS_KEY] = self.workspace = None
             return
         if IWorkspaceContext.providedBy(context):
             self.annotations[_WS_KEY] = self.workspace = self.context
         else:
             self.annotations[_WS_KEY] = self.workspace = queryAdapter(
                 self.context,
                 IWorkspaceContext,
             )
Ejemplo n.º 13
0
 def checkLocalRolesAllowed(self, user, object, object_roles):
     user, principal_ids = self._user_info(user)
     workspace = None
     check_roles = set(object_roles)
     for obj in self._parent_chain(object):
         for provider in self._getAdapters(obj):
             for principal_id in principal_ids:
                 roles = list(provider.getRoles(principal_id))
                 if workspace:
                     # seen previous workspace, don't inherit some roles
                     roles = filter_roles(roles)
                 if check_roles.intersection(roles):
                     if user._check_context(obj):
                         return 1
                     else:
                         return 0
         if IWorkspaceContext.providedBy(obj):
             workspace = obj  # mark ws as seen before looking at parents
     return None
Ejemplo n.º 14
0
 def checkLocalRolesAllowed(self, user, object, object_roles):
     user, principal_ids = self._user_info(user)
     workspace = None
     check_roles = set(object_roles)
     for obj in self._parent_chain(object):
         for provider in self._getAdapters(obj):
             for principal_id in principal_ids:
                 roles = list(provider.getRoles(principal_id))
                 if workspace:
                     # seen previous workspace, don't inherit some roles
                     roles = filter_roles(roles)
                 if check_roles.intersection(roles):
                     if user._check_context(obj):
                         return 1
                     else:
                         return 0
         if IWorkspaceContext.providedBy(obj):
             workspace = obj  # mark ws as seen before looking at parents
     return None
Ejemplo n.º 15
0
 def getRolesInContext(self, user, object):
     roles = set()
     workspace = None
     user, principal_ids = self._user_info(user)
     for obj in self._parent_chain(object):
         if user._check_context(obj):
             for provider in self._getAdapters(obj):
                 for principal_id in principal_ids:
                     context_roles = list(provider.getRoles(principal_id))
                     if workspace:
                         # once you have seen a previous workspace, there
                         # are certain roles you DO NOT want to inherit
                         # from a higher-level workspace in the containment
                         # hierarchy.  We filter those roles from the list
                         # for all but the first seen workspace walking up
                         # the hierarchy.
                         context_roles = filter_roles(context_roles)
                     roles.update(context_roles)
         if IWorkspaceContext.providedBy(obj):
             workspace = obj  # mark ws as seen before looking at parents
     return list(roles)
Ejemplo n.º 16
0
 def getRolesInContext(self, user, object):
     roles = set()
     workspace = None
     user, principal_ids = self._user_info(user)
     for obj in self._parent_chain(object):
         if user._check_context(obj):
             for provider in self._getAdapters(obj):
                 for principal_id in principal_ids:
                     context_roles = list(provider.getRoles(principal_id))
                     if workspace:
                         # once you have seen a previous workspace, there
                         # are certain roles you DO NOT want to inherit
                         # from a higher-level workspace in the containment
                         # hierarchy.  We filter those roles from the list
                         # for all but the first seen workspace walking up
                         # the hierarchy.
                         context_roles = filter_roles(context_roles)
                     roles.update(context_roles)
         if IWorkspaceContext.providedBy(obj):
             workspace = obj  # mark ws as seen before looking at parents
     return list(roles)
Ejemplo n.º 17
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.º 18
0
def workspace_for(context):
    if IWorkspaceContext.providedBy(context):
        return context
    return find_parent(context, iface=IWorkspaceContext, start_depth=3)
Ejemplo n.º 19
0
def workspace_for(context):
    if IWorkspaceContext.providedBy(context):
        return context
    return find_parent(context, iface=IWorkspaceContext, start_depth=3)
Ejemplo n.º 20
0
 def __init__(self, context, request=None):
     if not IWorkspaceContext.providedBy(context):
         raise ValueError
     self.context = context
     self.request = request if request else getRequest()
     self.schemakeys = []