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