Changeset 7162 for main/waeup.sirp/trunk


Ignore:
Timestamp:
22 Nov 2011, 07:25:31 (13 years ago)
Author:
Henrik Bettermann
Message:

Move getGlobalRoles and getLocalRoles to SiteLayout? class so that we can put these strings into the personal box of officers.

Rename UserEditFormPage? to UserManageFormPage? and omit name field when editing user data. User ids can't be edited.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/browser
Files:
5 edited

Legend:

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

    r7149 r7162  
    135135We can edit user bob:
    136136
    137   >>> browser.getControl("edit", index=0).click()
     137  >>> browser.getControl("manage", index=0).click()
    138138  >>> browser.getControl("Save", index=0).click()
    139139  >>> browser.getControl("Cancel", index=0).click()
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/layout.py

    r7137 r7162  
    1616from waeup.sirp.students.interfaces import IStudentNavigation
    1717from waeup.sirp.authentication import get_principal_role_manager
     18from waeup.sirp.permissions import getRoles
    1819
    1920grok.templatedir('templates')
     
    165166    def isStudent(self):
    166167        prm = get_principal_role_manager()
    167         roles = [x[0] for x in prm.getRolesForPrincipal(self.request.principal.id)]
     168        roles = [x[0] for x in
     169            prm.getRolesForPrincipal(self.request.principal.id)]
    168170        return 'waeup.Student' in roles
     171
     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
    169197
    170198    def update(self):
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r7149 r7162  
    3737    ISessionConfiguration, ISessionConfigurationAdd, academic_sessions_vocab,
    3838    IPasswordValidator)
    39 from waeup.sirp.permissions import get_users_with_local_roles, getRoles
     39from waeup.sirp.permissions import get_users_with_local_roles
    4040from waeup.sirp.university.catalog import search
    4141from waeup.sirp.university.vocabularies import course_levels
     
    253253    title = 'Portal Users'
    254254
    255     def update(self, userid=None, adduser=None, edit=None, delete=None):
    256         if edit is not None and userid is not None:
    257             self.redirect(self.url(userid))
     255    def update(self, userid=None, adduser=None, manage=None, delete=None):
     256        if manage is not None and userid is not None:
     257            self.redirect(self.url(userid) + '/@@manage')
    258258        if delete is not None and userid is not None:
    259259            self.context.delUser(userid)
    260260            self.flash('User %s successfully deleted.' % userid)
    261 
    262     def getLocalRoles(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(getRoles())[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: %s <br />' %(role_title,
    273                 objects_string.rstrip(', '))
    274         return local_roles_string
    275 
    276     def getGlobalRoles(self,account):
    277         global_roles = account.roles
    278         global_roles_string = ''
    279         for global_role in global_roles:
    280             role_title = dict(getRoles())[global_role].title
    281             global_roles_string += '%s <br />' % role_title
    282         return global_roles_string
    283261
    284262class AddUserFormPage(WAeUPAddFormPage):
     
    316294        self.redirect(self.url(self.context))
    317295
    318 class UserEditFormPage(WAeUPEditFormPage):
    319     """Edit a user account.
     296class UserManageFormPage(WAeUPEditFormPage):
     297    """Manage a user account.
    320298    """
    321299    grok.context(IUserAccount)
    322     grok.name('index')
    323 
    324     form_fields = grok.AutoFields(IUserAccount)
     300    grok.name('manage')
     301    grok.template('usereditformpage')
     302
     303    form_fields = grok.AutoFields(IUserAccount).omit('name')
    325304    grok.require('waeup.manageUsers')
    326305
    327     title = "Edit user"
     306    title = "Portal Users"
     307
     308    def label(self):
     309        return "Edit user %s" % self.context.__name__
    328310
    329311    @grok.action('Save')
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/templates/usercontainerpage.pt

    r6511 r7162  
    2121      <td tal:content="account/title">Title</td>
    2222      <td tal:content="account/description">Description</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>
     23      <td tal:content="structure python:layout.getGlobalRoles(account)">Global Roles</td>
     24      <td tal:content="structure python:layout.getLocalRoles(account)">Local Roles</td>
    2525      <td class="text-right">
    2626        <form method="post">
    2727          <input type="hidden" name="userid"
    2828           tal:attributes="value account/name"/>
    29             <input type="submit" name="edit" value="edit" />
     29            <input type="submit" name="manage" value="manage" />
    3030            <input type="submit" name="delete" value="delete" />
    3131        </form>
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/tests/test_permissions.py

    r6686 r7162  
    4343    # The pages that should only be accessible by manager...
    4444    '/@@manage', '/@@administration', '/faculties/@@search',
    45     '/users/@@index', '/users/@@add', '/users/alice/@@index',
     45    '/users/@@index', '/users/@@add', '/users/alice/@@manage',
    4646    '/datacenter/@@index', '/datacenter/@@upload', '/datacenter/@@import1',
    4747    '/datacenter/@@import2', '/datacenter/@@import3', '/datacenter/@@import4',
Note: See TracChangeset for help on using the changeset viewer.