refac
This commit is contained in:
@@ -84,14 +84,18 @@ async def get_models(
|
|||||||
if direction:
|
if direction:
|
||||||
filter["direction"] = direction
|
filter["direction"] = direction
|
||||||
|
|
||||||
|
# Pre-fetch user group IDs once - used for both filter and write_access check
|
||||||
|
groups = Groups.get_groups_by_member_id(user.id, db=db)
|
||||||
|
user_group_ids = {group.id for group in groups}
|
||||||
|
|
||||||
if not user.role == "admin" or not BYPASS_ADMIN_ACCESS_CONTROL:
|
if not user.role == "admin" or not BYPASS_ADMIN_ACCESS_CONTROL:
|
||||||
groups = Groups.get_groups_by_member_id(user.id, db=db)
|
|
||||||
if groups:
|
if groups:
|
||||||
filter["group_ids"] = [group.id for group in groups]
|
filter["group_ids"] = [group.id for group in groups]
|
||||||
|
|
||||||
filter["user_id"] = user.id
|
filter["user_id"] = user.id
|
||||||
|
|
||||||
result = Models.search_models(user.id, filter=filter, skip=skip, limit=limit, db=db)
|
result = Models.search_models(user.id, filter=filter, skip=skip, limit=limit, db=db)
|
||||||
|
|
||||||
return ModelAccessListResponse(
|
return ModelAccessListResponse(
|
||||||
items=[
|
items=[
|
||||||
ModelAccessResponse(
|
ModelAccessResponse(
|
||||||
@@ -104,6 +108,7 @@ async def get_models(
|
|||||||
resource_type="model",
|
resource_type="model",
|
||||||
resource_id=model.id,
|
resource_id=model.id,
|
||||||
permission="write",
|
permission="write",
|
||||||
|
user_group_ids=user_group_ids,
|
||||||
db=db,
|
db=db,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -100,8 +100,11 @@ async def get_prompt_list(
|
|||||||
if direction:
|
if direction:
|
||||||
filter["direction"] = direction
|
filter["direction"] = direction
|
||||||
|
|
||||||
|
# Pre-fetch user group IDs once - used for both filter and write_access check
|
||||||
|
groups = Groups.get_groups_by_member_id(user.id, db=db)
|
||||||
|
user_group_ids = {group.id for group in groups}
|
||||||
|
|
||||||
if not (user.role == "admin" and BYPASS_ADMIN_ACCESS_CONTROL):
|
if not (user.role == "admin" and BYPASS_ADMIN_ACCESS_CONTROL):
|
||||||
groups = Groups.get_groups_by_member_id(user.id, db=db)
|
|
||||||
if groups:
|
if groups:
|
||||||
filter["group_ids"] = [group.id for group in groups]
|
filter["group_ids"] = [group.id for group in groups]
|
||||||
|
|
||||||
@@ -123,6 +126,7 @@ async def get_prompt_list(
|
|||||||
resource_type="prompt",
|
resource_type="prompt",
|
||||||
resource_id=prompt.id,
|
resource_id=prompt.id,
|
||||||
permission="write",
|
permission="write",
|
||||||
|
user_group_ids=user_group_ids,
|
||||||
db=db,
|
db=db,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user