from PLC.Auth import Auth
from PLC.Sites import Site, Sites
-from PLC.Nodes import Nodes
from PLC.TagTypes import TagType, TagTypes
from PLC.SiteTags import SiteTag, SiteTags
+# need to import so the core classes get decorated with caller_may_write_tag
from PLC.AuthorizeHelpers import AuthorizeHelpers
class UpdateSiteTag(Method):
tag_type_id = site_tag['tag_type_id']
tag_type = TagTypes (self.api,[tag_type_id])[0]
- site = Sites (self.api, site_tag['site_id'])
+
+ sites = Sites (self.api, site_tag['site_id'])
+ if not sites:
+ raise PLCInvalidArgument, "No such site %d"%site_tag['site_id']
+ site=sites[0]
# check authorizations
- if 'admin' in self.caller['roles']:
- pass
- elif not AuthorizeHelpers.caller_may_access_tag_type (self.api, self.caller, tag_type):
- raise PLCPermissionDenied, "%s, forbidden tag %s"%(self.name,tag_type['tagname'])
- elif AuthorizeHelpers.person_belongs_to_site (self.api, self.caller, site):
- pass
- else:
- raise PLCPermissionDenied, "%s: you must be part of the subject site"%self.name
+ site.caller_may_write_tag(self.api,self.caller,tag_type)
site_tag['value'] = value
site_tag.sync()