add/update/delete slice tags should be fine
[plcapi.git] / PLC / Methods / DeleteSiteTag.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.Sites import Site, Sites
10 from PLC.Nodes import Nodes
11 from PLC.TagTypes import TagType, TagTypes
12 from PLC.SiteTags import SiteTag, SiteTags
13
14 from PLC.AuthorizeHelpers import AuthorizeHelpers
15
16 class DeleteSiteTag(Method):
17     """
18     Deletes the specified site setting
19
20     Admins have full access.  Non-admins need to 
21     (1) have at least one of the roles attached to the tagtype, 
22     and (2) belong in the same site as the tagged subject.
23
24     Returns 1 if successful, faults otherwise.
25     """
26
27     roles = ['admin', 'pi', 'user']
28
29     accepts = [
30         Auth(),
31         SiteTag.fields['site_tag_id']
32         ]
33
34     returns = Parameter(int, '1 if successful')
35
36     def call(self, auth, site_tag_id):
37         site_tags = SiteTags(self.api, [site_tag_id])
38         if not site_tags:
39             raise PLCInvalidArgument, "No such site tag %r"%site_tag_id
40         site_tag = site_tags[0]
41
42         tag_type_id = site_tag['tag_type_id']
43         tag_type = TagTypes (self.api,[tag_type_id])[0]
44         site = Sites (self.api, site_tag['site_id'])
45         
46         # check authorizations
47         if 'admin' in self.caller['roles']:
48             pass
49         elif not AuthorizeHelpers.caller_may_access_tag_type (self.api, self.caller, tag_type):
50             raise PLCPermissionDenied, "%s, forbidden tag %s"%(self.name,tag_type['tagname'])
51         elif AuthorizeHelpers.person_in_site (self.api, self.caller, site):
52             pass
53         else:
54             raise PLCPermissionDenied, "%s: you must be part of the subject site"%self.name
55             
56         site_tag.delete()
57         self.object_ids = [site_tag['site_tag_id']]
58
59         return 1