Esempio n. 1
0
    def permission_settings(self, permission=None):
        """Return user-role permission settings.

        If 'permission' is passed to the method then only the settings for
        'permission' is returned.
        """
        result=[]
        valid=self.valid_roles()
        indexes=range(len(valid))
        ip=0

        permissions = self.ac_inherited_permissions(1)
        # Filter permissions
        if permission:
            permissions = [p for p in permissions if p[0] == permission]

        for p in permissions:
            name, value = p[:2]
            p=Permission(name,value,self)
            roles=p.getRoles(default=[])
            d={'name': name,
               'acquire': isinstance(roles, list) and 'CHECKED' or '',
               'roles': map(
                   lambda ir, roles=roles, valid=valid, ip=ip:
                   {
                       'name': "p%dr%d" % (ip,ir),
                       'checked': (valid[ir] in roles) and 'CHECKED' or '',
                       },
                   indexes)
               }
            ip=ip+1
            result.append(d)
        return result
Esempio n. 2
0
    def permission_settings(self, permission=None):
        """Return user-role permission settings.

        If 'permission' is passed to the method then only the settings for
        'permission' is returned.
        """
        result = []
        valid = self.valid_roles()
        indexes = range(len(valid))
        ip = 0

        permissions = self.ac_inherited_permissions(1)
        # Filter permissions
        if permission:
            permissions = [p for p in permissions if p[0] == permission]

        for p in permissions:
            name, value = p[:2]
            p = Permission(name, value, self)
            roles = p.getRoles(default=[])
            d = {
                'name':
                name,
                'acquire':
                isinstance(roles, list) and 'CHECKED' or '',
                'roles':
                map(lambda ir, roles=roles, valid=valid, ip=ip: {
                    'name': "p%dr%d" % (ip, ir),
                    'checked': (valid[ir] in roles) and 'CHECKED' or '',
                },
                    indexes)
            }
            ip = ip + 1
            result.append(d)
        return result
Esempio n. 3
0
    def manage_changePermissions(self, REQUEST):
        """Change all permissions settings, called by management screen.
        """
        self._isBeingUsedAsAMethod(REQUEST, 0)
        valid_roles = self.valid_roles()
        indexes = range(len(valid_roles))
        have = REQUEST.has_key
        permissions = self.ac_inherited_permissions(1)
        fails = []
        for ip in range(len(permissions)):
            roles = []
            for ir in indexes:
                if have("p%dr%d" % (ip, ir)): roles.append(valid_roles[ir])
            name, value = permissions[ip][:2]
            try:
                p = Permission(name, value, self)
                if not have('a%d' % ip): roles = tuple(roles)
                p.setRoles(roles)
            except:
                fails.append(name)

        if fails:
            return MessageDialog(title="Warning!",
                                 message="Some permissions had errors: " +
                                 escape(', '.join(fails)),
                                 action='manage_access')
        return MessageDialog(title='Success!',
                             message='Your changes have been saved',
                             action='manage_access')
Esempio n. 4
0
    def manage_changePermissions(self, REQUEST):
        """Change all permissions settings, called by management screen.
        """
        self._isBeingUsedAsAMethod(REQUEST, 0)
        valid_roles=self.valid_roles()
        indexes=range(len(valid_roles))
        have=REQUEST.has_key
        permissions=self.ac_inherited_permissions(1)
        fails = []
        for ip in range(len(permissions)):
            roles=[]
            for ir in indexes:
                if have("p%dr%d" % (ip,ir)): roles.append(valid_roles[ir])
            name, value = permissions[ip][:2]
            try:
                p=Permission(name,value,self)
                if not have('a%d' % ip): roles=tuple(roles)
                p.setRoles(roles)
            except:
                fails.append(name)

        if fails:
            return MessageDialog(title="Warning!",
                                 message="Some permissions had errors: "
                                   + escape(', '.join(fails)),
                                 action='manage_access')
        return MessageDialog(
            title  ='Success!',
            message='Your changes have been saved',
            action ='manage_access')
Esempio n. 5
0
    def manage_role(self, role_to_manage, permissions=[], REQUEST=None):
        "Change the permissions given to the given role"
        self._isBeingUsedAsAMethod(REQUEST, 0)
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            p=Permission(name,value,self)
            p.setRole(role_to_manage, name in permissions)

        if REQUEST is not None: return self.manage_access(REQUEST)
Esempio n. 6
0
    def manage_role(self, role_to_manage, permissions=[], REQUEST=None):
        """Change the permissions given to the given role.
        """
        self._isBeingUsedAsAMethod(REQUEST, 0)
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            p = Permission(name, value, self)
            p.setRole(role_to_manage, name in permissions)

        if REQUEST is not None: return self.manage_access(REQUEST)
Esempio n. 7
0
    def acquiredRolesAreUsedBy(self, permission):
        "used by management screen"
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            if name==permission:
                p=Permission(name,value,self)
                roles=p.getRoles()
                return type(roles) is ListType and 'CHECKED' or ''

        raise 'Invalid Permission', (
            "The permission <em>%s</em> is invalid." % escape(permission))
Esempio n. 8
0
 def permissionsOfRole(self, role):
     "used by management screen"
     r=[]
     for p in self.ac_inherited_permissions(1):
         name, value = p[:2]
         p=Permission(name,value,self)
         roles=p.getRoles()
         r.append({'name': name,
                   'selected': role in roles and 'SELECTED' or '',
                   })
     return r
