コード例 #1
0
ファイル: members.py プロジェクト: Zojax/zojax.members
 def toManager(self, id):
     if id in self:
         if id not in self.managers:
             managers = list(self.managers)
             managers.append(id)
             self.managers = tuple(managers)
             updatePermissions(self.__parent__)
             event.notify(ObjectModifiedEvent(self.__parent__))
コード例 #2
0
ファイル: company.py プロジェクト: Zojax/zojax.company
def companyModified(company, ev):
    if not company.type:
        company.type = u'open'

    IObjectPermissionsMapsManager(
        removeSecurityProxy(company)).set(('company.%s'%company.type,))

    updatePermissions(company)
コード例 #3
0
ファイル: group.py プロジェクト: Zojax/zojax.groups
def groupModified(group, ev):
    if not group.gtype:
        group.gtype = u'open'

    IObjectPermissionsMapsManager(
        removeSecurityProxy(group)).set(('group.%s'%group.gtype,))

    updatePermissions(group)
コード例 #4
0
ファイル: members.py プロジェクト: Zojax/zojax.members
    def approve(self, id):
        if id in self:
            member = self[id]
            if not member.approved:
                del member.approved
                self.notapproved.remove(id)

                event.notify(MemberApprovedEvent(member))
                event.notify(ObjectModifiedEvent(self.__parent__))
                updatePermissions(self.__parent__)
コード例 #5
0
ファイル: members.py プロジェクト: Zojax/zojax.members
    def __delitem__(self, key):
        member = self[key]
        self.toMember(key)
        del self.joined[member.joined]

        if key in self.notapproved:
            self.notapproved.remove(key)

        super(Members, self).__delitem__(key)
        updatePermissions(self.__parent__)
        event.notify(ObjectModifiedEvent(self.__parent__))
コード例 #6
0
ファイル: members.py プロジェクト: Zojax/zojax.members
    def joinPrincipal(self, principalId, approved=True,
                      _td = timedelta(milliseconds=1)):
        if principalId not in self:
            member = Member()
            event.notify(ObjectCreatedEvent(member))
            self[principalId] = member

            joined = parseDatetimetz(str(datetime.now()))
            while joined in self.joined:
                joined = joined + _td

            member.joined = joined
            self.joined[joined] = principalId

            if not approved:
                member.approved = False
                self.notapproved.insert(principalId)
            else:
                event.notify(MemberApprovedEvent(member))

            event.notify(ObjectModifiedEvent(self.__parent__))
            updatePermissions(self.__parent__)
コード例 #7
0
    def update(self):
        super(ContentPermissions, self).update()

        context = self.context
        request = self.request

        if IDraftedContent.providedBy(context):
            return

        # get principals
        bprincipals, batch = self.getPrincipals()
        if not bprincipals:
            return

        self.batch = batch

        principals = []
        principalIds = []
        for principal in bprincipals:
            name = principal.id.replace('.', '_')
            principalIds.append(principal.id)
            principals.append(
                {'id': principal.id,
                 'name': name,
                 'title': IPersonalProfile(principal).title})

        self.principals = principals

        # get permissions
        categories = []
        allpermissions = []
        for categoryName, category in getUtilitiesFor(IPermissionCategoryType):
            permissions = []
            for name, perm in getAdapters((context,), category):
                if perm.isAvailable():
                    permOb = perm.permission
                    permissions.append((permOb.title, permOb.description, perm))
                    allpermissions.append(perm)

            if not permissions:
                continue

            permissions.sort()
            categories.append(
                (categoryName, category.__doc__,
                 [{'id': perm.permissionId, 'object': perm,
                   'settings':perm.principals,'title':title,'desc':description}
                  for title, description, perm in permissions]))

        categories.sort()
        self.permissions = [
            {'name': name, 'desc':desc, 'perms': perms}
            for name, desc, perms in categories]

        # process form
        if 'form.updatePrincipalPermissions' in request:
            permissions = {}
            for principal in principals:
                for perm in request.get('principal-%s'%principal['name'], ()):
                    data = permissions.setdefault(perm, [])
                    data.append(principal['id'])

            for permission in allpermissions:
                permission.unsetAll()
                if permission.permissionId in permissions:
                    permission.allow(permissions[permission.permissionId])

            updatePermissions(context, permissions.keys())

            IStatusMessage(request).add(_('Permissions have been updated.'))

            for info in self.permissions:
                for perm in info['perms']:
                    perm['settings'] = perm['object'].principals