Skip to content

Commit b35069f

Browse files
Invite users improvements (#318)
* Language added to users table * Added Dutch to the app * SUbmodules update * Expiration info languages * Changed template for invitation
1 parent 499016f commit b35069f

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

controller/auth/kratos.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
KRATOS_IDENTITY_CACHE: Dict[str, Any] = {}
2626
KRATOS_IDENTITY_CACHE_TIMEOUT = timedelta(minutes=30)
2727

28+
LANGUAGE_MESSAGES = {
29+
"en": "Hello!\n\nClick the link to complete your account setup:\n\n",
30+
"de": "Hallo!\n\nKlicken Sie auf den Link, um Ihre Kontoeinrichtung abzuschließen:\n\n",
31+
}
32+
33+
INVITATION_SUBJECT = "Sie sind zu unserer app eingeladen/You are invited to our app"
34+
35+
LANGUAGE_EXPIRATION_INFO = {
36+
"en": "This link can only be clicked once and is valid for 2 days. Contact your system admin if you have issues.",
37+
"de": "Dieser Link kann nur einmal angeklickt werden und ist 2 Tage lang gültig. Kontaktieren Sie Ihren Systemadministrator, wenn Sie Probleme haben.",
38+
}
39+
2840

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

240252
def email_with_link(to_email: str, recovery_link: str) -> None:
241253
msg = MIMEText(
242-
f"Welcome! Click the link to complete your account setup:\n\n{recovery_link}"
254+
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']}",
243255
)
244-
msg["Subject"] = "You're invited to our app!"
256+
msg["Subject"] = INVITATION_SUBJECT
245257
msg["From"] = "[email protected]"
246258
msg["To"] = to_email
247259

controller/auth/manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def invite_users(
177177
emails: List[str],
178178
organization_name: str,
179179
user_role: str,
180+
language: str,
180181
provider: Optional[str] = None,
181182
):
182183
user_ids = []
@@ -192,6 +193,9 @@ def invite_users(
192193
# Assign the user role
193194
user_manager.update_user_role(user["id"], user_role)
194195

196+
# Add the preferred language
197+
user_manager.update_user_field(user["id"], "language_display", language)
198+
195199
# Get the recovery link for the email
196200
recovery_link = kratos.get_recovery_link(user["id"])
197201
if not recovery_link:

fast_api/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ class InviteUsersBody(BaseModel):
503503
organization_name: StrictStr
504504
provider: Optional[StrictStr] = None
505505
user_role: StrictStr
506+
language: StrictStr
506507

507508

508509
class CheckInviteUsersBody(BaseModel):

fast_api/routes/misc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,11 @@ def invite_users(request: Request, body: InviteUsersBody = Body(...)):
294294
if not auth.check_is_full_admin(request):
295295
raise AuthManagerError("Full admin access required")
296296
data = auth.invite_users(
297-
body.emails, body.organization_name, body.user_role, body.provider
297+
body.emails,
298+
body.organization_name,
299+
body.user_role,
300+
body.language,
301+
body.provider,
298302
)
299303
return pack_json_result(data)
300304

tests/fast_api/routes/test_invite_users.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def test_invite_users(client: TestClient, org: Organization):
5757
"organization_name": org.name,
5858
"emails": valid_emails_to_test,
5959
"user_role": UserRoles.ENGINEER.value,
60+
"language": "en",
6061
},
6162
)
6263
assert response.status_code == 200

0 commit comments

Comments
 (0)