fix: deleted user handling

This commit is contained in:
Timothy Jaeryang Baek 2024-11-19 16:47:35 -08:00
parent 011b8ea3a8
commit 0c43c1edf6
54 changed files with 114 additions and 42 deletions

View File

@ -128,17 +128,20 @@ class KnowledgeTable:
def get_knowledge_bases(self) -> list[KnowledgeUserModel]:
with get_db() as db:
return [
KnowledgeUserModel.model_validate(
{
**KnowledgeModel.model_validate(knowledge).model_dump(),
"user": Users.get_user_by_id(knowledge.user_id).model_dump(),
}
knowledge_bases = []
for knowledge in (
db.query(Knowledge).order_by(Knowledge.updated_at.desc()).all()
):
user = Users.get_user_by_id(knowledge.user_id)
knowledge_bases.append(
KnowledgeUserModel.model_validate(
{
**KnowledgeModel.model_validate(knowledge).model_dump(),
"user": user.model_dump() if user else None,
}
)
)
for knowledge in db.query(Knowledge)
.order_by(Knowledge.updated_at.desc())
.all()
]
return knowledge_bases
def get_knowledge_bases_by_user_id(
self, user_id: str, permission: str = "write"

View File

@ -175,15 +175,18 @@ class ModelsTable:
def get_models(self) -> list[ModelUserResponse]:
with get_db() as db:
return [
ModelUserResponse.model_validate(
{
**ModelModel.model_validate(model).model_dump(),
"user": Users.get_user_by_id(model.user_id).model_dump(),
}
models = []
for model in db.query(Model).filter(Model.base_model_id != None).all():
user = Users.get_user_by_id(model.user_id)
models.append(
ModelUserResponse.model_validate(
{
**ModelModel.model_validate(model).model_dump(),
"user": user.model_dump() if user else None,
}
)
)
for model in db.query(Model).filter(Model.base_model_id != None).all()
]
return models
def get_base_models(self) -> list[ModelModel]:
with get_db() as db:

View File

@ -103,15 +103,20 @@ class PromptsTable:
def get_prompts(self) -> list[PromptUserResponse]:
with get_db() as db:
return [
PromptUserResponse.model_validate(
{
**PromptModel.model_validate(prompt).model_dump(),
"user": Users.get_user_by_id(prompt.user_id).model_dump(),
}
prompts = []
for prompt in db.query(Prompt).order_by(Prompt.timestamp.desc()).all():
user = Users.get_user_by_id(prompt.user_id)
prompts.append(
PromptUserResponse.model_validate(
{
**PromptModel.model_validate(prompt).model_dump(),
"user": user.model_dump() if user else None,
}
)
)
for prompt in db.query(Prompt).all()
]
return prompts
def get_prompts_by_user_id(
self, user_id: str, permission: str = "write"

View File

@ -140,15 +140,18 @@ class ToolsTable:
def get_tools(self) -> list[ToolUserResponse]:
with get_db() as db:
return [
ToolUserResponse.model_validate(
{
**ToolModel.model_validate(tool).model_dump(),
"user": Users.get_user_by_id(tool.user_id).model_dump(),
}
tools = []
for tool in db.query(Tool).order_by(Tool.updated_at.desc()).all():
user = Users.get_user_by_id(tool.user_id)
tools.append(
ToolUserResponse.model_validate(
{
**ToolModel.model_validate(tool).model_dump(),
"user": user.model_dump() if user else None,
}
)
)
for tool in db.query(Tool).order_by(Tool.updated_at.desc()).all()
]
return tools
def get_tools_by_user_id(
self, user_id: str, permission: str = "write"

View File

@ -165,12 +165,14 @@
<div class="mt-3 flex justify-between">
<div class="text-xs text-gray-500">
<Tooltip
content={item?.user?.email}
content={item?.user?.email ?? $i18n.t('Deleted User')}
className="flex shrink-0"
placement="top-start"
>
{$i18n.t('By {{name}}', {
name: capitalizeFirstLetter(item?.user?.name ?? item?.user?.email)
name: capitalizeFirstLetter(
item?.user?.name ?? item?.user?.email ?? $i18n.t('Deleted User')
)
})}
</Tooltip>
</div>

View File

@ -279,10 +279,16 @@
<div class="flex justify-between items-center -mb-0.5 px-0.5">
<div class=" text-xs mt-0.5">
<Tooltip content={model?.user?.email} className="flex shrink-0" placement="top-start">
<Tooltip
content={model?.user?.email ?? $i18n.t('Deleted User')}
className="flex shrink-0"
placement="top-start"
>
<div class="shrink-0 text-gray-500">
{$i18n.t('By {{name}}', {
name: capitalizeFirstLetter(model?.user?.name ?? model?.user?.email)
name: capitalizeFirstLetter(
model?.user?.name ?? model?.user?.email ?? $i18n.t('Deleted User')
)
})}
</div>
</Tooltip>

View File

@ -155,13 +155,15 @@
<div class=" text-xs px-0.5">
<Tooltip
content={prompt?.user?.email}
content={prompt?.user?.email ?? $i18n.t('Deleted User')}
className="flex shrink-0"
placement="top-start"
>
<div class="shrink-0 text-gray-500">
{$i18n.t('By {{name}}', {
name: capitalizeFirstLetter(prompt?.user?.name ?? prompt?.user?.email)
name: capitalizeFirstLetter(
prompt?.user?.name ?? prompt?.user?.email ?? $i18n.t('Deleted User')
)
})}
</div>
</Tooltip>

View File

@ -251,12 +251,14 @@
<div class="text-xs text-gray-500 shrink-0">
<Tooltip
content={tool?.user?.email}
content={tool?.user?.email ?? $i18n.t('Deleted User')}
className="flex shrink-0"
placement="top-start"
>
{$i18n.t('By {{name}}', {
name: capitalizeFirstLetter(tool?.user?.name ?? tool?.user?.email)
name: capitalizeFirstLetter(
tool?.user?.name ?? tool?.user?.email ?? $i18n.t('Deleted User')
)
})}
</Tooltip>
</div>

View File

@ -234,6 +234,7 @@
"Delete User": "حذف المستخدم",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} حذف",
"Deleted {{name}}": "حذف {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "وصف",
"Didn't fully follow instructions": "لم أتبع التعليمات بشكل كامل",

View File

@ -234,6 +234,7 @@
"Delete User": "Изтриване на потребител",
"Deleted {{deleteModelTag}}": "Изтрито {{deleteModelTag}}",
"Deleted {{name}}": "Изтрито {{име}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Описание",
"Didn't fully follow instructions": "Не следва инструкциите",

View File

@ -234,6 +234,7 @@
"Delete User": "ইউজার মুছে ফেলুন",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} মুছে ফেলা হয়েছে",
"Deleted {{name}}": "{{name}} মোছা হয়েছে",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "বিবরণ",
"Didn't fully follow instructions": "ইনস্ট্রাকশন সম্পূর্ণ অনুসরণ করা হয়নি",

View File

@ -234,6 +234,7 @@
"Delete User": "Eliminar usuari",
"Deleted {{deleteModelTag}}": "S'ha eliminat {{deleteModelTag}}",
"Deleted {{name}}": "S'ha eliminat {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "Descriu la teva base de coneixement i objectius",
"Description": "Descripció",
"Didn't fully follow instructions": "No s'han seguit les instruccions completament",

View File

@ -234,6 +234,7 @@
"Delete User": "",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} gipapas",
"Deleted {{name}}": "",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Deskripsyon",
"Didn't fully follow instructions": "",

View File

@ -234,6 +234,7 @@
"Delete User": "Smazat uživatele",
"Deleted {{deleteModelTag}}": "Smazáno {{deleteModelTag}}",
"Deleted {{name}}": "Smazáno {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Popis",
"Didn't fully follow instructions": "Nenásledovali jste přesně všechny instrukce.",

View File

@ -234,6 +234,7 @@
"Delete User": "Slet bruger",
"Deleted {{deleteModelTag}}": "Slettede {{deleteModelTag}}",
"Deleted {{name}}": "Slettede {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Beskrivelse",
"Didn't fully follow instructions": "Fulgte ikke instruktioner",

View File

@ -234,6 +234,7 @@
"Delete User": "Benutzer löschen",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} gelöscht",
"Deleted {{name}}": "{{name}} gelöscht",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Beschreibung",
"Didn't fully follow instructions": "Nicht genau den Answeisungen gefolgt",

View File

@ -234,6 +234,7 @@
"Delete User": "",
"Deleted {{deleteModelTag}}": "Deleted {{deleteModelTag}}",
"Deleted {{name}}": "",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Description",
"Didn't fully follow instructions": "",

View File

@ -234,6 +234,7 @@
"Delete User": "",
"Deleted {{deleteModelTag}}": "",
"Deleted {{name}}": "",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "",
"Didn't fully follow instructions": "",

View File

@ -234,6 +234,7 @@
"Delete User": "",
"Deleted {{deleteModelTag}}": "",
"Deleted {{name}}": "",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "",
"Didn't fully follow instructions": "",

View File

@ -234,6 +234,7 @@
"Delete User": "Borrar Usuario",
"Deleted {{deleteModelTag}}": "Se borró {{deleteModelTag}}",
"Deleted {{name}}": "Eliminado {{nombre}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Descripción",
"Didn't fully follow instructions": "No siguió las instrucciones",

View File

@ -234,6 +234,7 @@
"Delete User": "حذف کاربر",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} پاک شد",
"Deleted {{name}}": "حذف شده {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "توضیحات",
"Didn't fully follow instructions": "نمی تواند دستورالعمل را کامل پیگیری کند",

View File

@ -234,6 +234,7 @@
"Delete User": "Poista käyttäjä",
"Deleted {{deleteModelTag}}": "Poistettu {{deleteModelTag}}",
"Deleted {{name}}": "Poistettu {{nimi}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Kuvaus",
"Didn't fully follow instructions": "Ei noudattanut ohjeita täysin",

View File

@ -234,6 +234,7 @@
"Delete User": "Supprimer le compte d'utilisateur",
"Deleted {{deleteModelTag}}": "Supprimé {{deleteModelTag}}",
"Deleted {{name}}": "Supprimé {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Description",
"Didn't fully follow instructions": "N'a pas entièrement respecté les instructions",

View File

@ -234,6 +234,7 @@
"Delete User": "Supprimer le compte d'utilisateur",
"Deleted {{deleteModelTag}}": "Supprimé {{deleteModelTag}}",
"Deleted {{name}}": "Supprimé {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Description",
"Didn't fully follow instructions": "N'a pas entièrement respecté les instructions",

View File

@ -234,6 +234,7 @@
"Delete User": "מחק משתמש",
"Deleted {{deleteModelTag}}": "נמחק {{deleteModelTag}}",
"Deleted {{name}}": "נמחק {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "תיאור",
"Didn't fully follow instructions": "לא עקב אחרי ההוראות באופן מלא",

View File

@ -234,6 +234,7 @@
"Delete User": "उपभोक्ता मिटायें",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} हटा दिया गया",
"Deleted {{name}}": "{{name}} हटा दिया गया",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "विवरण",
"Didn't fully follow instructions": "निर्देशों का पूरी तरह से पालन नहीं किया",

View File

@ -234,6 +234,7 @@
"Delete User": "Izbriši korisnika",
"Deleted {{deleteModelTag}}": "Izbrisan {{deleteModelTag}}",
"Deleted {{name}}": "Izbrisano {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Opis",
"Didn't fully follow instructions": "Nije u potpunosti slijedio upute",

View File

@ -234,6 +234,7 @@
"Delete User": "Felhasználó törlése",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} törölve",
"Deleted {{name}}": "{{name}} törölve",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Leírás",
"Didn't fully follow instructions": "Nem követte teljesen az utasításokat",

