feat(auth): support dual-email schema (internal mail and recovery-email) in bootstrap script
Core Architecture & Invariant CI / validate (push) Successful in 9m42s
Core Architecture & Invariant CI / validate (push) Successful in 9m42s
This commit is contained in:
1 parent
1a02872fa5
commit
666e7a6900
1 file changed
+66
-8
@@ -19,20 +19,38 @@ INITIAL_GROUPS = ["admins", "dev", "users"]
|
||||
INITIAL_USERS = [
|
||||
{
|
||||
"id": "kiskaadee",
|
||||
"email": "fcortesbio@gmail.com",
|
||||
"email": "kiskaadee@roadtotech.me",
|
||||
"displayName": "kiskaadee",
|
||||
"firstName": "Andrés",
|
||||
"lastName": "Cortés",
|
||||
"recoveryEmail": "fcortesbio@gmail.com",
|
||||
"groups": ["admins", "dev"],
|
||||
},
|
||||
{
|
||||
"id": "misa",
|
||||
"email": "icdf0728@gmail.com",
|
||||
"displayName": "misa",
|
||||
"id": "lusm1302",
|
||||
"email": "lusm1302@roadtotech.me",
|
||||
"displayName": "Lu.",
|
||||
"firstName": "Luisa",
|
||||
"lastName": "Santos",
|
||||
"recoveryEmail": "luisita13029999@gmail.com",
|
||||
"groups": ["users"],
|
||||
},
|
||||
{
|
||||
"id": "misa0728",
|
||||
"email": "misa0728@roadtotech.me",
|
||||
"displayName": "Misa",
|
||||
"firstName": "Isabel",
|
||||
"lastName": "Anacona",
|
||||
"recoveryEmail": "icdf0728@gmail.com",
|
||||
"groups": ["users"],
|
||||
},
|
||||
{
|
||||
"id": "valenvg",
|
||||
"email": "vegavalentina069@gmail.com",
|
||||
"displayName": "valenvg",
|
||||
"email": "valenvg@roadtotech.me",
|
||||
"displayName": "Valen",
|
||||
"firstName": "Valentina",
|
||||
"lastName": "Vega",
|
||||
"recoveryEmail": "vegavalentina069@gmail.com",
|
||||
"groups": ["users"],
|
||||
},
|
||||
]
|
||||
@@ -104,6 +122,20 @@ def bootstrap():
|
||||
else:
|
||||
print(f" ℹ️ Group {group_name} already exists.")
|
||||
|
||||
# Ensure custom recovery-email attribute exists in schema
|
||||
schema_res = query_graphql(LLDAP_URL, token, "{ schema { userSchema { attributes { name } } } }")
|
||||
existing_attrs = [
|
||||
a["name"]
|
||||
for a in schema_res.get("data", {}).get("schema", {}).get("userSchema", {}).get("attributes", [])
|
||||
]
|
||||
if "recovery-email" not in existing_attrs:
|
||||
print(" ➕ Adding custom schema attribute: recovery-email...")
|
||||
add_attr_mutation = (
|
||||
'mutation { addUserAttribute(name: "recovery-email", attributeType: STRING, '
|
||||
'isList: false, isVisible: true, isEditable: true) { ok } }'
|
||||
)
|
||||
query_graphql(LLDAP_URL, token, add_attr_mutation)
|
||||
|
||||
# 2. Fetch existing users
|
||||
users_res = query_graphql(LLDAP_URL, token, "{ users { id email displayName } }")
|
||||
existing_users = {u["id"]: u for u in users_res.get("data", {}).get("users", [])}
|
||||
@@ -111,6 +143,14 @@ def bootstrap():
|
||||
|
||||
for user in INITIAL_USERS:
|
||||
uid = user["id"]
|
||||
rec_attr = (
|
||||
f'insertAttributes: [{{ name: "recovery-email", value: ["{user["recoveryEmail"]}"] }}]'
|
||||
if "recoveryEmail" in user
|
||||
else ""
|
||||
)
|
||||
first_name = f'firstName: "{user["firstName"]}",' if "firstName" in user else ""
|
||||
last_name = f'lastName: "{user["lastName"]}",' if "lastName" in user else ""
|
||||
|
||||
if uid not in existing_users:
|
||||
print(f" ➕ Creating user: {uid} ({user['email']})...")
|
||||
mutation = f"""
|
||||
@@ -118,7 +158,10 @@ def bootstrap():
|
||||
createUser(user: {{
|
||||
id: "{uid}",
|
||||
email: "{user['email']}",
|
||||
displayName: "{user['displayName']}"
|
||||
displayName: "{user['displayName']}",
|
||||
{first_name}
|
||||
{last_name}
|
||||
{rec_attr}
|
||||
}}) {{
|
||||
id
|
||||
email
|
||||
@@ -132,7 +175,22 @@ def bootstrap():
|
||||
else:
|
||||
print(f" ✅ User {uid} created.")
|
||||
else:
|
||||
print(f" ℹ️ User {uid} already exists.")
|
||||
print(f" ℹ️ User {uid} already exists; syncing attributes...")
|
||||
update_mutation = f"""
|
||||
mutation {{
|
||||
updateUser(user: {{
|
||||
id: "{uid}",
|
||||
email: "{user['email']}",
|
||||
displayName: "{user['displayName']}",
|
||||
{first_name}
|
||||
{last_name}
|
||||
{rec_attr}
|
||||
}}) {{
|
||||
ok
|
||||
}}
|
||||
}}
|
||||
"""
|
||||
query_graphql(LLDAP_URL, token, update_mutation)
|
||||
|
||||
# Assign user to groups
|
||||
for group_name in user.get("groups", []):
|
||||
|
||||
Reference in new issue
Block a user