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"
45 if person['peer_id'] is not None:
46 raise PLCInvalidArgument, "Not a local account"
48 # Authenticated function
49 assert self.caller is not None
51 # Check if we can update this account
52 if not self.caller.can_update(person):
53 raise PLCPermissionDenied, "Not allowed to update specified account"
55 person.update(person_fields)
59 self.object_ids = [person['person_id']]
62 if 'password' in person_fields:
63 person_fields['password'] = "Removed by API"
64 self.message = 'Person %d updated: %s.' % \
65 (person['person_id'], person_fields.keys())
66 if 'enabled' in person_fields:
67 self.message += ' Person enabled'