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