View File

@ -234,6 +234,7 @@
"Delete User": "Menghapus Pengguna",
"Deleted {{deleteModelTag}}": "Menghapus {{deleteModelTag}}",
"Deleted {{name}}": "Menghapus {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Deskripsi",
"Didn't fully follow instructions": "Tidak sepenuhnya mengikuti instruksi",

View File

@ -234,6 +234,7 @@
"Delete User": "Scrios Úsáideoir",
"Deleted {{deleteModelTag}}": "Scriosta {{deleteModelTag}}",
"Deleted {{name}}": "Scriosta {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Cur síos",
"Didn't fully follow instructions": "Níor lean sé treoracha go hiomlán",

View File

@ -234,6 +234,7 @@
"Delete User": "Elimina utente",
"Deleted {{deleteModelTag}}": "Eliminato {{deleteModelTag}}",
"Deleted {{name}}": "Eliminato {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Descrizione",
"Didn't fully follow instructions": "Non ha seguito completamente le istruzioni",

View File

@ -234,6 +234,7 @@
"Delete User": "ユーザーを削除",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} を削除しました",
"Deleted {{name}}": "{{name}}を削除しました",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "説明",
"Didn't fully follow instructions": "説明に沿って操作していませんでした",

View File

@ -234,6 +234,7 @@
"Delete User": "მომხმარებლის წაშლა",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} წაშლილია",
"Deleted {{name}}": "Deleted {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "აღწერა",
"Didn't fully follow instructions": "ვერ ყველა ინფორმაციისთვის ვერ ხელახლა ჩაწერე",

