Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 98 additions & 10 deletions apps/common/constants/permission_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class Group(Enum):
APPLICATION_FOLDER = "APPLICATION_FOLDER"
KNOWLEDGE_FOLDER = "KNOWLEDGE_FOLDER"
TOOL_FOLDER = "TOOL_FOLDER"
# 身份与权限 Identity & Access Management
IAM = "IAM"



class SystemGroup(Enum):
Expand All @@ -124,6 +127,7 @@ class SystemGroup(Enum):
SYSTEM_SETTING = "SYSTEM_SETTING"
OPERATION_LOG = "OPERATION_LOG"
OTHER = "OTHER"
USER_GROUP = "USER_GROUP"


class WorkspaceGroup(Enum):
Expand All @@ -145,6 +149,24 @@ class UserGroup(Enum):
OTHER = "OTHER"


class TopLevelGroup(Enum):
"""
一级目录(最顶层分类),用于在 parent_group 之上再加一层分类
"""
# 身份与权限
IAM = "IAM"
# 资源管理
RESOURCE = "RESOURCE"
# 共享资源
SHARED = "SHARED"
CHAT_CLIENT = "CHAT_CLIENT"
# 系统设置
SYSTEM_SETTING = "SYSTEM_SETTING"
#操作日志
OPERATION_LOG = "OPERATION_LOG"
OTHER = "OTHER"


