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.Slices import Slice, Slices
8 from PLC.Auth import Auth
10 class DeletePersonFromSlice(Method):
12 Deletes the specified person from the specified slice. If the person is
13 not a member of the slice, no errors are returned.
15 Returns 1 if successful, faults otherwise.
18 roles = ['admin', 'pi']
22 Mixed(Person.fields['person_id'],
23 Person.fields['email']),
24 Mixed(Slice.fields['slice_id'],
28 returns = Parameter(int, '1 if successful')
30 def call(self, auth, person_id_or_email, slice_id_or_name):
31 # Get account information
32 persons = Persons(self.api, [person_id_or_email])
34 raise PLCInvalidArgument, "No such account"
37 # Get slice information
38 slices = Slices(self.api, [slice_id_or_name])
40 raise PLCInvalidArgument, "No such slice"
43 # N.B. Allow foreign users to be added to local slices and
44 # local users to be added to foreign slices (and, of course,
45 # local users to be added to local slices).
46 if person['peer_id'] is not None and slice['peer_id'] is not None:
47 raise PLCInvalidArgument, "Cannot delete foreign users from foreign slices"
49 # If we are not admin, make sure the caller is a pi
50 # of the site associated with the slice
51 if 'admin' not in self.caller['roles']:
52 if slice['site_id'] not in self.caller['site_ids']:
53 raise PLCPermissionDenied, "Not allowed to delete users from this slice"
55 if slice['slice_id'] in person['slice_ids']:
56 slice.remove_person(person)
58 self.event_objects = {'Slice': [slice['slice_id']],
59 'Person': [person['person_id']]}