enh: arena model access control

This commit is contained in:
Timothy Jaeryang Baek 2024-11-18 07:18:47 -08:00
parent 1ab47a1ff9
commit 269151cd2c
2 changed files with 25 additions and 1 deletions

View File

@ -1114,6 +1114,17 @@ async def get_models(user=Depends(get_verified_user)):
if user.role == "user":
filtered_models = []
for model in models:
if model.get("arena"):
if has_access(
user.id,
type="read",
access_control=model.get("info", {})
.get("meta", {})
.get("access_control", {}),
):
filtered_models.append(model)
continue
model_info = Models.get_model_by_id(model["id"])
if model_info:
if user.id == model_info.user_id or has_access(

View File

@ -9,6 +9,7 @@
import Minus from '$lib/components/icons/Minus.svelte';
import PencilSolid from '$lib/components/icons/PencilSolid.svelte';
import { toast } from 'svelte-sonner';
import AccessControl from '$lib/components/workspace/common/AccessControl.svelte';
export let show = false;
export let edit = false;
@ -39,6 +40,8 @@
let modelIds = [];
let filterMode = 'include';
let accessControl = {};
let imageInputElement;
let loading = false;
@ -74,7 +77,8 @@
profile_image_url: profileImageUrl,
description: description || null,
model_ids: modelIds.length > 0 ? modelIds : null,
filter_mode: modelIds.length > 0 ? (filterMode ? filterMode : null) : null
filter_mode: modelIds.length > 0 ? (filterMode ? filterMode : null) : null,
access_control: accessControl
}
};
@ -98,6 +102,7 @@
description = model.meta.description;
modelIds = model.meta.model_ids || [];
filterMode = model.meta?.filter_mode ?? 'include';
accessControl = model.meta?.access_control ?? {};
}
};
@ -283,6 +288,14 @@
<hr class=" border-gray-100 dark:border-gray-700/10 my-2.5 w-full" />
<div class="my-2 -mx-2">
<div class="px-3 py-2 bg-gray-50 dark:bg-gray-950 rounded-lg">
<AccessControl bind:accessControl />
</div>
</div>
<hr class=" border-gray-100 dark:border-gray-700/10 my-2.5 w-full" />
<div class="flex flex-col w-full">
<div class="mb-1 flex justify-between">
<div class="text-xs text-gray-500">{$i18n.t('Models')}</div>