Esempio n. 9
0
    def acquiredRolesAreUsedBy(self, permission):
        """Used by management screen.
        """
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            if name == permission:
                p = Permission(name, value, self)
                roles = p.getRoles()
                return isinstance(roles, list) and 'CHECKED' or ''

        raise ValueError, ("The permission <em>%s</em> is invalid." %
                           escape(permission))
Esempio n. 10
0
    def acquiredRolesAreUsedBy(self, permission):
        """Used by management screen.
        """
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            if name==permission:
                p=Permission(name,value,self)
                roles=p.getRoles()
                return isinstance(roles, list) and 'CHECKED' or ''

        raise ValueError, (
            "The permission <em>%s</em> is invalid." % escape(permission))
Esempio n. 11
0
 def permissionsOfRole(self, role):
     """Used by management screen.
     """
     r = []
     for p in self.ac_inherited_permissions(1):
         name, value = p[:2]
         p = Permission(name, value, self)
         roles = p.getRoles()
         r.append({
             'name': name,
             'selected': role in roles and 'SELECTED' or '',
         })
     return r
Esempio n. 12
0
    def rolesOfPermission(self, permission):
        """Used by management screen.
        """
        valid_roles = self.valid_roles()
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            if name == permission:
                p = Permission(name, value, self)
                roles = p.getRoles()
                return map(lambda role, roles=roles: {
                    'name': role,
                    'selected': role in roles and 'SELECTED' or '',
                },
                           valid_roles)

        raise ValueError, ("The permission <em>%s</em> is invalid." %
                           escape(permission))
Esempio n. 13
0
    def rolesOfPermission(self, permission):
        "used by management screen"
        valid_roles=self.valid_roles()
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            if name==permission:
                p=Permission(name,value,self)
                roles=p.getRoles()
                return map(
                    lambda role, roles=roles:
                    {'name': role,
                     'selected': role in roles and 'SELECTED' or '',
                     },
                    valid_roles)

        raise 'Invalid Permission', (
            "The permission <em>%s</em> is invalid." % escape(permission))
Esempio n. 14
0
    def manage_permission(self, permission_to_manage,
                          roles=[], acquire=0, REQUEST=None):
        """Change the settings for the given permission

        If optional arg acquire is true, then the roles for the permission
        are acquired, in addition to the ones specified, otherwise the
        permissions are restricted to only the designated roles."""
        self._isBeingUsedAsAMethod(REQUEST, 0)
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            if name==permission_to_manage:
                p=Permission(name,value,self)
                if acquire: roles=list(roles)
                else: roles=tuple(roles)
                p.setRoles(roles)
                if REQUEST is not None: return self.manage_access(REQUEST)
                return

        raise 'Invalid Permission', (
            "The permission <em>%s</em> is invalid." %
                escape(permission_to_manage))
Esempio n. 15
0
    def manage_acquiredPermissions(self, permissions=[], REQUEST=None):
        """Change the permissions that acquire.
        """
        self._isBeingUsedAsAMethod(REQUEST, 0)
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            p = Permission(name, value, self)
            roles = p.getRoles()
            if roles is None: continue
            if name in permissions: p.setRoles(list(roles))
            else: p.setRoles(tuple(roles))

        if REQUEST is not None: return self.manage_access(REQUEST)
Esempio n. 16
0
    def manage_permission(self,
                          permission_to_manage,
                          roles=[],
                          acquire=0,
                          REQUEST=None):
        """Change the settings for the given permission.

        If optional arg acquire is true, then the roles for the permission
        are acquired, in addition to the ones specified, otherwise the
        permissions are restricted to only the designated roles.
        """
        self._isBeingUsedAsAMethod(REQUEST, 0)
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            if name == permission_to_manage:
                p = Permission(name, value, self)
                if acquire: roles = list(roles)
                else: roles = tuple(roles)
                p.setRoles(roles)
                if REQUEST is not None: return self.manage_access(REQUEST)
                return

        raise ValueError, ("The permission <em>%s</em> is invalid." %
                           escape(permission_to_manage))
Esempio n. 17
0
 def permission_settings(self):
     """Return user-role permission settings
     """
     result=[]
     valid=self.valid_roles()
     indexes=range(len(valid))
     ip=0
     for p in self.ac_inherited_permissions(1):
         name, value = p[:2]
         p=Permission(name,value,self)
         roles=p.getRoles(default=[])
         d={'name': name,
            'acquire': type(roles) is ListType and 'CHECKED' or '',
            'roles': map(
                lambda ir, roles=roles, valid=valid, ip=ip:
                {
                    'name': "p%dr%d" % (ip,ir),
                    'checked': (valid[ir] in roles) and 'CHECKED' or '',
                    },
                indexes)
            }
         ip=ip+1
         result.append(d)
     return result
Esempio n. 18
0
    def manage_acquiredPermissions(self, permissions=[], REQUEST=None):
        "Change the permissions that acquire"
        self._isBeingUsedAsAMethod(REQUEST, 0)
        for p in self.ac_inherited_permissions(1):
            name, value = p[:2]
            p=Permission(name,value,self)
            roles=p.getRoles()
            if roles is None: continue
            if name in permissions: p.setRoles(list(roles))
            else:                   p.setRoles(tuple(roles))

        if REQUEST is not None: return self.manage_access(REQUEST)