|
17 | 17 | from agents.preprocess_manager import preprocess_manager |
18 | 18 | from services.agent_version_service import publish_version_impl |
19 | 19 | from consts.const import MEMORY_SEARCH_START_MSG, MEMORY_SEARCH_DONE_MSG, MEMORY_SEARCH_FAIL_MSG, TOOL_TYPE_MAPPING, \ |
20 | | - LANGUAGE, MESSAGE_ROLE, MODEL_CONFIG_MAPPING, CAN_EDIT_ALL_USER_ROLES, PERMISSION_EDIT, PERMISSION_READ |
| 20 | + LANGUAGE, MESSAGE_ROLE, MODEL_CONFIG_MAPPING, CAN_EDIT_ALL_USER_ROLES, PERMISSION_EDIT, PERMISSION_READ, PERMISSION_PRIVATE |
21 | 21 | from consts.exceptions import MemoryPreparationException |
22 | 22 | from consts.model import ( |
23 | 23 | AgentInfoRequest, |
@@ -823,7 +823,8 @@ async def update_agent_info_impl(request: AgentInfoRequest, authorization: str = |
823 | 823 | "constraint_prompt": request.constraint_prompt, |
824 | 824 | "few_shots_prompt": request.few_shots_prompt, |
825 | 825 | "enabled": request.enabled if request.enabled is not None else True, |
826 | | - "group_ids": convert_list_to_string(request.group_ids) if request.group_ids else user_group_ids |
| 826 | + "group_ids": convert_list_to_string(request.group_ids) if request.group_ids else user_group_ids, |
| 827 | + "ingroup_permission": request.ingroup_permission |
827 | 828 | }, tenant_id=tenant_id, user_id=user_id) |
828 | 829 | agent_id = created["agent_id"] |
829 | 830 | else: |
@@ -1325,7 +1326,10 @@ async def list_all_agent_info_impl(tenant_id: str, user_id: str) -> list[dict]: |
1325 | 1326 | # Apply visibility filter for DEV/USER based on group overlap |
1326 | 1327 | if not can_edit_all: |
1327 | 1328 | agent_group_ids = set(convert_string_to_list(agent.get("group_ids"))) |
1328 | | - if len(user_group_ids.intersection(agent_group_ids)) == 0 and user_id != agent.get("created_by"): |
| 1329 | + ingroup_permission = agent.get("ingroup_permission") |
| 1330 | + is_creator = str(agent.get("created_by")) == str(user_id) |
| 1331 | + # Hide agent if: no group overlap OR (ingroup_permission is PRIVATE AND user is not creator) |
| 1332 | + if len(user_group_ids.intersection(agent_group_ids)) == 0 or (ingroup_permission == PERMISSION_PRIVATE and not is_creator): |
1329 | 1333 | continue |
1330 | 1334 |
|
1331 | 1335 | # Use shared availability check function |
@@ -1358,7 +1362,14 @@ async def list_all_agent_info_impl(tenant_id: str, user_id: str) -> list[dict]: |
1358 | 1362 | model_cache[model_id] = get_model_by_model_id(model_id, tenant_id) |
1359 | 1363 | model_info = model_cache.get(model_id) |
1360 | 1364 |
|
1361 | | - permission = PERMISSION_EDIT if can_edit_all or str(agent.get("created_by")) == str(user_id) else PERMISSION_READ |
| 1365 | + # Permission logic: |
| 1366 | + # - If creator or can_edit_all: PERMISSION_EDIT |
| 1367 | + # - Otherwise: use ingroup_permission, default to PERMISSION_READ if None |
| 1368 | + if can_edit_all or str(agent.get("created_by")) == str(user_id): |
| 1369 | + permission = PERMISSION_EDIT |
| 1370 | + else: |
| 1371 | + ingroup_permission = agent.get("ingroup_permission") |
| 1372 | + permission = ingroup_permission if ingroup_permission is not None else PERMISSION_READ |
1362 | 1373 |
|
1363 | 1374 | simple_agent_list.append({ |
1364 | 1375 | "agent_id": agent["agent_id"], |
|
0 commit comments