from PLC.Persons import Person, Persons
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['first_name', 'last_name', 'title', 'email',
+ 'password', 'phone', 'url', 'bio', 'accepted_aup',
+ 'enabled']
+
class UpdatePerson(Method):
"""
- Updates a person. Only the fields specified in update_fields are
+ Updates a person. Only the fields specified in person_fields are
updated, all other fields are left untouched.
To remove a value without setting a new one in its place (for
roles = ['admin', 'pi', 'user', 'tech']
- can_update = lambda (field, value): field in \
- ['first_name', 'last_name', 'title', 'email',
- 'password', 'phone', 'url', 'bio', 'accepted_aup',
- 'enabled']
- update_fields = dict(filter(can_update, Person.fields.items()))
+ person_fields = dict(filter(can_update, Person.fields.items()))
+ for field in person_fields.values():
+ field.optional = True
accepts = [
PasswordAuth(),
Mixed(Person.fields['person_id'],
Person.fields['email']),
- update_fields
+ person_fields
]
returns = Parameter(int, '1 if successful')
- def call(self, auth, person_id_or_email, update_fields):
- valid_fields = self.update_fields.keys()
-
- # Remove admin only fields
- if 'admin' not in self.caller['roles']:
- for key in ['enabled']:
- valid_fields.remove(key)
-
- if filter(lambda field: field not in valid_fields, update_fields):
- raise PLCInvalidArgument, "Invalid field specified"
+ def call(self, auth, person_id_or_email, person_fields):
+ person_fields = dict(filter(can_update, person_fields.items()))
# Get account information
persons = Persons(self.api, [person_id_or_email])
if not self.caller.can_update(person):
raise PLCPermissionDenied, "Not allowed to update specified account"
- person.update(update_fields)
+ person.update(person_fields)
person.sync()
return 1