2 # Thierry Parmentelat - INRIA
5 from PLC.Faults import *
6 from PLC.Method import Method
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.Auth import Auth
10 from PLC.Ilinks import Ilink, Ilinks
11 from PLC.Interfaces import Interface, Interfaces
12 from PLC.TagTypes import TagType, TagTypes
13 from PLC.Sites import Sites
15 from PLC.AuthorizeHelpers import AuthorizeHelpers
17 class UpdateIlink(Method):
19 Updates the value of an existing ilink
21 Access rights depend on the tag type.
23 Returns 1 if successful, faults otherwise.
26 roles = ['admin', 'pi', 'tech', 'user']
30 Ilink.fields['ilink_id'],
34 returns = Parameter(int, '1 if successful')
36 object_type = 'Interface'
38 def call(self, auth, ilink_id, value):
39 ilinks = Ilinks(self.api, [ilink_id])
41 raise PLCInvalidArgument("No such ilink %r"%ilink_id)
44 src_if=Interfaces(self.api,ilink['src_interface_id'])[0]
45 dst_if=Interfaces(self.api,ilink['dst_interface_id'])[0]
46 tag_type_id = ilink['tag_type_id']
47 tag_type = TagTypes (self.api,[tag_type_id])[0]
49 # check authorizations
50 if 'admin' in self.caller['roles']:
52 elif not AuthorizeHelpers.caller_may_access_tag_type (self.api, self.caller, tag_type):
53 raise PLCPermissionDenied("%s, forbidden tag %s"%(self.name,tag_type['tagname']))
54 elif AuthorizeHelpers.interface_belongs_to_person (self.api, src_if, self.caller):
56 elif src_if_id != dst_if_id and AuthorizeHelpers.interface_belongs_to_person (self.api, dst_if, self.caller):
59 raise PLCPermissionDenied("%s: you must own either the src or dst interface"%self.name)
61 ilink['value'] = value
64 self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]