fix db bootstrap scripts - AddPerson/UpdatePerson won't let you set person_id anymore
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 12 Dec 2012 08:15:42 +0000 (09:15 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 12 Dec 2012 08:15:42 +0000 (09:15 +0100)
db-config.d/001-admin_user
db-config.d/002-system_site

index 6532530..74a9723 100644 (file)
@@ -2,15 +2,16 @@
 #################### 
 # Create/update the default administrator account (should be person_id 2).
 
-admin = { 'person_id': 2,
-          'first_name': "Default",
+the_admin_id=2
+admin = { 'first_name': "Default",
           'last_name': "Administrator",
           'email': plc['root_user'],
           'password': plc['root_password'] }
-persons = GetPersons([admin['person_id']])
+persons = GetPersons(the_admin_id)
 if not persons:
+    # AddPerson won't let you pass a person_id
     person_id = AddPerson(admin)
-    if person_id != admin['person_id']:
+    if person_id != the_admin_id:
         # Huh? Someone deleted the account manually from the database.
         DeletePerson(person_id)
         raise Exception, "Someone deleted the \"%s %s\" account from the database!" % \
index 12e00a7..4a60581 100644 (file)
@@ -34,17 +34,17 @@ site_id = sites[0]['site_id']
 UpdateSite(site_id, site)
 
 # The default administrator account must be associated with a site
-# in order to login.
-AddPersonToSite(admin['person_id'], site['site_id'])
-SetPersonPrimarySite(admin['person_id'], site['site_id'])
+# in order to login - see 001-admin_user
+AddPersonToSite(the_admin_id, site['site_id'])
+SetPersonPrimarySite(the_admin_id, site['site_id'])
 
 # Grant admin and PI roles to the default administrator account
-AddRoleToPerson(10, admin['person_id'])
-AddRoleToPerson(20, admin['person_id'])
+AddRoleToPerson(10, the_admin_id)
+AddRoleToPerson(20, the_admin_id)
 
 # Associate root ssh key with the default administrator
 keyfile=plc['root_ssh_key_pub']
-person = GetPersons(admin['person_id'])[0]
+person = GetPersons(the_admin_id)[0]
 keys = GetKeys(person['key_ids'])
 if os.path.exists(keyfile):
     sshkeyfp = file(keyfile,"r")
@@ -60,7 +60,7 @@ if os.path.exists(keyfile):
                 # should we delete other keys?
                 pass
     if not found:
-        key_id = AddPersonKey(admin['person_id'],{'key_type':'ssh','key':sshkey})
+        key_id = AddPersonKey(the_admin_id,{'key_type':'ssh','key':sshkey})
 else:
     if len(keys)==0:
         print "WARNING: default administrator does not have an ssh key"