a slightly clearer version of GetSliceFamily
[plcapi.git] / PLC / Methods / DeleteInterfaceTag.py
index 187d25e..5ef9635 100644 (file)
@@ -12,6 +12,9 @@ from PLC.Interfaces import Interface, Interfaces
 from PLC.TagTypes import TagType, TagTypes
 from PLC.InterfaceTags import InterfaceTag, InterfaceTags
 
+# need to import so the core classes get decorated with caller_may_write_tag
+from PLC.AuthorizeHelpers import AuthorizeHelpers
+
 class DeleteInterfaceTag(Method):
     """
     Deletes the specified interface setting
@@ -40,17 +43,14 @@ class DeleteInterfaceTag(Method):
 
         tag_type_id = interface_tag['tag_type_id']
         tag_type = TagTypes (self.api,[tag_type_id])[0]
-        interface = Interfaces (self.api, interface_tag['interface_id'])
+
+        interfaces = Interfaces (self.api, interface_tag['interface_id'])
+        if not interfaces:
+            raise PLCInvalidArgument, "No such interface %d"%interface_tag['interface_id']
+        interface=interfaces[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.interface_belongs_to_person (self.api, interface, self.caller):
-            pass
-        else:
-            raise PLCPermissionDenied, "%s: you must belong in the same site as subject interface"%self.name
+        interface.caller_may_write_tag(self.api,self.caller,tag_type)
 
         interface_tag.delete()
         self.object_ids = [interface_tag['interface_tag_id']]