mirror of
https://github.com/StanGirard/quivr.git
synced 2024-09-11 21:17:36 +03:00
fix: delete brain on users click in brains management (#1638)
# Description Fix subscription routes on get users Revert changes deleting the function to get user email from its id in SQL https://www.loom.com/share/46534965a83f4296898495ac370b3451?sid=7f582838-32f6-4812-960e-c80d71517a6d
This commit is contained in:
parent
fb4cfdcf9c
commit
18946ad329
@ -1,4 +1,5 @@
|
||||
from .get_user_identity import get_user_identity
|
||||
from .create_user_identity import create_user_identity
|
||||
from .update_user_properties import update_user_properties, UserUpdatableProperties
|
||||
from .get_user_id_by_user_email import get_user_id_by_user_email
|
||||
from .get_user_id_by_user_email import get_user_id_by_user_email
|
||||
from .get_user_email_by_user_id import get_user_email_by_user_id
|
11
backend/modules/user/repository/get_user_email_by_user_id.py
Normal file
11
backend/modules/user/repository/get_user_email_by_user_id.py
Normal file
@ -0,0 +1,11 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models import get_supabase_client
|
||||
|
||||
|
||||
def get_user_email_by_user_id(user_id: UUID) -> str:
|
||||
supabase_client = get_supabase_client()
|
||||
response = supabase_client.rpc(
|
||||
"get_user_email_by_user_id", {"user_id": str(user_id)}
|
||||
).execute()
|
||||
return response.data[0]["email"]
|
@ -3,7 +3,8 @@ from uuid import UUID
|
||||
|
||||
from models import get_supabase_client
|
||||
from modules.user.entity.user_identity import UserIdentity
|
||||
from modules.user.repository import create_user_identity
|
||||
|
||||
from .create_user_identity import create_user_identity
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
from .get_user_id_by_email import get_user_id_by_email
|
||||
from .get_user_id_by_email import get_user_id_by_email
|
||||
from modules.user.repository import get_user_email_by_user_id
|
||||
|
@ -5,6 +5,7 @@ from fastapi import APIRouter, Depends, HTTPException
|
||||
from middlewares.auth.auth_bearer import AuthBearer, get_current_user
|
||||
from models import BrainSubscription, PromptStatusEnum
|
||||
from modules.user.entity.user_identity import UserIdentity
|
||||
from modules.user.service import get_user_email_by_user_id
|
||||
from modules.user.service.get_user_id_by_email import get_user_id_by_email
|
||||
from pydantic import BaseModel
|
||||
from repository.api_brain_definition.get_api_brain_definition import (
|
||||
@ -103,6 +104,29 @@ def invite_users_to_brain(
|
||||
Depends(has_brain_authorization([RoleEnum.Owner, RoleEnum.Editor])),
|
||||
],
|
||||
)
|
||||
def get_users_with_brain_access(
|
||||
brain_id: UUID,
|
||||
):
|
||||
"""
|
||||
Get all users for a brain
|
||||
"""
|
||||
|
||||
brain_users = get_brain_users(
|
||||
brain_id=brain_id,
|
||||
)
|
||||
|
||||
brain_access_list = []
|
||||
|
||||
for brain_user in brain_users:
|
||||
brain_access = {}
|
||||
# TODO: find a way to fetch user email concurrently
|
||||
brain_access["email"] = get_user_email_by_user_id(brain_user.user_id)
|
||||
brain_access["rights"] = brain_user.rights
|
||||
brain_access_list.append(brain_access)
|
||||
|
||||
return brain_access_list
|
||||
|
||||
|
||||
@subscription_router.delete(
|
||||
"/brains/{brain_id}/subscription",
|
||||
)
|
||||
|
@ -37,7 +37,7 @@
|
||||
"back_to_chat": "Back to chat",
|
||||
"onboarding": {
|
||||
"title": "Hi 👋🏻 Want to discover Quivr ? 😇",
|
||||
"step_1_1": "1. Drap and drop file on the chat or in the 📎.",
|
||||
"step_1_1": "1. Drag and drop file on the chat or in the 📎.",
|
||||
"step_1_2": "Don't have a file ? Download 'Quivr documentation'",
|
||||
"step_2": "2. Start chatting with your file",
|
||||
"step_3": "3. Enjoy !",
|
||||
@ -51,4 +51,4 @@
|
||||
}
|
||||
},
|
||||
"welcome": "Welcome"
|
||||
}
|
||||
}
|
||||
|
17
scripts/20231116102600_add_get_user_email_by_user_id.sql
Normal file
17
scripts/20231116102600_add_get_user_email_by_user_id.sql
Normal file
@ -0,0 +1,17 @@
|
||||
CREATE OR REPLACE FUNCTION public.get_user_email_by_user_id(user_id uuid)
|
||||
RETURNS TABLE (email text)
|
||||
SECURITY definer
|
||||
AS $$
|
||||
BEGIN
|
||||
RETURN QUERY SELECT au.email::text FROM auth.users au WHERE au.id = user_id;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Update migrations table
|
||||
INSERT INTO migrations (name)
|
||||
SELECT '20231116102600_add_get_user_email_by_user_id'
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM migrations WHERE name = '20231116102600_add_get_user_email_by_user_id'
|
||||
);
|
||||
|
||||
COMMIT;
|
@ -220,6 +220,14 @@ CREATE TABLE IF NOT EXISTS api_brain_definition (
|
||||
secrets JSON
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.get_user_email_by_user_id(user_id uuid)
|
||||
RETURNS TABLE (email text)
|
||||
SECURITY definer
|
||||
AS $$
|
||||
BEGIN
|
||||
RETURN QUERY SELECT au.email::text FROM auth.users au WHERE au.id = user_id;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.get_user_id_by_user_email(user_email text)
|
||||
RETURNS TABLE (user_id uuid)
|
||||
@ -436,7 +444,7 @@ $$;
|
||||
|
||||
|
||||
INSERT INTO migrations (name)
|
||||
SELECT '20231114162700_drop_get_user_email_by_user_id'
|
||||
SELECT '20231116102600_add_get_user_email_by_user_id'
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM migrations WHERE name = '20231114162700_drop_get_user_email_by_user_id'
|
||||
SELECT 1 FROM migrations WHERE name = '20231116102600_add_get_user_email_by_user_id'
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user