Skip to content
Snippets Groups Projects
Commit 7dd23fbd authored by Daniel Göbel's avatar Daniel Göbel
Browse files

Merge branch 'bugfix/10-fix-invitation-email-template' into 'main'

Resolve "Fix invitation email template"

Closes #10

See merge request !10
parents 7ce8fdbc 2c9087b4
No related branches found
No related tags found
1 merge request!10Resolve "Fix invitation email template"
Pipeline #53598 passed
......@@ -106,7 +106,7 @@ async def login(
current_span.set_attribute("invitation_uid", str(user.uid))
if (
round(time.time()) - (0 if user.invitation_token_created_at is None else user.invitation_token_created_at)
> 84200
> 43200 # 12 hours
):
raise LoginException(error_source="expired invitation link")
request.session[INVITATION_UID_KEY] = str(user.uid)
......@@ -260,7 +260,7 @@ async def login_callback(
async def logout(response: RedirectResponse) -> str:
"""
Logout the user from the system by deleting the bearer cookie.
\f
Parameters
----------
response : fastapi.responses.RedirectResponse
......
......@@ -57,6 +57,7 @@ async def create_user(
current_span.set_attribute("uid", str(user.uid))
token = await CRUDUser.create_invitation_token(user.uid, db=db)
background_tasks.add_task(send_invitation_email, user=user, token=token)
await db.refresh(user, attribute_names=["invitation_token_created_at"])
return UserOutExtended.from_db_user(user)
......@@ -263,5 +264,6 @@ async def resend_invitation(
if user.invitation_token is None:
raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=f"user {user.uid} has not open invitation")
token = await CRUDUser.create_invitation_token(user.uid, db=db)
await db.refresh(user, attribute_names=["invitation_token_created_at"])
background_tasks.add_task(send_invitation_email, user=user, token=token)
return UserOutExtended.from_db_user(user)
......@@ -37,7 +37,12 @@ class UserRoles(BaseModel):
class UserOutExtended(UserOut, UserRoles):
lifescience_id: str | None = Field(None, description="Lifesicence ID of the user")
lifescience_id: str | None = Field(
None, description="Lifesicence ID of the user", examples=["18b59678f16d2c59306c0aedb1dc7ddcfe162456'"]
)
invitation_token_created_at: int | None = Field(
None, description="Timestamp when the invitation token was created as UNIX timestamp"
)
@staticmethod
def from_db_user(user: User) -> "UserOutExtended":
......@@ -47,4 +52,5 @@ class UserOutExtended(UserOut, UserRoles):
display_name=user.display_name,
roles=[mapping.get_role_name(role.role_id) for role in user.roles],
lifescience_id=user.lifescience_id,
invitation_token_created_at=user.invitation_token_created_at,
)
......@@ -2,5 +2,6 @@
<p>Hello ${user.display_name}</p>
<p>the administrator of CloWM created an account for you. Click on the link below and connect your account with one of the available identity providers.</p>
<p><a href=${invitation_link}>${invitation_link}</a></p>
<p>This link will expire in 24 hours.</p>
<p><a href="${invitation_link}">${invitation_link}</a></p>
<p>This link will expire in 12 hours. If the link is expired, reply to this email and you will get an new invitation \
link send to you.</p>
......@@ -6,4 +6,5 @@ the available identity providers.
${invitation_link}
This link will expire in 24 hours.
This link will expire in 12 hours. If the link is expired, reply to this email and you will get an new invitation \
link send to you.
......@@ -339,6 +339,7 @@ class TestUserRoutesCreate(_TestUserRoutes):
assert user.lifescience_id is None
assert user.roles[0] == user_in.roles[0]
assert user.display_name == user_in.display_name
assert user.invitation_token_created_at is not None
db_user = await db.scalar(select(User).where(User.uid == user.uid))
assert db_user is not None
......@@ -385,6 +386,7 @@ class TestUserRoutesCreate(_TestUserRoutes):
assert len(user.roles) == 0
assert user.lifescience_id is None
assert user.display_name == user_in.display_name
assert user.invitation_token_created_at is not None
db_user = await db.scalar(select(User).where(User.uid == user.uid))
assert db_user is not None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment