Changeset 13226


Ignore:
Timestamp:
24 Aug 2015, 19:53:21 (9 years ago)
Author:
Henrik Bettermann
Message:

Use ApplicantsPlugin? to remove outdated applicant ids from global role map.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/root.py

    r13216 r13226  
    2222from hurry.query import Eq
    2323from hurry.query.interfaces import IQuery
     24from zope.securitypolicy.interfaces import IPrincipalRoleManager
    2425from zope.component import getUtility
    2526from zope.component.interfaces import ComponentLookupError
     
    7475        leave it that way. If not create one and delete the old one if
    7576        appropriate.
     77
     78        Update applicants catalog.
     79
     80        Remove deprecated applicant ids from global role map.
    7681        """
    7782        app_folder = site.get('applicants', None)
     
    103108            except ComponentLookupError: # in unit tests
    104109                pass
     110
     111            try:
     112                removed_applicant_ids = []
     113                cat = getUtility(ICatalog, name='applicants_catalog')
     114                role_manager = IPrincipalRoleManager(grok.getSite())
     115                principals = role_manager.getPrincipalsForRole('waeup.Applicant')
     116                for principal in principals:
     117                    applicant_id = principal[0]
     118                    results = cat.searchResults(applicant_id=(applicant_id, applicant_id))
     119                    if len(results):
     120                        continue
     121                    # The applicant does no longer exist.
     122                    nothing_to_do = False
     123                    role_manager.unsetRoleForPrincipal(
     124                        'waeup.Applicant', applicant_id)
     125                    removed_applicant_ids.append(applicant_id)
     126                if len(removed_applicant_ids):
     127                    logger.info(
     128                        '%s: %s removed from global role map.'
     129                        % (self.log_prefix, removed_applicant_ids))
     130            except ComponentLookupError: # in unit tests
     131                pass
     132
    105133            if nothing_to_do:
    106134                logger.info(
Note: See TracChangeset for help on using the changeset viewer.