580e97b27fde266400c4081c51949a234af6c356
[plcapi.git] / PLC / Methods / SliceListUserSlices.py
1 from PLC.Method import Method
2 from PLC.Parameter import Parameter, Mixed
3 from PLC.Filter import Filter
4 from PLC.Auth import Auth
5 from PLC.Slices import Slice, Slices
6 from PLC.Persons import Person, Persons
7 from PLC.Methods.GetSlices import GetSlices
8
9 class SliceListUserSlices(GetSlices):
10     """
11     Deprecated. Can be implemented with GetPersons.
12
13     Return the slices the specified user (by email address) is a member of.
14
15     Users may only query slices of which they are members. PIs may
16     query any of the slices at their sites. Admins may query any
17     slice. If a slice that cannot be queried is specified in
18     slice_filter, details about that slice will not be returned.
19     """
20
21     roles = ['admin', 'pi', 'user']
22
23     accepts = [
24         Auth(),
25         Parameter(str, "Slice prefix", nullok = True)
26         ]
27
28     returns = [Slice.fields]
29     
30
31     def call(self, auth, email):
32
33         persons = Persons(self.api, [email])
34         if not persons:
35                 return []
36         person = persons[0]
37         slice_ids = person['slice_ids']
38         if not slice_ids:
39                 return []
40         
41         slices = GetSlices.call(self, auth, slice_ids)
42         slice_names = [slice['name'] for slice in slices]
43
44         return slice_names