Changeset 12189


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

We need to check if imported roles do exist.

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

Legend:

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

    r11949 r12189  
    4040    IBatchProcessor, IGNORE_MARKER, IFailedLoginInfo)
    4141from waeup.ikoba.utils.batching import BatchProcessor
     42from waeup.ikoba.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.ikoba/trunk/src/waeup/ikoba/browser/batchprocessing.txt

    r11954 r12189  
    147147    ... isouaba,Issoufou Abba Moussa,Chief Developer,isouaba@abc.de,+49-234-567,[]
    148148    ... henrik,Henrik Bettermann,Admin,henrik@abc.de,+49-234-567,"['waeup.PortalManager', 'waeup.ImportManager']"
     149    ... anne,Anne Palina,,anne@abc.de,+49-234-567,"['waeup.Nonsense']"
    149150    ... """)
    150151
     
    188189    >>> browser.getControl('Perform import').click()
    189190
    190 One line could not be imported:
     191Two lines could not be imported:
    191192
    192193    >>> print browser.contents
    193194    <!DOCTYPE html PUBLIC...
    194195    ...
    195     ...Processing of 1 rows failed...
     196    ...Processing of 2 rows failed...
    196197    ...Successfully processed 1 rows...
    197198    ...
     
    204205    name,roles,title,public_name,phone,email,--ERRORS--
    205206    henrik,"['waeup.PortalManager', 'waeup.ImportManager']",Henrik Bettermann,Admin,+49-234-567,henrik@abc.de,This object already exists. Skipping.
     207    anne,['waeup.Nonsense'],Anne Palina,,+49-234-567,anne@abc.de,roles: invalid role
    206208
    207209    >>> finished_file = dc_path + '/finished/newusers_zope.mgr.create.finished.csv'
     
    218220-----------------------
    219221
    220 We 'edit' the pending file (setting code to ``FAC5`` and title
    221 appropriately, and removing the --ERROR-- column) and finish the
    222 import this way:
     222We 'edit' the pending file by removing anne and replacing henrik by gbenga
     223and finish the import this way:
    223224
    224225    >>> open(dc_path + '/newusers_zope.mgr.create.pending.csv', 'wb').write(
Note: See TracChangeset for help on using the changeset viewer.