Ignore:
Timestamp:
10 Dec 2014, 11:43:50 (10 years ago)
Author:
Henrik Bettermann
Message:

UserProcessor?: Check if imported roles do exist in the portal.

Location:
main/waeup.kofa/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r11891 r12190  
    441.3dev (unreleased)
    55===================
     6
     7* UserProcessor: Check if imported roles do exist in the portal.
    68
    79* Enable localization of batch processing modules.
  • main/waeup.kofa/trunk/src/waeup/kofa/authentication.py

    r10055 r12190  
    4040    IBatchProcessor, IGNORE_MARKER, IFailedLoginInfo)
    4141from waeup.kofa.utils.batching import BatchProcessor
     42from waeup.kofa.permissions import get_all_roles
    4243
    4344def setup_authentication(pau):
     
    513514        return
    514515
     516    def checkConversion(self, row, mode='ignore'):
     517        """Validates all values in row.
     518        """
     519        errs, inv_errs, conv_dict = super(
     520            UserProcessor, self).checkConversion(row, mode=mode)
     521        # We need to check if roles exist.
     522        roles = row.get('roles', None)
     523        all_roles = [i[0] for i in get_all_roles()]
     524        if roles not in ('', IGNORE_MARKER):
     525            evalvalue = eval(roles)
     526            for role in evalvalue:
     527                if role not in all_roles:
     528                    errs.append(('roles','invalid role'))
     529        return errs, inv_errs, conv_dict
     530
    515531class UsersPlugin(grok.GlobalUtility):
    516532    """A plugin that updates users.
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/batchprocessing.txt

    r11699 r12190  
    430430    ... uli,Uli Fouquet,Chief Developer,uli@abc.de,+49-234-567,[]
    431431    ... henrik,Henrik Bettermann,Admin,henrik@abc.de,+49-234-567,"['waeup.PortalManager', 'waeup.ImportManager']"
     432    ... anne,Anne Palina,,anne@abc.de,+49-234-567,"['waeup.Nonsense']"
    432433    ... """)
    433434
     
    619620    ...
    620621
     622Oh no, we forgot Anne Palina. Her user record was not imported because
     623she has a non-existent role:
     624
    621625    >>> sorted(os.listdir(dc_path))
    622     ['deleted', 'finished', 'logs', 'unfinished']
     626    ['deleted', 'finished', 'logs', 'unfinished', 'users_zope.mgr.create.pending.csv']
    623627
    624628    >>> os.listdir(dc_path + '/unfinished')
    625     []
     629    ['users_zope.mgr.csv']
     630
     631    >>> pending_file = dc_path + '/users_zope.mgr.create.pending.csv'
     632    >>> print open(pending_file).read()
     633    name,roles,title,public_name,phone,email,--ERRORS--
     634    anne,['waeup.Nonsense'],Anne Palina,,+49-234-567,anne@abc.de,roles: invalid role
     635
     636There are many finished-files:
    626637
    627638    >>> sorted(os.listdir(dc_path + '/finished'))
    628639    ['certificates_zope.mgr.create.finished.csv', ...,
    629     'users_zope.mgr.create.finished.csv', 'users_zope.mgr.csv']
     640    'users_zope.mgr.create.finished.csv']
    630641
    631642Processed (finished) Files
Note: See TracChangeset for help on using the changeset viewer.