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 AdmSetPersonEnabled(Method):
9 Enables or disables a person.
11 Users and techs can only update themselves. PIs can only update
12 themselves and other non-PIs at their sites. Admins can update
15 Returns 1 if successful, faults otherwise.
18 roles = ['admin', 'pi']
22 Mixed(Person.fields['person_id'],
23 Person.fields['email']),
24 Person.fields['enabled']
27 returns = Parameter(int, '1 if successful')
29 def call(self, auth, person_id_or_email, enabled):
30 # Get account information
31 persons = Persons(self.api, [person_id_or_email])
33 raise PLCInvalidArgument, "No such account"
35 person = persons.values()[0]
37 # Authenticated function
38 assert self.caller is not None
40 # Check if we can update this account
41 if not self.caller.can_update(person):
42 raise PLCPermissionDenied, "Not allowed to enable specified account"
44 person['enabled'] = enabled