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 class UpdatePerson(Method):
9 Updates a person. Only the fields specified in update_fields are
10 updated, all other fields are left untouched.
12 To remove a value without setting a new one in its place (for
13 example, to remove an address from the person), specify -1 for int
14 and double fields and 'null' for string fields. first_name and
15 last_name cannot be unset.
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 can_update = lambda (field, value): field in \
26 ['first_name', 'last_name', 'title', 'email',
27 'password', 'phone', 'url', 'bio', 'accepted_aup']
28 update_fields = dict(filter(can_update, Person.fields.items()))
32 Mixed(Person.fields['person_id'],
33 Person.fields['email']),
37 returns = Parameter(int, '1 if successful')
39 def call(self, auth, person_id_or_email, update_fields):
40 if filter(lambda field: field not in self.update_fields, update_fields):
41 raise PLCInvalidArgument, "Invalid field specified"
43 # Get account information
44 persons = Persons(self.api, [person_id_or_email])
46 raise PLCInvalidArgument, "No such account"
48 person = persons.values()[0]
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(update_fields)