View File

@ -234,6 +234,7 @@
"Delete User": "사용자 삭제",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} 삭제됨",
"Deleted {{name}}": "{{name}}을(를) 삭제했습니다.",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "설명",
"Didn't fully follow instructions": "완전히 지침을 따르지 않음",

View File

@ -234,6 +234,7 @@
"Delete User": "Ištrinti naudotoją",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} ištrinta",
"Deleted {{name}}": "Ištrinta {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Aprašymas",
"Didn't fully follow instructions": "Pilnai nesekė instrukcijų",

View File

@ -234,6 +234,7 @@
"Delete User": "Padam Pengguna",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} dipadam",
"Deleted {{name}}": "{{name}} dipadam",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Penerangan",
"Didn't fully follow instructions": "Tidak mengikut arahan sepenuhnya",

View File

@ -234,6 +234,7 @@
"Delete User": "Slett bruker",
"Deleted {{deleteModelTag}}": "Slettet {{deleteModelTag}}",
"Deleted {{name}}": "Slettet {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "Beskriv kunnskapsbasen din og målene dine",
"Description": "Beskrivelse",
"Didn't fully follow instructions": "Fulgte ikke instruksjonene fullstendig",

View File

@ -234,6 +234,7 @@
"Delete User": "Verwijder Gebruiker",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} is verwijderd",
"Deleted {{name}}": "{{name}} verwijderd",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Beschrijving",
"Didn't fully follow instructions": "Heeft niet alle instructies gevolgt",