class Operate(Enum):
"""
一个权限组的操作权限
Expand Down Expand Up @@ -323,14 +345,14 @@ def get_workspace_role(self):
SystemGroup.USER_MANAGEMENT.value: _("User Management"),
SystemGroup.ROLE.value: _("Role"),
SystemGroup.WORKSPACE.value: _("Workspace"),
SystemGroup.RESOURCE_APPLICATION.value: _("Resource Application"),
SystemGroup.RESOURCE_KNOWLEDGE.value: _("Resource Knowledge"),
SystemGroup.RESOURCE_TOOL.value: _("Resource Tool"),
SystemGroup.RESOURCE_MODEL.value: _("Resource Model"),
SystemGroup.RESOURCE_APPLICATION.value: _("Application"),
SystemGroup.RESOURCE_KNOWLEDGE.value: _("Knowledge"),
SystemGroup.RESOURCE_TOOL.value: _("Tool"),
SystemGroup.RESOURCE_MODEL.value: _("Model"),
SystemGroup.RESOURCE_PERMISSION.value: _("Resource Permission"),
SystemGroup.SHARED_KNOWLEDGE.value: _("Shared Knowledge"),
SystemGroup.SHARED_MODEL.value: _("Shared Model"),
SystemGroup.SHARED_TOOL.value: _("Shared Tool"),
SystemGroup.SHARED_KNOWLEDGE.value: _("Knowledge"),
SystemGroup.SHARED_MODEL.value: _("Model"),
SystemGroup.SHARED_TOOL.value: _("Tool"),
SystemGroup.OPERATION_LOG.value: _("Operation Log"),
SystemGroup.OTHER.value: _("Other"),
WorkspaceGroup.SYSTEM_MANAGEMENT.value: _("System Management"),
Expand Down Expand Up @@ -439,17 +461,57 @@ def get_workspace_role(self):
Group.APPLICATION_FOLDER.value: _("Folder"),
Group.KNOWLEDGE_FOLDER.value: _("Folder"),
Group.TOOL_FOLDER.value: _("Folder"),
# SystemGroup.RESOURCE.value: _("Resource"),
TopLevelGroup.IAM.value: _("IAM"),
TopLevelGroup.RESOURCE.value: _("Resource"),
TopLevelGroup.SHARED.value: _("Shared"),
TopLevelGroup.CHAT_CLIENT.value: _("Chat Client"),
}
GROUPS = {
TopLevelGroup.IAM: (
SystemGroup.USER_MANAGEMENT,
SystemGroup.ROLE,
SystemGroup.WORKSPACE,
SystemGroup.USER_GROUP,
SystemGroup.RESOURCE_PERMISSION,
),
TopLevelGroup.RESOURCE: (
SystemGroup.RESOURCE_APPLICATION,
SystemGroup.RESOURCE_KNOWLEDGE,
SystemGroup.RESOURCE_TOOL,
SystemGroup.RESOURCE_MODEL,
),
TopLevelGroup.SHARED: (
SystemGroup.SHARED_KNOWLEDGE,
SystemGroup.SHARED_MODEL,
SystemGroup.SHARED_TOOL,
),
TopLevelGroup.CHAT_CLIENT: (
SystemGroup.CHAT_USER,
),
TopLevelGroup.SYSTEM_SETTING: (
SystemGroup.SYSTEM_SETTING,
),
TopLevelGroup.OPERATION_LOG: (
SystemGroup.OPERATION_LOG,
),
TopLevelGroup.OTHER: (
SystemGroup.OTHER,
)
}
TOP_LEVEL_GROUP_MAP = {
group: top_level
for top_level, groups in GROUPS.items()
for group in groups
}


class Permission:
"""
权限信息
"""

def __init__(self, group: Group, operate: Operate, resource_path=None, role_list=None,
resource_permission_group_list=None, parent_group=None, label=None, is_ee=True):
resource_permission_group_list=None, parent_group=None, label=None, is_ee=True,
top_group=None):
if role_list is None:
role_list = []
if resource_permission_group_list is None:
Expand All @@ -464,6 +526,7 @@ def __init__(self, group: Group, operate: Operate, resource_path=None, role_list
self.parent_group = parent_group # 新增字段:父级组
self.label = label
self.is_ee = is_ee # 是否是企业版权限
self.top_group = top_group # 一级目录分类

@staticmethod
def new_instance(permission_str: str):
Expand Down Expand Up @@ -521,6 +584,31 @@ class PermissionConstants(Enum):
parent_group=[SystemGroup.USER_MANAGEMENT]
)

SYSTEM_USER_GROUP_READ = Permission(group=Group.USER_GROUP, operate=Operate.READ,
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
parent_group=[SystemGroup.USER_GROUP]
)
SYSTEM_USER_GROUP_CREATE = Permission(group=Group.USER_GROUP, operate=Operate.CREATE,
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
parent_group=[SystemGroup.USER_GROUP]
)
SYSTEM_USER_GROUP_EDIT = Permission(group=Group.USER_GROUP, operate=Operate.EDIT,
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
parent_group=[SystemGroup.USER_GROUP]
)
SYSTEM_USER_GROUP_DELETE = Permission(group=Group.USER_GROUP, operate=Operate.DELETE,
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
parent_group=[SystemGroup.USER_GROUP]
)
SYSTEM_USER_GROUP_ADD_MEMBER = Permission(group=Group.USER_GROUP, operate=Operate.ADD_MEMBER,
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
parent_group=[SystemGroup.USER_GROUP]
)
SYSTEM_USER_GROUP_REMOVE_MEMBER = Permission(group=Group.USER_GROUP, operate=Operate.REMOVE_MEMBER,
role_list=[RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE],
parent_group=[SystemGroup.USER_GROUP]
)

MODEL_READ = Permission(
group=Group.MODEL, operate=Operate.READ, role_list=[RoleConstants.ADMIN, RoleConstants.USER],
parent_group=[WorkspaceGroup.MODEL, UserGroup.MODEL],
Expand Down
32 changes: 31 additions & 1 deletion apps/locales/en_US/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9381,4 +9381,34 @@ msgid "User Name"
msgstr "User Name"

msgid "New chat"
msgstr "A new conversation has been generated. Please ask your question again!"
msgstr "A new conversation has been generated. Please ask your question again!"

msgid "IAM"
msgstr "IAM"

msgid "Chat Client"
msgstr "Chat Client"

msgid "Shared"
msgstr ""

msgid "IAM/User Group"
msgstr ""

msgid "Create or update System User Group"
msgstr ""

msgid "Get System User Group list by workspace id"
msgstr ""

msgid "Delete System User Group"
msgstr ""

msgid "Add members to System User Group"
msgstr ""

msgid "Unauthorized users are present"
msgstr ""

msgid "Remove members from System User Group"
msgstr ""
32 changes: 31 additions & 1 deletion apps/locales/zh_CN/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9504,4 +9504,34 @@ msgid "User Name"
msgstr "用户名称"

msgid "New chat"
msgstr "已生成新对话,请重新提问!"
msgstr "已生成新对话,请重新提问!"

msgid "IAM"
msgstr "身份与权限"

msgid "Chat Client"
msgstr "对话端管理"

msgid "Shared"
msgstr "共享资源"

msgid "IAM/User Group"
msgstr "身份与权限/用户组"

msgid "Create or update System User Group"
msgstr "创建或更新系统用户组"

msgid "Get System User Group list by workspace id"
msgstr "通过工作空间 ID 获取系统用户组列表"

msgid "Delete System User Group"
msgstr "删除系统用户组"

msgid "Add members to System User Group"
msgstr "添加成员到系统用户组"

msgid "Unauthorized users are present"
msgstr "存在未授权的用户"

msgid "Remove members from System User Group"
msgstr "从系统用户组中移除成员"
32 changes: 31 additions & 1 deletion apps/locales/zh_Hant/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9504,4 +9504,34 @@ msgid "User Name"
msgstr "用戶名稱"

msgid "New chat"
msgstr "已生成新對話,請重新提問!"
msgstr "已生成新對話,請重新提問!"

msgid "IAM"
msgstr "身份與權限"

msgid "Chat Client"
msgstr "對話端管理"

msgid "Shared"
msgstr "共享資源"

msgid "IAM/User Group"
msgstr "身份與權限/用戶組"

msgid "Create or update System User Group"
msgstr "創建或更新系統用戶組"

msgid "Get System User Group list by workspace id"
msgstr "通過工作空間 ID 獲取系統用戶組列表"

msgid "Delete System User Group"
msgstr "刪除系統用戶組"

msgid "Add members to System User Group"
msgstr "添加成員到系統用戶組"

msgid "Unauthorized users are present"
msgstr "存在未授權的使用者"

msgid "Remove members from System User Group"
msgstr "從系統用戶組中移除成員"
Loading
Loading