2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Persons import Person, Persons
6 from PLC.Auth import Auth
8 class DeletePerson(Method):
10 Mark an existing account as deleted.
12 Users and techs can only delete themselves. PIs can only delete
13 themselves and other non-PIs at their sites. ins can delete
16 Returns 1 if successful, faults otherwise.
19 roles = ['admin', 'pi', 'user', 'tech']
23 Mixed(Person.fields['person_id'],
24 Person.fields['email'])
27 returns = Parameter(int, '1 if successful')
29 def call(self, auth, person_id_or_email):
30 # Get account information
31 persons = Persons(self.api, [person_id_or_email])
33 raise PLCInvalidArgument, "No such account"
36 if person['peer_id'] is not None:
37 raise PLCInvalidArgument, "Not a local account"
39 # Authenticated function
40 assert self.caller is not None
42 # Check if we can update this account
43 if not self.caller.can_update(person):
44 raise PLCPermissionDenied, "Not allowed to delete specified account"
49 self.event_objects = {'Person': [person['person_id']]}
50 self.message = 'Person %d deleted' % person['person_id']