Ignore:
Timestamp:
3 Sep 2011, 23:38:21 (13 years ago)
Author:
uli
Message:

Factor out get_principal_role_manager from w.s.authentication.Account.
This method had nothing specific for class and we have use for it in
students authentication.

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

Legend:

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

    r6672 r6673  
    2626    for name, util in auth_plugin_utilities:
    2727        util.register(pau)
     28
     29def get_principal_role_manager():
     30    """Get a role manager for principals.
     31
     32    If we are currently 'in a site', return the role manager for the
     33    portal or the global rolemanager else.
     34    """
     35    portal = grok.getSite()
     36    if portal is not None:
     37        return IPrincipalRoleManager(portal)
     38    return principalRoleManager
    2839
    2940class WAeUPSessionCredentialsPlugin(grok.GlobalUtility,
     
    7485
    7586    def getRoles(self):
    76         prm = self._getPrincipalRoleManager()
     87        prm = get_principal_role_manager()
    7788        roles = [x[0] for x in prm.getRolesForPrincipal(self.name)
    7889                 if x[0].startswith('waeup.')]
     
    8091
    8192    def setRoles(self, roles):
    82         prm = self._getPrincipalRoleManager()
     93        prm = get_principal_role_manager()
    8394
    8495        old_roles = self.getRoles()
     
    107118        self._p_changed = True
    108119        return
    109 
    110     def _getPrincipalRoleManager(self):
    111         portal = grok.getSite()
    112         if portal is not None:
    113             return IPrincipalRoleManager(portal)
    114         return principalRoleManager
    115120
    116121class UserAuthenticatorPlugin(grok.GlobalUtility):
  • main/waeup.sirp/trunk/src/waeup/sirp/tests/test_authentication.py

    r6617 r6673  
    44from zope.interface.verify import verifyClass, verifyObject
    55from zope.pluggableauth.interfaces import IAuthenticatorPlugin
     6from zope.securitypolicy.interfaces import IPrincipalRoleManager
    67from waeup.sirp.testing import FunctionalTestCase, FunctionalLayer
    78from waeup.sirp.authentication import (
    8     UserAuthenticatorPlugin, Account, PrincipalInfo)
     9    UserAuthenticatorPlugin, Account, PrincipalInfo, get_principal_role_manager)
    910
    1011class FakeSite(grok.Site, grok.Container):
     
    5758        self.assertTrue(result2 is None)
    5859        return
     60
     61    def test_get_principal_role_manager(self):
     62        # make sure we get different role managers for different situations
     63        prm1 = get_principal_role_manager()
     64        clearSite(None)
     65        prm2 = get_principal_role_manager()
     66        self.assertTrue(IPrincipalRoleManager.providedBy(prm1))
     67        self.assertTrue(IPrincipalRoleManager.providedBy(prm2))
     68        self.assertTrue(prm1._context is self.site)
     69        self.assertTrue(hasattr(prm2, '_context') is False)
     70        return
Note: See TracChangeset for help on using the changeset viewer.