- roles = ['admin', 'pi', 'user', 'tech']
-
- can_update = lambda (field, value): field in \
- ['first_name', 'last_name', 'title', 'email',
- 'password', 'phone', 'url', 'bio', 'accepted_aup']
- update_fields = dict(filter(can_update, Person.fields.items()))
-
- accepts = [
- PasswordAuth(),
- Mixed(Person.fields['person_id'],
- Person.fields['email']),
- update_fields
- ]
-
- returns = Parameter(int, '1 if successful')
-
- def call(self, auth, person_id_or_email, update_fields):
- if filter(lambda field: field not in self.update_fields, update_fields):
- raise PLCInvalidArgument, "Invalid field specified"
-
- # XML-RPC cannot marshal None, so we need special values to
- # represent "unset".
- for key, value in update_fields.iteritems():
- if value == -1 or value == "null":
- if key in ['first_name', 'last_name']:
- raise PLCInvalidArgument, "first_name and last_name cannot be unset"
- update_fields[key] = None
-
- # Get account information
- persons = Persons(self.api, [person_id_or_email])
- if not persons:
- raise PLCInvalidArgument, "No such account"
-
- person = persons.values()[0]
-
- # Authenticated function
- assert self.caller is not None
-
- # Check if we can update this account
- if not self.caller.can_update(person):
- raise PLCPermissionDenied, "Not allowed to update specified account"
-
- person.update(update_fields)
- person.sync()
-
- return 1