backend: add 'allow_dupe_invites' option to allow re-inviting users. if not set (default), duplicate invites will result in errors (#471)
This commit is contained in:
parent
4dbca8c421
commit
827b643262
@ -4,6 +4,7 @@ from datetime import datetime
|
||||
from enum import IntEnum
|
||||
from typing import Optional
|
||||
import uuid
|
||||
import os
|
||||
|
||||
from pydantic import BaseModel, UUID4
|
||||
from fastapi import HTTPException
|
||||
@ -62,6 +63,7 @@ class InviteOps:
|
||||
self.invites = mdb["invites"]
|
||||
self.archives = mdb["archives"]
|
||||
self.email = email
|
||||
self.allow_dupe_invites = os.environ.get("ALLOW_DUPE_INVITES", "0") == "1"
|
||||
|
||||
async def add_new_user_invite(
|
||||
self,
|
||||
@ -71,8 +73,10 @@ class InviteOps:
|
||||
):
|
||||
"""Add invite for new user"""
|
||||
|
||||
res = await self.invites.find_one({"email": new_user_invite.email})
|
||||
if res:
|
||||
res = await self.invites.find_one(
|
||||
{"email": new_user_invite.email, "aid": new_user_invite.aid}
|
||||
)
|
||||
if res and not self.allow_dupe_invites:
|
||||
raise HTTPException(
|
||||
status_code=403, detail="This user has already been invited"
|
||||
)
|
||||
@ -82,6 +86,9 @@ class InviteOps:
|
||||
if not new_user_invite.role:
|
||||
new_user_invite.role = UserRole.OWNER
|
||||
|
||||
if res:
|
||||
await self.invites.delete_one({"_id": res["_id"]})
|
||||
|
||||
await self.invites.insert_one(new_user_invite.to_dict())
|
||||
|
||||
self.email.send_new_user_invite(
|
||||
|
||||
@ -45,6 +45,8 @@ data:
|
||||
|
||||
REGISTRATION_ENABLED: "{{ .Values.registration_enabled | default 0 }}"
|
||||
|
||||
ALLOW_DUPE_INVITES: "{{ .Values.allow_dupe_invites | default 0 }}"
|
||||
|
||||
JWT_TOKEN_LIFETIME_MINUTES: "{{ .Values.jwt_token_lifetime_minutes | default 60 }}"
|
||||
|
||||
WEB_CONCURRENCY: "{{ .Values.backend_workers | default 4 }}"
|
||||
|
||||
@ -15,6 +15,9 @@ volume_storage_class:
|
||||
registration_enabled: "0"
|
||||
jwt_token_lifetime_minutes: 1440
|
||||
|
||||
# if set to "1", allow inviting same user to same org multiple times
|
||||
allow_dupe_invites: "0"
|
||||
|
||||
# number of workers for backend api
|
||||
backend_workers: 4
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user