Skip to content

Commit f5ee7b5

Browse files
authored
feat: user resource permission (#3424)
1 parent 74b76d9 commit f5ee7b5

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

apps/common/constants/permission_constants.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class WorkspaceGroup(Enum):
104104
MODEL = "MODEL"
105105
TOOL = "TOOL"
106106
OTHER = "OTHER"
107+
RESOURCE_PERMISSION = "RESOURCE_PERMISSION"
107108

108109

109110
class UserGroup(Enum):
@@ -340,6 +341,10 @@ def get_workspace_role(self):
340341
Group.WORKSPACE_CHAT_USER.value: _("Chat User"),
341342
Group.WORKSPACE_WORKSPACE.value: _("Workspace"),
342343
Group.WORKSPACE_ROLE.value: _("Role"),
344+
Group.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION.value: _("Application"),
345+
Group.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION.value: _("Knowledge"),
346+
Group.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION.value: _("Model"),
347+
Group.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION.value: _("Tool"),
343348
}
344349

345350

@@ -596,35 +601,44 @@ class PermissionConstants(Enum):
596601
)
597602
APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION_READ = Permission(
598603
group=Group.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION, operate=Operate.READ,
599-
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE]
604+
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
605+
parent_group=[SystemGroup.RESOURCE_PERMISSION, WorkspaceGroup.RESOURCE_PERMISSION]
600606
)
601607
APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION_EDIT = Permission(
602608
group=Group.APPLICATION_WORKSPACE_USER_RESOURCE_PERMISSION, operate=Operate.EDIT,
603-
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE]
609+
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
610+
parent_group=[SystemGroup.RESOURCE_PERMISSION, WorkspaceGroup.RESOURCE_PERMISSION]
604611
)
605612
KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION_READ = Permission(
606613
group=Group.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION, operate=Operate.READ,
607-
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE]
614+
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
615+
parent_group=[SystemGroup.RESOURCE_PERMISSION, WorkspaceGroup.RESOURCE_PERMISSION]
608616
)
609617
KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION_EDIT = Permission(
610618
group=Group.KNOWLEDGE_WORKSPACE_USER_RESOURCE_PERMISSION, operate=Operate.EDIT,
611-
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE]
619+
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
620+
parent_group=[SystemGroup.RESOURCE_PERMISSION, WorkspaceGroup.RESOURCE_PERMISSION]
612621
)
613622
TOOL_WORKSPACE_USER_RESOURCE_PERMISSION_READ = Permission(
614623
group=Group.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION, operate=Operate.READ,
615-
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE]
624+
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
625+
parent_group=[SystemGroup.RESOURCE_PERMISSION, WorkspaceGroup.RESOURCE_PERMISSION]
616626
)
617627
TOOL_WORKSPACE_USER_RESOURCE_PERMISSION_EDIT = Permission(
618628
group=Group.TOOL_WORKSPACE_USER_RESOURCE_PERMISSION, operate=Operate.EDIT,
619-
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE]
629+
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
630+
parent_group=[SystemGroup.RESOURCE_PERMISSION, WorkspaceGroup.RESOURCE_PERMISSION]
631+
620632
)
621633
MODEL_WORKSPACE_USER_RESOURCE_PERMISSION_READ = Permission(
622634
group=Group.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION, operate=Operate.READ,
623-
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE]
635+
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
636+
parent_group=[SystemGroup.RESOURCE_PERMISSION, WorkspaceGroup.RESOURCE_PERMISSION]
624637
)
625638
MODEL_WORKSPACE_USER_RESOURCE_PERMISSION_EDIT = Permission(
626639
group=Group.MODEL_WORKSPACE_USER_RESOURCE_PERMISSION, operate=Operate.EDIT,
627-
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE]
640+
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
641+
parent_group=[SystemGroup.RESOURCE_PERMISSION, WorkspaceGroup.RESOURCE_PERMISSION]
628642
)
629643

630644
EMAIL_SETTING_READ = Permission(
@@ -1268,6 +1282,16 @@ def get_workspace_knowledge_permission(self):
12681282
resource_path=
12691283
f"/WORKSPACE/{kwargs.get('workspace_id')}/KNOWLEDGE/{kwargs.get('knowledge_id')}")
12701284

1285+
def get_workspace_model_permission(self):
1286+
return lambda r, kwargs: Permission(group=self.value.group, operate=self.value.operate,
1287+
resource_path=
1288+
f"/WORKSPACE/{kwargs.get('workspace_id')}/MODEL/{kwargs.get('knowledge_id')}")
1289+
1290+
def get_workspace_tool_permission(self):
1291+
return lambda r, kwargs: Permission(group=self.value.group, operate=self.value.operate,
1292+
resource_path=
1293+
f"/WORKSPACE/{kwargs.get('workspace_id')}/TOOL/{kwargs.get('knowledge_id')}")
1294+
12711295
def get_workspace_permission(self):
12721296
return lambda r, kwargs: Permission(group=self.value.group, operate=self.value.operate,
12731297
resource_path=

0 commit comments

Comments
 (0)