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 object_type = 'Person'
38 def call(self, auth, person_id_or_email, person_fields):
39 person_fields = dict(filter(can_update, person_fields.items()))
41 # Get account information
42 persons = Persons(self.api, [person_id_or_email])
44 raise PLCInvalidArgument, "No such account"
47 if person['peer_id'] is not None:
48 raise PLCInvalidArgument, "Not a local account"
50 # Authenticated function
51 assert self.caller is not None
53 # Check if we can update this account
54 if not self.caller.can_update(person):
55 raise PLCPermissionDenied, "Not allowed to update specified account"
57 person.update(person_fields)
61 self.object_ids = [person['person_id']]
64 if 'password' in person_fields:
65 person_fields['password'] = "Removed by API"
66 self.message = 'Person %d updated: %s.' % \
67 (person['person_id'], person_fields.keys())
68 if 'enabled' in person_fields:
69 self.message += ' Person enabled'