Changeset 7177 for main/waeup.sirp


Ignore:
Timestamp:
23 Nov 2011, 09:18:19 (13 years ago)
Author:
Henrik Bettermann
Message:

Role back some changes made earlier: global and local role strings with html tags should be better constructed in view not in permission module.

Rename some role related methods to avoid (my) confusion.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/authentication.py

    r7173 r7177  
    7676        self.description = description
    7777        self.setPassword(password)
    78         self.setRoles(roles)
     78        #self.setSiteRolesForPrincipal(roles)
    7979        # We don't want to share this dict with other accounts
    8080        self._local_roles = dict()
     
    8888        return passwordmanager.checkPassword(self.password, password)
    8989
    90     def getRoles(self):
     90    def getSiteRolesForPrincipal(self):
    9191        prm = get_principal_role_manager()
    9292        roles = [x[0] for x in prm.getRolesForPrincipal(self.name)
     
    9494        return roles
    9595
    96     def setRoles(self, roles):
     96    def setSiteRolesForPrincipal(self, roles):
    9797        prm = get_principal_role_manager()
    98 
    99         old_roles = self.getRoles()
     98        old_roles = self.getSiteRolesForPrincipal()
    10099        for role in old_roles:
    101100            # Remove old roles, not to be set now...
    102101            if role.startswith('waeup.') and role not in roles:
    103102                prm.unsetRoleForPrincipal(role, self.name)
    104 
    105103        for role in roles:
    106104            prm.assignRoleToPrincipal(role, self.name)
    107105
    108     roles = property(getRoles, setRoles)
     106    roles = property(getSiteRolesForPrincipal, setSiteRolesForPrincipal)
    109107
    110108    def getLocalRoles(self):
  • main/waeup.sirp/trunk/src/waeup/sirp/authentication.txt

    r7173 r7177  
    5353Users have also got the global PortalUser role:
    5454
    55   >>> alice.getRoles()
     55  >>> alice.getSiteRolesForPrincipal()
    5656  ['waeup.PortalUser']
    5757
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/layout.py

    r7176 r7177  
    1616from waeup.sirp.students.interfaces import IStudentNavigation
    1717from waeup.sirp.authentication import get_principal_role_manager
    18 from waeup.sirp.permissions import getRoles
    1918
    2019grok.templatedir('templates')
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r7176 r7177  
    3737    ISessionConfiguration, ISessionConfigurationAdd, academic_sessions_vocab,
    3838    IPasswordValidator)
    39 from waeup.sirp.permissions import (
    40     get_users_with_local_roles,
    41     getGlobalRolesForAccount, getLocalRolesForAccount)
     39from waeup.sirp.permissions import get_users_with_local_roles, getAllRoles
    4240from waeup.sirp.university.catalog import search
    4341from waeup.sirp.university.vocabularies import course_levels
     
    263261
    264262    def getLocalRoles(self, account):
    265         return getLocalRolesForAccount(self, account)
     263        local_roles = account.getLocalRoles()
     264        local_roles_string = ''
     265        site_url = self.url(grok.getSite())
     266        for local_role in local_roles.keys():
     267            role_title = dict(getAllRoles())[local_role].title
     268            objects_string = ''
     269            for object in local_roles[local_role]:
     270                objects_string += '<a href="%s">%s</a>, ' %(self.url(object),
     271                    self.url(object).replace(site_url,''))
     272            local_roles_string += '%s: <br />%s <br />' %(role_title,
     273                objects_string.rstrip(', '))
     274        return local_roles_string
    266275
    267276    def getGlobalRoles(self, account):
    268         return getGlobalRolesForAccount(account)
     277        global_roles = account.roles
     278        global_roles_string = ''
     279        for global_role in global_roles:
     280            role_title = dict(getAllRoles())[global_role].title
     281            global_roles_string += '%s <br />' % role_title
     282        return global_roles_string
    269283
    270284class AddUserFormPage(WAeUPAddFormPage):
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r7172 r7177  
    8686    def getTitle(self, value):
    8787        # late import: in interfaces we should not import local modules
    88         from waeup.sirp.permissions import getRoles
    89         roles = dict(getRoles())
     88        from waeup.sirp.permissions import getAllRoles
     89        roles = dict(getAllRoles())
    9090        if value in roles.keys():
    9191            title = roles[value].title
  • main/waeup.sirp/trunk/src/waeup/sirp/permissions.py

    r7176 r7177  
    8585                     'waeup.viewHostels', 'waeup.manageHostels')
    8686
    87 def getRoles():
     87def getAllRoles():
    8888    """Return a list of tuples ``<ROLE-NAME>, <ROLE>``.
    8989    """
     
    102102    Returns a generator of the found roles.
    103103    """
    104     for name, item in getRoles():
     104    for name, item in getAllRoles():
    105105        if not name.startswith('waeup.'):
    106106            # Ignore non-WAeUP roles...
     
    120120    return sorted([x.id for x in getWAeUPRoles()])
    121121
    122 def getLocalRolesForAccount(view, account):
    123     """Return HTML tagged string with all local roles of a user account.
    124     """
    125     local_roles = account.getLocalRoles()
    126     local_roles_string = ''
    127     site_url = view.url(grok.getSite())
    128     for local_role in local_roles.keys():
    129         role_title = dict(getRoles())[local_role].title
    130         objects_string = ''
    131         for object in local_roles[local_role]:
    132             objects_string += '<a href="%s">%s</a>, ' %(view.url(object),
    133                 view.url(object).replace(site_url,''))
    134         local_roles_string += '%s: <br />%s <br />' %(role_title,
    135             objects_string.rstrip(', '))
    136     return local_roles_string
    137 
    138 def getGlobalRolesForAccount(account):
    139     """Return HTML tagged string with all global roles of a user account.
    140     """
    141     global_roles = account.roles
    142     global_roles_string = ''
    143     for global_role in global_roles:
    144         role_title = dict(getRoles())[global_role].title
    145         global_roles_string += '%s <br />' % role_title
    146     return global_roles_string
     122#def getLocalRolesForAccount(view, account):
     123#    """Return HTML tagged string with all local roles of a user account.
     124#    """
     125#    local_roles = account.getLocalRoles()
     126#    local_roles_string = ''
     127#    site_url = view.url(grok.getSite())
     128#    for local_role in local_roles.keys():
     129#        role_title = dict(getAllRoles())[local_role].title
     130#        objects_string = ''
     131#        for object in local_roles[local_role]:
     132#            objects_string += '<a href="%s">%s</a>, ' %(view.url(object),
     133#                view.url(object).replace(site_url,''))
     134#        local_roles_string += '%s: <br />%s <br />' %(role_title,
     135#            objects_string.rstrip(', '))
     136#    return local_roles_string
     137
     138#def getGlobalRolesForAccount(account):
     139#    """Return HTML tagged string with all global roles of a user account.
     140#    """
     141#    global_roles = account.roles
     142#    global_roles_string = ''
     143#    for global_role in global_roles:
     144#        role_title = dict(getAllRoles())[global_role].title
     145#        global_roles_string += '%s <br />' % role_title
     146#    return global_roles_string
    147147
    148148def getMyRoles(view):
     
    183183        self.context = context
    184184        role_ids = getattr(context, 'local_roles', self._roles)
    185         self._roles = [(name, role) for name, role in getRoles()
     185        self._roles = [(name, role) for name, role in getAllRoles()
    186186                       if name in role_ids]
    187187        return
     
    214214        user = grok.getSite()['users'].get(user_name,None)
    215215        user_title = getattr(user, 'description', user_name)
    216         local_role_title = dict(getRoles())[local_role].title
     216        local_role_title = dict(getAllRoles())[local_role].title
    217217        yield dict(user_name = user_name,
    218218                   user_title = user_title,
  • main/waeup.sirp/trunk/src/waeup/sirp/permissions.txt

    r7168 r7177  
    1313roles.
    1414
    15 :func:`getRoles`
    16 ----------------
     15:func:`getAllRoles`
     16-------------------
    1717
    1818Gives us all roles defined in a WAeUP SIRP portal. We get tuples of
     
    2424with the ZCA (a string) and ``<ROLE>`` is the real role object.
    2525
    26     >>> from waeup.sirp.permissions import getRoles
    27     >>> getRoles()
     26    >>> from waeup.sirp.permissions import getAllRoles
     27    >>> getAllRoles()
    2828    <generator object...at 0x...>
    2929
    30     >>> sorted(list(getRoles()))
     30    >>> sorted(list(getAllRoles()))
    3131    [(u'waeup.AccommodationOfficer', <waeup.sirp.hostels.permissions.AccommodationOfficer object at 0x...]
    3232
Note: See TracChangeset for help on using the changeset viewer.