reviewing the tags permission system
[plcapi.git] / PLC / Methods / DeleteSliceTag.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4 from PLC.Faults import *
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.Auth import Auth
8
9 from PLC.SliceTags import SliceTag, SliceTags
10 from PLC.Slices import Slice, Slices
11 from PLC.Nodes import Node, Nodes
12
13 from PLC.AuthorizeHelpers import AuthorizeHelpers
14
15 class DeleteSliceTag(Method):
16     """
17     Deletes the specified slice or sliver attribute.
18
19     Attributes may require the caller to have a particular role in
20     order to be deleted. Users may only delete attributes of
21     slices or slivers of which they are members. PIs may only delete
22     attributes of slices or slivers at their sites, or of which they
23     are members. Admins may delete attributes of any slice or sliver.
24
25     Returns 1 if successful, faults otherwise.
26     """
27
28     roles = ['admin', 'pi', 'user', 'tech']
29
30     accepts = [
31         Auth(),
32         SliceTag.fields['slice_tag_id']
33         ]
34
35     returns = Parameter(int, '1 if successful')
36
37     def call(self, auth, slice_tag_id):
38         slice_tags = SliceTags(self.api, [slice_tag_id])
39         if not slice_tags:
40             raise PLCInvalidArgument, "No such slice attribute"
41         slice_tag = slice_tags[0]
42
43         slices = Slices(self.api, [slice_tag['slice_id']])
44         if not slices:
45             raise PLCInvalidArgument, "No such slice"
46         slice = slices[0]
47
48         assert slice_tag['slice_tag_id'] in slice['slice_tag_ids']
49
50         if 'admin' not in self.caller['roles']:
51             if self.caller['person_id'] in slice['person_ids']:
52                 pass
53             elif 'pi' not in self.caller['roles']:
54                 raise PLCPermissionDenied, "Not a member of the specified slice"
55             elif slice['site_id'] not in self.caller['site_ids']:
56                 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
57
58             if slice_tag['min_role_id'] is not None and \
59                min(self.caller['role_ids']) > slice_tag['min_role_id']:
60                 raise PLCPermissioinDenied, "Not allowed to delete the specified attribute"
61
62         slice_tag.delete()
63         self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
64
65         return 1