Skip to content

Invite users improvements #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions controller/auth/kratos.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
KRATOS_IDENTITY_CACHE: Dict[str, Any] = {}
KRATOS_IDENTITY_CACHE_TIMEOUT = timedelta(minutes=30)

LANGUAGE_MESSAGES = {
"en": "Hello!\n\nClick the link to complete your account setup:\n\n",
"de": "Hallo!\n\nKlicken Sie auf den Link, um Ihre Kontoeinrichtung abzuschließen:\n\n",
}

INVITATION_SUBJECT = "Sie sind zu unserer app eingeladen/You are invited to our app"

LANGUAGE_EXPIRATION_INFO = {
"en": "This link can only be clicked once and is valid for 2 days. Contact your system admin if you have issues.",
"de": "Dieser Link kann nur einmal angeklickt werden und ist 2 Tage lang gültig. Kontaktieren Sie Ihren Systemadministrator, wenn Sie Probleme haben.",
}


def get_cached_values(update_db_users: bool = True) -> Dict[str, Dict[str, Any]]:
global KRATOS_IDENTITY_CACHE
Expand Down Expand Up @@ -239,9 +251,9 @@ def get_recovery_link(user_id: str) -> str:

def email_with_link(to_email: str, recovery_link: str) -> None:
msg = MIMEText(
f"Welcome! Click the link to complete your account setup:\n\n{recovery_link}"
f"{LANGUAGE_MESSAGES['de']}{recovery_link}\n\n{LANGUAGE_EXPIRATION_INFO['de']}\n\n\n------\n\n{LANGUAGE_MESSAGES['en']}{recovery_link}\n\n{LANGUAGE_EXPIRATION_INFO['en']}",
)
msg["Subject"] = "You're invited to our app!"
msg["Subject"] = INVITATION_SUBJECT
msg["From"] = "[email protected]"
msg["To"] = to_email

Expand Down
4 changes: 4 additions & 0 deletions controller/auth/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def invite_users(
emails: List[str],
organization_name: str,
user_role: str,
language: str,
provider: Optional[str] = None,
):
user_ids = []
Expand All @@ -192,6 +193,9 @@ def invite_users(
# Assign the user role
user_manager.update_user_role(user["id"], user_role)

# Add the preferred language
user_manager.update_user_field(user["id"], "language_display", language)

# Get the recovery link for the email
recovery_link = kratos.get_recovery_link(user["id"])
if not recovery_link:
Expand Down
1 change: 1 addition & 0 deletions fast_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ class InviteUsersBody(BaseModel):
organization_name: StrictStr
provider: Optional[StrictStr] = None
user_role: StrictStr
language: StrictStr


class CheckInviteUsersBody(BaseModel):
Expand Down
6 changes: 5 additions & 1 deletion fast_api/routes/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ def invite_users(request: Request, body: InviteUsersBody = Body(...)):
if not auth.check_is_full_admin(request):
raise AuthManagerError("Full admin access required")
data = auth.invite_users(
body.emails, body.organization_name, body.user_role, body.provider
body.emails,
body.organization_name,
body.user_role,
body.language,
body.provider,
)
return pack_json_result(data)

Expand Down
1 change: 1 addition & 0 deletions tests/fast_api/routes/test_invite_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_invite_users(client: TestClient, org: Organization):
"organization_name": org.name,
"emails": valid_emails_to_test,
"user_role": UserRoles.ENGINEER.value,
"language": "en",
},
)
assert response.status_code == 200
Expand Down