feat(auth): support dual-email schema (internal mail and recovery-email) in bootstrap script
Core Architecture & Invariant CI / validate (push) Successful in 9m42s

This commit is contained in:
kiskaadee committed 2026-09-15 01:59:11 -05:00
1 parent 1a02872fa5
commit 666e7a6900
1 file changed
+66 -8
+66 -8
View File
@@ -19,20 +19,38 @@ INITIAL_GROUPS = ["admins", "dev", "users"]
INITIAL_USERS = [ INITIAL_USERS = [
{ {
"id": "kiskaadee", "id": "kiskaadee",
"email": "fcortesbio@gmail.com", "email": "kiskaadee@roadtotech.me",
"displayName": "kiskaadee", "displayName": "kiskaadee",
"firstName": "Andrés",
"lastName": "Cortés",
"recoveryEmail": "fcortesbio@gmail.com",
"groups": ["admins", "dev"], "groups": ["admins", "dev"],
}, },
{ {
"id": "misa", "id": "lusm1302",
"email": "icdf0728@gmail.com", "email": "lusm1302@roadtotech.me",
"displayName": "misa", "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"], "groups": ["users"],
}, },
{ {
"id": "valenvg", "id": "valenvg",
"email": "vegavalentina069@gmail.com", "email": "valenvg@roadtotech.me",
"displayName": "valenvg", "displayName": "Valen",
"firstName": "Valentina",
"lastName": "Vega",
"recoveryEmail": "vegavalentina069@gmail.com",
"groups": ["users"], "groups": ["users"],
}, },
] ]
@@ -104,6 +122,20 @@ def bootstrap():
else: else:
print(f" ℹ️ Group {group_name} already exists.") 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 # 2. Fetch existing users
users_res = query_graphql(LLDAP_URL, token, "{ users { id email displayName } }") 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", [])} 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: for user in INITIAL_USERS:
uid = user["id"] 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: if uid not in existing_users:
print(f" ➕ Creating user: {uid} ({user['email']})...") print(f" ➕ Creating user: {uid} ({user['email']})...")
mutation = f""" mutation = f"""
@@ -118,7 +158,10 @@ def bootstrap():
createUser(user: {{ createUser(user: {{
id: "{uid}", id: "{uid}",
email: "{user['email']}", email: "{user['email']}",
displayName: "{user['displayName']}" displayName: "{user['displayName']}",
{first_name}
{last_name}
{rec_attr}
}}) {{ }}) {{
id id
email email
@@ -132,7 +175,22 @@ def bootstrap():
else: else:
print(f" ✅ User {uid} created.") print(f" ✅ User {uid} created.")
else: 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 # Assign user to groups
for group_name in user.get("groups", []): for group_name in user.get("groups", []):