Add 'php/phpxmlrpc/' from commit 'cd5dbb4a511e7a616a61187a5de1a611a9748cbd'
[plcapi.git] / PLC / Methods / DeleteNodeTag.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4
5 from PLC.Faults import *
6 from PLC.Method import Method
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.Auth import Auth
9
10 from PLC.Sites import Site, Sites
11 from PLC.Nodes import Node, Nodes
12 from PLC.TagTypes import TagType, TagTypes
13 from PLC.NodeTags import NodeTag, NodeTags
14
15 class DeleteNodeTag(Method):
16     """
17     Deletes the specified node tag
18
19     Admins have full access.  Non-admins need to 
20     (1) have at least one of the roles attached to the tagtype, 
21     and (2) belong in the same site as the tagged subject.
22
23     Returns 1 if successful, faults otherwise.
24     """
25
26     roles = ['admin', 'pi', 'user', 'tech']
27
28     accepts = [
29         Auth(),
30         NodeTag.fields['node_tag_id']
31         ]
32
33     returns = Parameter(int, '1 if successful')
34
35     def call(self, auth, node_tag_id):
36         node_tags = NodeTags(self.api, [node_tag_id])
37         if not node_tags:
38             raise PLCInvalidArgument, "No such node tag %r"%node_tag_id
39         node_tag = node_tags[0]
40
41         tag_type_id = node_tag['tag_type_id']
42         tag_type = TagTypes (self.api,[tag_type_id])[0]
43
44         nodes = Nodes (self.api, node_tag['node_id'])
45         if not nodes:
46             raise PLCInvalidArgument, "No such node %d"%node_tag['node_id']
47         node=nodes[0]
48
49         # check authorizations
50         node.caller_may_write_tag(self.api,self.caller,tag_type)
51
52         node_tag.delete()
53         self.object_ids = [node_tag['node_tag_id']]
54
55         return 1