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 PasswordAuth
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 To remove a value without setting a new one in its place (for
18 example, to remove an address from the person), specify -1 for int
19 and double fields and 'null' for string fields. first_name and
20 last_name cannot be unset.
22 Users and techs can only update themselves. PIs can only update
23 themselves and other non-PIs at their sites.
25 Returns 1 if successful, faults otherwise.
28 roles = ['admin', 'pi', 'user', 'tech']
30 person_fields = dict(filter(can_update, Person.fields.items()))
31 for field in person_fields.values():
36 Mixed(Person.fields['person_id'],
37 Person.fields['email']),
41 returns = Parameter(int, '1 if successful')
43 def call(self, auth, person_id_or_email, person_fields):
44 person_fields = dict(filter(can_update, person_fields.items()))
46 # Get account information
47 persons = Persons(self.api, [person_id_or_email])
49 raise PLCInvalidArgument, "No such account"
51 person = persons.values()[0]
53 # Authenticated function
54 assert self.caller is not None
56 # Check if we can update this account
57 if not self.caller.can_update(person):
58 raise PLCPermissionDenied, "Not allowed to update specified account"
60 person.update(person_fields)