Ignore:
Timestamp:
23 Nov 2011, 07:21:03 (13 years ago)
Author:
Henrik Bettermann
Message:

Move getGlobalRolesForAccount and getLocalRolesForAccount to permissions.py (work in progress!)

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

Legend:

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

    r7162 r7176  
    170170        return 'waeup.Student' in roles
    171171
    172     def getLocalRoles(self, account):
    173         """Return HTML tagged string with all local roles of a user account.
    174         """
    175         local_roles = account.getLocalRoles()
    176         local_roles_string = ''
    177         site_url = self.url(grok.getSite())
    178         for local_role in local_roles.keys():
    179             role_title = dict(getRoles())[local_role].title
    180             objects_string = ''
    181             for object in local_roles[local_role]:
    182                 objects_string += '<a href="%s">%s</a>, ' %(self.url(object),
    183                     self.url(object).replace(site_url,''))
    184             local_roles_string += '%s: <br />%s <br />' %(role_title,
    185                 objects_string.rstrip(', '))
    186         return local_roles_string
    187 
    188     def getGlobalRoles(self, account):
    189         """Return HTML tagged string with all global roles of a user account.
    190         """
    191         global_roles = account.roles
    192         global_roles_string = ''
    193         for global_role in global_roles:
    194             role_title = dict(getRoles())[global_role].title
    195             global_roles_string += '%s <br />' % role_title
    196         return global_roles_string
    197 
    198172    def update(self):
    199173        """Include the resources required by the chosen skin/theme.
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r7172 r7176  
    3737    ISessionConfiguration, ISessionConfigurationAdd, academic_sessions_vocab,
    3838    IPasswordValidator)
    39 from waeup.sirp.permissions import get_users_with_local_roles
     39from waeup.sirp.permissions import (
     40    get_users_with_local_roles,
     41    getGlobalRolesForAccount, getLocalRolesForAccount)
    4042from waeup.sirp.university.catalog import search
    4143from waeup.sirp.university.vocabularies import course_levels
     
    259261            self.context.delUser(userid)
    260262            self.flash('User %s successfully deleted.' % userid)
     263
     264    def getLocalRoles(self, account):
     265        return getLocalRolesForAccount(self, account)
     266
     267    def getGlobalRoles(self, account):
     268        return getGlobalRolesForAccount(account)
    261269
    262270class AddUserFormPage(WAeUPAddFormPage):
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/templates/userscontainerpage.pt

    r7172 r7176  
    2121      <td tal:content="account/title">Title</td>
    2222      <td tal:content="account/description">Description</td>
    23       <td tal:content="structure python:layout.getGlobalRoles(account)">Global Roles</td>
    24       <td tal:content="structure python:layout.getLocalRoles(account)">Local Roles</td>
     23      <td tal:content="structure python:view.getGlobalRoles(account)">Global Roles</td>
     24      <td tal:content="structure python:view.getLocalRoles(account)">Local Roles</td>
    2525      <td class="text-right">
    2626        <form method="post">
  • main/waeup.sirp/trunk/src/waeup/sirp/permissions.py

    r7168 r7176  
    44from zope.securitypolicy.interfaces import IRole, IPrincipalRoleMap
    55from waeup.sirp.interfaces import ILocalRolesAssignable
     6from waeup.sirp.utils.helpers import get_user_account
    67
    78class Public(grok.Permission):
     
    118119    """
    119120    return sorted([x.id for x in getWAeUPRoles()])
     121
     122def 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
     138def 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
     147
     148def getMyRoles(view):
     149    account = get_user_account(view.request)
     150    if account:
     151        global_roles = getGlobalRoles(account)
     152        local_roles = getLocalRoles(account)
     153        return [global_roles,local_roles]
     154    return
    120155
    121156
Note: See TracChangeset for help on using the changeset viewer.