View File

@ -234,6 +234,7 @@
"Delete User": "ਉਪਭੋਗਤਾ ਮਿਟਾਓ",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} ਮਿਟਾਇਆ ਗਿਆ",
"Deleted {{name}}": "ਮਿਟਾ ਦਿੱਤਾ ਗਿਆ {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "ਵਰਣਨਾ",
"Didn't fully follow instructions": "ਹਦਾਇਤਾਂ ਨੂੰ ਪੂਰੀ ਤਰ੍ਹਾਂ ਫਾਲੋ ਨਹੀਂ ਕੀਤਾ",

View File

@ -234,6 +234,7 @@
"Delete User": "Usuń użytkownika",
"Deleted {{deleteModelTag}}": "Usunięto {{deleteModelTag}}",
"Deleted {{name}}": "Usunięto {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Opis",
"Didn't fully follow instructions": "Nie postępował zgodnie z instrukcjami",

View File

@ -234,6 +234,7 @@
"Delete User": "Deletar Usuário",
"Deleted {{deleteModelTag}}": "Deletado {{deleteModelTag}}",
"Deleted {{name}}": "Deletado {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "Descreva sua base de conhecimento e objetivos",
"Description": "Descrição",
"Didn't fully follow instructions": "Não seguiu completamente as instruções",

