Repository navigation
refactor: add knowledge-base tokenize permission bit #7759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,6 +164,18 @@ def test_mcp_config_has_its_own_permission_and_response(self, serializer): | |
| response = KnowledgeMcpConfigView().get(self.request(P.KNOWLEDGE_MCP_CONFIG), **self.kwargs()) | ||
| self.assertEqual(json.loads(response.content)["data"], {"mcp_config": {"test": True}}) | ||
|
|
||
| @patch("common.log.log.Log") | ||
| @patch("knowledge.views.knowledge.KnowledgeSerializer.Operate") | ||
| def test_tokenize_uses_knowledge_token_permission_instead_of_document_token(self, serializer, log): | ||
| serializer.return_value.tokenize.return_value = {} | ||
| KnowledgeView.Tokenize().put(self.request(P.KNOWLEDGE_TOKEN), **self.kwargs()) | ||
| serializer.assert_called_once() | ||
| for permission in (P.KNOWLEDGE_DOCUMENT_TOKEN, P.KNOWLEDGE_IMAGE_TOKEN, P.KNOWLEDGE_EDIT): | ||
| serializer.reset_mock() | ||
| with self.assertRaises(AppUnauthorizedFailed): | ||
| KnowledgeView.Tokenize().put(self.request(permission), **self.kwargs()) | ||
| serializer.assert_not_called() | ||
|
|
||
| @patch("knowledge.views.knowledge.KnowledgeSerializer.Operate") | ||
| def test_detail_redaction_and_settings_section_permissions(self, serializer): | ||
| serializer.return_value.one.side_effect = lambda: { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's my review of the added test code: Issues & Potential Problems1. Incorrect patch signature / argument order (critical)@patch("common.log.log.Log")
@patch("knowledge.views.knowledge.KnowledgeSerializer.Operate")
def test_...(self, serializer, log):Decorators apply bottom-up, so the innermost decorator is the last argument. That means
So the order happens to be correct here, but it's fragile. Since you're asserting only on 2.
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -565,8 +565,8 @@ class Tokenize(APIView): | |
| tags=[_("Knowledge Base")], # type: ignore | ||
| ) | ||
| @has_permissions( | ||
| PermissionConstants.KNOWLEDGE_DOCUMENT_TOKEN.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_DOCUMENT_TOKEN.get_workspace_permission_workspace_manage_role(), | ||
| PermissionConstants.KNOWLEDGE_TOKEN.get_workspace_knowledge_permission(), | ||
| PermissionConstants.KNOWLEDGE_TOKEN.get_workspace_permission_workspace_manage_role(), | ||
| RoleConstants.WORKSPACE_MANAGE.get_workspace_role(), | ||
| ViewPermission( | ||
| [RoleConstants.USER.get_workspace_role()], | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review of the diff The change replaces
Overall: the edit itself is syntactically fine, but verify the new constant’s existence, keep permission definitions consistent across related endpoints, and add a permission test to guard the changed authorization semantics. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the diff, there are no obvious syntax errors, but there are several things to verify:
bit_indexuniquenessbit_index=73is not already used withinGroup.KNOWLEDGE / Group.KNOWLEDGE.SHARED_KNOWLEDGE_TOKENandRESOURCE_KNOWLEDGE_TOKENboth usebit_index=65. This is fine only ifbit_indexis scoped per(group, sub_group). If bit indexes are global or mixed across groups, this is a collision.bit_index=65is not already used insideGroup.SYSTEM_SHARED_KNOWLEDGEorGroup.SYSTEM_RES_KNOWLEDGE.64-bit overflow risk
bit_index=65andbit_index=73exceed 63. If permission bitmasks are stored as 64-bit integers,BIGINT, or JavaScript numbers, these bits may overflow or lose precision.Security / least privilege for
KNOWLEDGE_TOKENKNOWLEDGE_TOKENis granted toWORKSPACE_MANAGEandUSER, with scopesWORKSPACEandWORKSPACE_RESOURCE.ADMINor management roles.EE / non-EE consistency
SHARED_KNOWLEDGE_TOKENandRESOURCE_KNOWLEDGE_TOKENuseis_ee=is_ee, whileKNOWLEDGE_TOKENdoes not.Operate.TOKENintegrationOperate.TOKENis defined and handled consistently in:Naming / comments
TOKENis somewhat ambiguous. If it means “tokenization/indexing,” considerTOKENIZEorINDEX_TOKEN, or add a comment.KNOWLEDGE_TOKENandSHARED_KNOWLEDGE_TOKENsimilar to the existing# 资源管理 - 知识库分词索引comment.resource_permission_group_listconsistencyKNOWLEDGE_TOKENincludesresource_permission_group_list=[ResourcePermissionConst.KNOWLEDGE_MANAGE].Overall: the main risks are bit-index collisions and >64-bit permission storage. The rest are consistency and least-privilege checks.