From 083cca53aa50aa0932c795ecdddffed1382b6dc4 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Fri, 13 Oct 2006 20:02:36 +0000 Subject: [PATCH] - silently remove fields that can't be updated from person_fields, for backward compatibility with AdmUpdatePerson --- PLC/Methods/UpdatePerson.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/PLC/Methods/UpdatePerson.py b/PLC/Methods/UpdatePerson.py index 5e84f7d5..6ef7b701 100644 --- a/PLC/Methods/UpdatePerson.py +++ b/PLC/Methods/UpdatePerson.py @@ -4,9 +4,14 @@ from PLC.Parameter import Parameter, Mixed 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 @@ -22,10 +27,6 @@ class UpdatePerson(Method): 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())) accepts = [ @@ -37,16 +38,13 @@ class UpdatePerson(Method): returns = Parameter(int, '1 if successful') - def call(self, auth, person_id_or_email, update_fields): - valid_fields = self.update_fields.keys() + def call(self, auth, person_id_or_email, person_fields): + person_fields = dict(filter(can_update, person_fields.items())) # 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" + del person_fields[key] # Get account information persons = Persons(self.api, [person_id_or_email]) @@ -62,7 +60,7 @@ class UpdatePerson(Method): 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 -- 2.47.0