1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from indico
.util
.user
import principal_from_fossil
18 from MaKaC
import user
19 from MaKaC
.services
.implementation
.base
import ParameterManager
20 from MaKaC
.services
.interface
.rpc
.common
import ServiceError
23 class UserModificationBase ( object ):
24 """ Base class to retrieve an Avatar object from a 'user' parameter.
25 It will store the Avatar object in self._targetUser
28 def _checkParams(self
):
29 if 'user' in self
._params
:
30 self
._targetUser
= user
.AvatarHolder().getById(self
._params
['user'])
32 self
._targetUser
= None
35 class UserListModificationBase ( object):
36 """ Base class to retrieve a list of users from a 'userList' parameter.
37 The userList parameter will contain dictionaries with the following keys:
38 id, title, familyName, firstName, affiliation, email, address, telephone, fax, submission
41 -a number, in this case it represents an Avatar id (a user in the DB)
42 -a string beginning by 'newUser', ex: 'newUser0'. In that case it represents a user not in the DB, whose data was input
43 -a string beginning by 'edited', ex: 'edited0'. In that case it represents an Avatar (a user in the DB),
44 but whose data was changed.
46 The class will store the users in the following 3 attributes:
47 self._avatars = a list of Avatar objects
48 self._newUsers = a list of dictionaries as the ones described before
49 self._editedAvatars = a list of tuples (Avatar, dictionary)
53 def retrieveUsers(params
, fieldName
="userList"):
54 pm
= ParameterManager(params
)
55 userList
= pm
.extract(fieldName
, pType
=list, allowEmpty
= True)
60 for userDict
in userList
:
62 if str(id).startswith('newUser'):
63 newUsers
.append(userDict
)
64 elif str(id).startswith('edited'):
65 editedAvatars
.append((user
.AvatarHolder().getById(id[6:]), userDict
))
67 avatars
.append(principal_from_fossil(userDict
, allow_pending
=True))
69 return avatars
, newUsers
, editedAvatars
71 def _checkParams( self
, params
= None, fieldName
= "userList" ):
74 if fieldName
in self
._params
:
75 self
._avatars
, self
._newUsers
, self
._editedAvatars
= UserListModificationBase
.retrieveUsers(self
._params
, fieldName
)
77 raise ServiceError("ERR-E5", '"userList" parameter missing')