1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Persons import Person, Persons
5 from PLC.Auth import Auth
7 can_update = lambda (field, value): field in \
8 ['first_name', 'last_name', 'title', 'email',
9 'password', 'phone', 'url', 'bio', 'accepted_aup',
12 class UpdatePerson(Method):
14 Updates a person. Only the fields specified in person_fields are
15 updated, all other fields are left untouched.
17 Users and techs can only update themselves. PIs can only update
18 themselves and other non-PIs at their sites.
20 Returns 1 if successful, faults otherwise.
23 roles = ['admin', 'pi', 'user', 'tech']
25 person_fields = dict(filter(can_update, Person.fields.items()))
29 Mixed(Person.fields['person_id'],
30 Person.fields['email']),
34 returns = Parameter(int, '1 if successful')
36 def call(self, auth, person_id_or_email, person_fields):
37 person_fields = dict(filter(can_update, person_fields.items()))
39 # Get account information
40 persons = Persons(self.api, [person_id_or_email])
42 raise PLCInvalidArgument, "No such account"
46 # Authenticated function
47 assert self.caller is not None
49 # Check if we can update this account
50 if not self.caller.can_update(person):
51 raise PLCPermissionDenied, "Not allowed to update specified account"
53 person.update(person_fields)