mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 14:56:01 +00:00
run fmt
This commit is contained in:
@@ -109,14 +109,14 @@ def add_user(
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
)
|
||||
def create_invite_link(
|
||||
request: Request, role: str, expiration_seconds: int | None = None
|
||||
request: Request, role: str, expiration: int | None = None
|
||||
) -> InviteLinkSchema:
|
||||
"""Create an invite link for a user.
|
||||
|
||||
Args:
|
||||
request (Request): FastAPI Request object
|
||||
role (str): The role of the user
|
||||
expiration_seconds (int | None): Token expiration in seconds. Defaults to
|
||||
expiration (int | None): Token expiration in seconds. Defaults to
|
||||
the INVITE_TOKEN_EXPIRY_SECONDS environment variable.
|
||||
|
||||
Returns:
|
||||
@@ -140,8 +140,8 @@ def create_invite_link(
|
||||
detail=msg,
|
||||
)
|
||||
|
||||
if expiration_seconds is not None and expiration_seconds <= 0:
|
||||
msg = "expiration_seconds must be a positive integer"
|
||||
if expiration is not None and expiration <= 0:
|
||||
msg = "expiration must be a positive integer"
|
||||
log.error(msg)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
@@ -149,7 +149,7 @@ def create_invite_link(
|
||||
)
|
||||
|
||||
token = auth_handler.generate_invite_link_token(
|
||||
request.user, role=role, expiration_seconds=expiration_seconds
|
||||
request.user, role=role, expiration=expiration
|
||||
)
|
||||
return InviteLinkSchema.model_validate({"token": token})
|
||||
|
||||
|
||||
@@ -170,19 +170,21 @@ class AuthHandler:
|
||||
await RedisSessionMiddleware.clear_user_sessions(user.username)
|
||||
|
||||
def generate_invite_link_token(
|
||||
self, user: Any, role: str, expiration_seconds: int | None = None
|
||||
self, user: Any, role: str, expiration: int | None = None
|
||||
) -> str:
|
||||
"""
|
||||
Generate an invite link token for the user.
|
||||
Args:
|
||||
user (Any): The user object.
|
||||
role (str): The role of the user.
|
||||
expiration_seconds (int | None): Token expiration in seconds. Defaults to
|
||||
expiration (int | None): Token expiration in seconds. Defaults to
|
||||
the INVITE_TOKEN_EXPIRY_SECONDS environment variable.
|
||||
Returns:
|
||||
str: The generated invite link token.
|
||||
"""
|
||||
expires_in = expiration_seconds if expiration_seconds is not None else INVITE_TOKEN_EXPIRY_SECONDS
|
||||
expires_in = (
|
||||
expiration if expiration is not None else INVITE_TOKEN_EXPIRY_SECONDS
|
||||
)
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
jti = str(uuid.uuid4())
|
||||
|
||||
@@ -31,7 +31,7 @@ function createInviteLink() {
|
||||
userApi
|
||||
.createInviteLink({
|
||||
role: selectedRole.value,
|
||||
expirationSeconds: selectedExpiration.value,
|
||||
expiration: selectedExpiration.value,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
|
||||
@@ -26,14 +26,14 @@ async function createUser({
|
||||
|
||||
async function createInviteLink({
|
||||
role,
|
||||
expirationSeconds,
|
||||
expiration,
|
||||
}: {
|
||||
role: string;
|
||||
expirationSeconds?: number;
|
||||
expiration?: number;
|
||||
}) {
|
||||
const params: Record<string, string | number> = { role };
|
||||
if (expirationSeconds !== undefined) {
|
||||
params.expiration_seconds = expirationSeconds;
|
||||
if (expiration !== undefined) {
|
||||
params.expiration = expiration;
|
||||
}
|
||||
return api.post<InviteLinkSchema>("/users/invite-link", {}, { params });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user