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.Slices import Slice, Slices
6 from PLC.Auth import Auth
8 class DeletePersonFromSlice(Method):
10 Deletes the specified person from the specified slice. If the person is
11 not a member of the slice, no errors are returned.
13 Returns 1 if successful, faults otherwise.
16 roles = ['admin', 'pi']
20 Mixed(Person.fields['person_id'],
21 Person.fields['email']),
22 Mixed(Slice.fields['slice_id'],
26 returns = Parameter(int, '1 if successful')
28 def call(self, auth, person_id_or_email, slice_id_or_name):
29 # Get account information
30 persons = Persons(self.api, [person_id_or_email])
32 raise PLCInvalidArgument, "No such account"
36 # Get slice information
37 slices = Slices(self.api, [slice_id_or_name])
39 raise PLCInvalidArgument, "No such slice"
43 # If we are not admin, make sure the caller is a pi
44 # of the site associated with the slice
45 if 'admin' not in self.caller['roles']:
46 if slice['site_id'] not in self.caller['site_ids']:
47 raise PLCPermissionDenied, "Not allowed to delete users from this slice"
49 if slice['slice_id'] in person['slice_ids']:
50 slice.remove_person(person)