View File

@ -234,6 +234,7 @@
"Delete User": "Apagar Utilizador",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} apagado",
"Deleted {{name}}": "Apagado {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Descrição",
"Didn't fully follow instructions": "Não seguiu instruções com precisão",

View File

@ -234,6 +234,7 @@
"Delete User": "Șterge Utilizatorul",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} șters",
"Deleted {{name}}": "{{name}} șters",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Descriere",
"Didn't fully follow instructions": "Nu a urmat complet instrucțiunile",

View File

@ -234,6 +234,7 @@
"Delete User": "Удалить пользователя",
"Deleted {{deleteModelTag}}": "Удалено {{deleteModelTag}}",
"Deleted {{name}}": "Удалено {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Описание",
"Didn't fully follow instructions": "Не полностью следует инструкциям",

View File

@ -234,6 +234,7 @@
"Delete User": "Обриши корисника",
"Deleted {{deleteModelTag}}": "Обрисано {{deleteModelTag}}",
"Deleted {{name}}": "Избрисано {{наме}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Опис",
"Didn't fully follow instructions": "Упутства нису праћена у потпуности",

View File

@ -234,6 +234,7 @@
"Delete User": "Radera användare",
"Deleted {{deleteModelTag}}": "Raderad {{deleteModelTag}}",
"Deleted {{name}}": "Borttagen {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Beskrivning",
"Didn't fully follow instructions": "Följde inte instruktionerna",

View File

@ -234,6 +234,7 @@
"Delete User": "ลบผู้ใช้",
"Deleted {{deleteModelTag}}": "ลบ {{deleteModelTag}}",
"Deleted {{name}}": "ลบ {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "คำอธิบาย",
"Didn't fully follow instructions": "ไม่ได้ปฏิบัติตามคำแนะนำทั้งหมด",

View File

@ -234,6 +234,7 @@
"Delete User": "",
"Deleted {{deleteModelTag}}": "",
"Deleted {{name}}": "",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "",
"Didn't fully follow instructions": "",

View File

@ -234,6 +234,7 @@
"Delete User": "Kullanıcıyı Sil",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} silindi",
"Deleted {{name}}": "{{name}} silindi",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Açıklama",
"Didn't fully follow instructions": "Talimatları tam olarak takip etmedi",

View File

@ -234,6 +234,7 @@
"Delete User": "Видалити користувача",
"Deleted {{deleteModelTag}}": "Видалено {{deleteModelTag}}",
"Deleted {{name}}": "Видалено {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "Опишіть вашу базу знань та цілі",
"Description": "Опис",
"Didn't fully follow instructions": "Не повністю дотримувалися інструкцій",

View File

@ -234,6 +234,7 @@
"Delete User": "صارف کو حذف کریں",
"Deleted {{deleteModelTag}}": "{{deleteModelTag}} حذف کر دیا گیا",
"Deleted {{name}}": "حذف کر دیا گیا {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "تفصیل",
"Didn't fully follow instructions": "ہدایات کو مکمل طور پر نہیں سمجھا",

View File

@ -234,6 +234,7 @@
"Delete User": "Xóa người dùng",
"Deleted {{deleteModelTag}}": "Đã xóa {{deleteModelTag}}",
"Deleted {{name}}": "Đã xóa {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "Mô tả",
"Didn't fully follow instructions": "Không tuân theo chỉ dẫn một cách đầy đủ",

View File

@ -234,6 +234,7 @@
"Delete User": "删除用户",
"Deleted {{deleteModelTag}}": "已删除 {{deleteModelTag}}",
"Deleted {{name}}": "已删除 {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "描述您的知识库和目标",
"Description": "描述",
"Didn't fully follow instructions": "没有完全遵照指示",

View File

@ -234,6 +234,7 @@
"Delete User": "刪除使用者",
"Deleted {{deleteModelTag}}": "已刪除 {{deleteModelTag}}",
"Deleted {{name}}": "已刪除 {{name}}",
"Deleted User": "",
"Describe your knowledge base and objectives": "",
"Description": "描述",
"Didn't fully follow instructions": "未完全遵循指示",