Beispiel #1
0
    def getRolesForPrincipal(self, principal, request=None):
        roles = dict.fromkeys(IUserRoles(self.context).getRoles())

        getGroups = getattr(principal, 'getGroups', lambda: tuple())
        group_ids = getGroups()
        if group_ids:
            mbtool = getToolByName(self.context, TOOLNAME)
            uSR = mbtool.unrestrictedSearchResults
            groups = uSR(
                exact_getGroupId=group_ids,
                object_implements=(group_ifaces.IGroup.__identifier__))
            for g in groups:
                group = group_ifaces.IGroup(g._unrestrictedGetObject())
                roles.update(dict.fromkeys(group.getRoles()))

        return list(roles.keys())
Beispiel #2
0
    def enumerateGroups(self,
                        id=None,
                        title=None,
                        exact_match=False,
                        sort_by=None,
                        max_results=None,
                        **kw):
        """
        See IGroupEnumerationPlugin.
        Quite similar to enumerateUsers, but searches for groups
        and uses title instead of login
        """
        group_info = []
        plugin_id = self.getId()

        if isinstance(id, basestring):
            id = [id]

        if isinstance(title, basestring):
            title = [title]

        mbtool = getToolByName(self, TOOLNAME)
        query = {}

        if id:
            if exact_match:
                query['exact_getGroupId'] = id
            else:
                query['getGroupId'] = ['%s*' % i for i in id if i]

        elif title:
            query['Title'] = exact_match and title or \
                ['%s*' % t for t in title if t]

        # allow arbitrary indexes to be passed in to the catalog query
        query_index_map = IAnnotations(mbtool).get(QIM_ANNOT_KEY)
        if query_index_map is not None:
            for keyword in kw.keys():
                if keyword in query_index_map:
                    index_name = query_index_map[keyword]
                    search_term = kw[keyword]
                    if search_term is not None:
                        if not exact_match:
                            index = mbtool.Indexes[index_name]
                            if isinstance(index, ZCTextIndex):
                                # split, glob, join
                                sep = search_term.strip().split()
                                sep = ["%s*" % val for val in sep]
                                search_term = ' '.join(sep)

                        query[index_name] = search_term

        if sort_by is not None:
            if sort_by == 'title':
                query['sort_on'] = 'Title'
            if sort_by == 'id':
                query['sort_on'] = 'getGroupId'

        query['object_implements'] = group_ifaces.IGroup.__identifier__

        groups = mbtool.unrestrictedSearchResults(**query)

        i = 0
        for g in groups:
            obj = g._unrestrictedGetObject()
            group = group_ifaces.IGroup(obj, None)
            if group is None:
                continue

            if max_results is not None and i >= max_results:
                break
            i += 1
            # XXX WE NEED TO ASK THE GROUP ITSELF WHERE ITS EDIT
            # SCREENS ARE
            info = {
                'id': group.getGroupId(),
                'pluginid': plugin_id,
                'properties_url': '%s/base_edit' % obj.absolute_url(),
                'members_url': '%s/base_edit' % obj.absolute_url(),
            }

            group_info.append(info)

        return tuple(group_info)