+ users = self.backend.get_user_list()
+ roles = self.backend.get_role_list({"name": "system_admin"})
+ role_id = roles[0]["_id"]
+ user_with_system_admin = False
+ user_admin_id = None
+ for user in users:
+ if not user_admin_id:
+ user_admin_id = user["_id"]
+ if user["username"] == "admin":
+ user_admin_id = user["_id"]
+ for prm in user.get("project_role_mappings", ()):
+ if prm["role"] == role_id:
+ user_with_system_admin = True
+ break
+ if user_with_system_admin:
+ break
+ if not user_with_system_admin:
+ self.backend.update_user({"_id": user_admin_id,
+ "add_project_role_mappings": [{"project": pid, "role": role_id}]})
+ self.logger.info("Added role system admin to user='{}' project=admin".format(user_admin_id))
+ except Exception as e:
+ self.logger.error("Error in Authorization DataBase initialization: {}: {}".format(type(e).__name__, e))