[FIX] Error reports
[cds-indico.git] / indico / MaKaC / webinterface / user.py
blob1bccbd5de973d6fd5a504a76a424f10ffaec0544
1 from MaKaC import user
2 from MaKaC.services.implementation.base import ParameterManager
3 from MaKaC.services.interface.rpc.common import ServiceError
6 class UserModificationBase ( object ):
7 """ Base class to retrieve an Avatar object from a 'user' parameter.
8 It will store the Avatar object in self._targetUser
9 """
11 def _checkParams( self ):
12 if 'user' in self._params:
13 ph = user.PrincipalHolder()
14 self._targetUser = ph.getById(self._params['user'])
15 else:
16 self._targetUser = None
18 ## TODO: this class is never used....
19 class UserEditBase ( object ):
21 def _checkParams(self):
22 if 'userData' in self._params:
23 pm = ParameterManager(self._params)
24 self._userData = pm.extract("userData", pType=dict, allowEmpty = True)
25 else:
26 raise ServiceError("ERR-E6", '"userData" parameter missing')
30 class UserListModificationBase ( object):
31 """ Base class to retrieve a list of users from a 'userList' parameter.
32 The userList parameter will contain dictionaries with the following keys:
33 id, title, familyName, firstName, affiliation, email, address, telephone, fax, submission
35 The id can be:
36 -a number, in this case it represents an Avatar id (a user in the DB)
37 -a string beginning by 'newUser', ex: 'newUser0'. In that case it represents a user not in the DB, whose data was input
38 -a string beginning by 'edited', ex: 'edited0'. In that case it represents an Avatar (a user in the DB),
39 but whose data was changed.
41 The class will store the users in the following 3 attributes:
42 self._avatars = a list of Avatar objects
43 self._newUsers = a list of dictionaries as the ones described before
44 self._editedAvatars = a list of tuples (Avatar, dictionary)
45 """
47 @staticmethod
48 def retrieveUsers(params, fieldName="userList"):
49 pm = ParameterManager(params)
50 userList = pm.extract(fieldName, pType=list, allowEmpty = True)
51 avatars = []
52 newUsers = []
53 editedAvatars = []
54 ph = user.PrincipalHolder()
56 for userDict in userList:
57 id = userDict['id']
58 if id.startswith('newUser'):
59 newUsers.append(userDict)
60 elif id.startswith('edited'):
61 editedAvatars.append((ph.getById(id[6:]), userDict))
62 else:
63 avatars.append(ph.getById(id))
65 return avatars, newUsers, editedAvatars
67 def _checkParams( self, params = None, fieldName = "userList" ):
68 if params:
69 self._params = params
70 if fieldName in self._params:
71 self._avatars, self._newUsers, self._editedAvatars = UserListModificationBase.retrieveUsers(self._params, fieldName)
72 else:
73 raise ServiceError("ERR-E5", '"userList" parameter missing')