04c13fe7d97bd13511ea1e44cefeedaa9fd40fe7
[plcapi.git] / PLC / Methods / SliceUserDel.py
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
7
8 class SliceUserDel(Method):
9     """
10     Deprecated. Can be implemented with DeletePersonFromSlice.
11
12     Removes the specified users from the specified slice. If the person is
13     already a member of the slice, no errors are returned. 
14
15     Returns 1 if successful, faults otherwise.
16     """
17
18     roles = ['admin', 'pi']
19
20     accepts = [
21         Auth(),
22         Slice.fields['name'],
23         [Person.fields['email']],
24         ]
25
26     returns = Parameter(int, '1 if successful')
27
28     def call(self, auth, slice_name, user_list):
29         # Get account information
30         persons = Persons(self.api, user_list)
31         if not persons:
32             raise PLCInvalidArgument, "No such account"
33
34         # Get slice information
35         slices = Slices(self.api, [slice_id_or_name])
36         if not slices:
37             raise PLCInvalidArgument, "No such slice"
38
39         slice = slices[0]
40         if slice['peer_id'] is not None:
41             raise PLCInvalidArgument, "Not a local slice"
42
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 add users to this slice"
48         
49         for person in persons:
50             if person['person_id'] in slice['person_ids']:
51                 slice.remove_person(person, False)
52         
53         slice.sync()
54         self.object_ids = [slice['slice_id']]
55
56         return 1