propagate caller in more places
[plcapi.git] / PLC / Methods / DeleteSiteTag.py
index f0e87c3..28eb768 100644 (file)
@@ -11,6 +11,7 @@ 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 DeleteSiteTag(Method):
@@ -41,18 +42,15 @@ class DeleteSiteTag(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.person_access_tag_type (self.api, self.caller, tag_type):
-            raise PLCPermissionDenied, "%s, no permission to use this tag type"%self.name
-        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.delete()
         self.object_ids = [site_tag['site_tag_id']]