only add the person to the site if this is a new record
[sfa.git] / sfa / methods / register.py
index 31220ea..863d6c5 100644 (file)
@@ -13,6 +13,7 @@ from sfa.util.genitable import GeniTable
 from sfa.util.debug import log
 from sfa.trust.auth import Auth
 from sfa.trust.gid import create_uuid
+from sfa.trust.credential import Credential
 
 class register(Method):
     """
@@ -35,8 +36,13 @@ class register(Method):
 
     returns = Parameter(int, "String representation of gid object")
     
-    def call(self, cred, record_dict):
+    def call(self, cred, record_dict, caller_cred=None):
         self.api.auth.check(cred, "register")
+        if caller_cred==None:
+               caller_cred=cred
+       
+        #log the call
+        self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, Credential(string=caller_cred).get_gid_caller().get_hrn(), None, self.name))
         record = GeniRecord(dict = record_dict)
         table = GeniTable()
         type = record['type']
@@ -106,8 +112,13 @@ class register(Method):
  
             if 'enabled' in record and record['enabled']:
                 self.api.plshell.UpdatePerson(self.api.plauth, pointer, {'enabled': record['enabled']})
-            login_base = get_leaf(auth_name)
-            self.api.plshell.AddPersonToSite(self.api.plauth, pointer, login_base)
+           
+            # add this persons to the site only if he is being added for the first
+            # time by sfa and doesont already exist in plc     
+            if not persons or not persons[0]['site_ids']:
+                login_base = get_leaf(auth_name)
+                self.api.plshell.AddPersonToSite(self.api.plauth, pointer, login_base)
+
             # What roles should this user have?
             self.api.plshell.AddRoleToPerson(self.api.plauth, 'user', pointer) 
             record.set_pointer(pointer)