locate_or_create_tag returns tag_type, and not tag_type_id anymore
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 25 Nov 2010 15:05:34 +0000 (16:05 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 25 Nov 2010 15:05:34 +0000 (16:05 +0100)
accessors are now fully type-checked
accessors to use the caller_may_write_tag method if exists

PLC/Accessor.py
PLC/Accessors/Factory.py
PLC/Method.py

index 39e7872..d4af37d 100644 (file)
@@ -28,7 +28,7 @@ This is implemented as a singleton, so we can cache results over time"""
 
     def has_cache (self,tagname): return self.cache.has_key(tagname)
     def get_cache (self,tagname): return self.cache[tagname]
-    def set_cache (self,tagname,tag_id): self.cache[tagname]=tag_id
+    def set_cache (self,tagname,tag_type): self.cache[tagname]=tag_type
 
     def locate_or_create_tag (self, tagname, category, description, roles):
         "search tag type from tagname & create if needed"
@@ -54,9 +54,8 @@ This is implemented as a singleton, so we can cache results over time"""
                 except:
                     # xxx todo find a more appropriate way of notifying this
                     print "Accessor.locate_or_create_tag: Could not add role %r to tag_type %s"%(role,tagname)
-        tag_type_id = tag_type['tag_type_id']
-        self.set_cache(tagname,tag_type_id)
-        return tag_type_id
+        self.set_cache(tagname,tag_type)
+        return tag_type
 
 
 ####################
index 01d8c81..2629587 100644 (file)
@@ -21,8 +21,7 @@ from PLC.SiteTags import SiteTags, SiteTag
 from PLC.Persons import Persons, Person
 from PLC.PersonTags import PersonTags, PersonTag
 
-# this is another story..
-#from PLC.Ilinks import Ilink
+from PLC.AuthorizeHelpers import AuthorizeHelpers
 
 # known classes : { class -> details }
 taggable_classes = { Node : {'table_class' : Nodes,
@@ -40,7 +39,6 @@ taggable_classes = { Node : {'table_class' : Nodes,
                      Person: {'table_class' : Persons,
                              'joins_class': PersonTags, 'join_class': PersonTag,
                              'secondary_key':'email'},
-#                     Ilink : xxx
                      }
 
 # xxx probably defined someplace else
@@ -117,12 +115,14 @@ def define_accessors (module, objclass, methodsuffix, tagname,
     setattr(get_class,'roles',get_roles)
     setattr(get_class,'accepts',get_accepts)
     setattr(get_class,'returns', get_returns)
-    setattr(get_class,'skip_typecheck',True)
+# that was useful for legacy method only, but we now need type_checking
+#    setattr(get_class,'skip_type_check',True)
 
     setattr(set_class,'roles',set_roles)
     setattr(set_class,'accepts',set_accepts)
     setattr(set_class,'returns', set_returns)
-    setattr(set_class,'skip_typecheck',True)
+# that was useful for legacy method only, but we now need type_checking
+#    setattr(set_class,'skip_type_check',True)
 
     table_class = taggable_classes[objclass]['table_class']
     joins_class = taggable_classes[objclass]['joins_class']
@@ -143,7 +143,8 @@ def define_accessors (module, objclass, methodsuffix, tagname,
     def get_call (self, auth, id_or_name):
         # locate the tag, see above
         locator = getattr(Accessor,locator_name)
-        tag_type_id = locator(AccessorSingleton(self.api))
+        tag_type = locator(AccessorSingleton(self.api))
+        tag_type_id=tag_type['tag_type_id']
 
         filter = {'tag_type_id':tag_type_id}
         if isinstance (id_or_name,int):
@@ -167,16 +168,25 @@ def define_accessors (module, objclass, methodsuffix, tagname,
             filter={primary_key:id_or_name}
         else:
             filter={secondary_key:id_or_name}
-        objs = table_class(self.api, filter,[primary_key,secondary_key])
+# we need the full monty b/c of the permission system
+#        objs = table_class(self.api, filter,[primary_key,secondary_key])
+        objs = table_class(self.api, filter)
         if not objs:
             raise PLCInvalidArgument, "Cannot set tag on %s %r"%(objclass.__name__,id_or_name)
-        primary_id = objs[0][primary_key]
+        # the object being tagged
+        obj=objs[0]
+        primary_id = obj[primary_key]
 
         # locate the tag, see above
         locator = getattr(Accessor,locator_name)
-        tag_type_id = locator(AccessorSingleton(self.api))
+        tag_type = locator(AccessorSingleton(self.api))
+        tag_type_id = tag_type['tag_type_id']
 
-        # locate the join object (e.g. NodeTag, SliceTag or InterfaceTag)
+        # check authorization
+        if hasattr(objclass,'caller_may_write_tag'):
+            obj.caller_may_write_tag (self.api,self.caller,tag_type)
+
+        # locate the join object (e.g. NodeTag or similar)
         filter = {'tag_type_id':tag_type_id}
         if isinstance (id_or_name,int):
             filter[primary_key]=id_or_name
index 352640f..275316f 100644 (file)
@@ -4,10 +4,6 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id$
-# $URL$
-#
-
 import xmlrpclib
 from types import *
 import textwrap
@@ -84,7 +80,8 @@ class Method (object):
             start = time.time()
 
             # legacy code cannot be type-checked, due to the way Method.args() works
-            if not hasattr(self,"skip_typecheck"):
+            # as of 5.0-rc16 we don't use skip_type_check anymore
+            if not hasattr(self,"skip_type_check"):
                 (min_args, max_args, defaults) = self.args()
 
                 # Check that the right number of arguments were passed in