Repository navigation
delete: knowledge export skills on the backend - #7721
Conversation
|
|
||
| RESOURCE_KNOWLEDGE_IMAGE_READ = ( | ||
| Permission(group=Group.SYSTEM_RES_KNOWLEDGE, sub_group=Group.SYSTEM_IMAGE, operate=Operate.READ, bit_index=46), | ||
| PermissionMeta( |
There was a problem hiding this comment.
Based on the provided diff, the changes are syntactically plausible: three PermissionConstants enum members are removed.
However, I see several potential risks and missing follow-ups:
1. High: Dangling references may break startup or authorization
Search the entire codebase for these removed symbols:
KNOWLEDGE_EXPORT_SKILLSSHARED_KNOWLEDGE_EXPORT_SKILLSRESOURCE_KNOWLEDGE_EXPORT_SKILLSOperate.EXPORT_SKILLS
If any decorator, authorization check, serializer, fixture, test, or config still references them, it will likely fail with AttributeError, KeyError, or import errors.
2. High: Persistent permissions and role grants need migration
If these permissions are stored in DB tables, role-permission mappings, cached bitmasks, or serialized configs, simply deleting the enum members is not enough. You likely need a data migration to:
- Remove or disable the permission records.
- Remove role mappings.
- Recalculate role bitmasks.
- Invalidate permission caches.
- Handle existing records that reference the deleted permission names.
Otherwise, stale grants may remain.
3. High: Do not reuse deleted bit_index values
The removed permissions use:
bit_index=13bit_index=64bit_index=45
If those bit indices are later reused for new permissions, existing role bitmasks may unintentionally grant the new permission. This is a privilege-escalation risk. Retire these bit indices permanently, or implement an explicit migration before reuse.
4. High: Check for authorization regressions
If the corresponding export-skill endpoints still exist, removing their permission constants may leave those endpoints:
- Unprotected,
- Protected by a different permission unintentionally,
- Returning
500instead of403, - Inconsistent between workspace/shared/resource scopes.
Confirm that removing these permissions is intentional and that the endpoints are either removed, feature-disabled, or still correctly authorized.
5. Medium: Breaking change for external consumers
Permission names are often part of API responses, configs, or client behavior. Removing them may be a breaking change. If they were released, consider deprecation/aliasing first unless this is coordinated with all consumers.
6. Medium: Tests and snapshots need updates
Check for tests that assert:
- The full permission list,
- Permission counts,
- Role bitmasks,
- OpenAPI/schema snapshots,
- EE permission matrix behavior.
The is_ee=is_ee field on SHARED_KNOWLEDGE_EXPORT_SKILLS suggests EE-specific behavior may be affected.
7. Low: Dead enum values and bit gaps
After removal, Operate.EXPORT_SKILLS may become unused. Also, permission bits are now non-contiguous. That is usually fine, but verify no code assumes contiguous bit ranges or maximum bit indices.
Recommendation
Before merging:
- Grep for all removed permission names and
Operate.EXPORT_SKILLS. - Add/verify DB migration and cache invalidation.
- Confirm endpoints are removed or still properly authorized.
- Update tests/snapshots/docs.
- Ensure deleted
bit_indexvalues are never reused without migration.
The diff itself does not show an obvious syntax error, but without the full repository I cannot confirm that all references and persisted data are handled.
| self.assertIn(str(P.KNOWLEDGE_EXPORT_SKILLS.value), ids) | ||
|
|
||
| @patch("knowledge.views.document.DocumentSerializers.Query") | ||
| def test_image_and_document_lists_require_their_own_read_permission(self, serializer): |
There was a problem hiding this comment.
Review of the diff
@@ -91,7 +91,6 @@ def test_new_permissions_appear_in_workspace_role_tree(self):
ids = {p["id"] for p in children["KNOWLEDGE"]["permission"]}
self.assertIn(str(P.KNOWLEDGE_MCP_CONFIG.value), ids)
- self.assertIn(str(P.KNOWLEDGE_EXPORT_SKILLS.value), ids)Issues / irregularities
-
Test intent no longer matches its name.
test_new_permissions_appear_in_workspace_role_treeis supposed to assert that new permissions appear. Deleting the assertion silently reduces coverage and lets a regression (permission disappearing from the role tree) pass. Prefer an explicitassertNotInif removal is intentional, so the expected behavior is documented:self.assertNotIn(str(P.KNOWLEDGE_EXPORT_SKILLS.value), ids)
-
Possible
countmismatch.
The test usescountto validate the number of permissions per group (assertEqual(len(children[group]["permission"]), count)). IfKNOWLEDGE_EXPORT_SKILLSwas removed from the tree, the expectedcountlikely needs to be decremented; otherwise the test may fail for an unrelated reason, or mask an off-by-one. -
Dead code / orphaned enum.
Check whetherP.KNOWLEDGE_EXPORT_SKILLSis still referenced anywhere. If not, remove the enum member (and any serializers/views/migrations that reference it). Leaving it behind is dead code and can confuse future permission-tree work. -
Data migration.
If the permission was removed, ensure a migration cleans up existingRole/permission rows referencingKNOWLEDGE_EXPORT_SKILLS. Otherwise stale DB records may remain and the role tree can behave inconsistently across environments. -
No replacement assertion.
IfEXPORT_SKILLSwas replaced by a new permission (e.g. renamed), add anassertInfor the new permission so the test still verifies the "new permissions appear" contract.
Minor / optimization suggestions
- Use
assertSet-style comparison orself.assertTrue(expected.issubset(ids))for clearer intent when checking multiple permissions, or loop withsubTestto get per-permission failure messages. - The
@patch(...)decorator injectsserializer, which appears unused in this test. If it's not used, remove it (or assert it was used) to avoid misleading test setup. - Given the current date and Python versions, consider
assertInover set membership is fine, but buildingidsonce and usingexpected - idsin an error message would make failures easier to debug:missing = expected - ids self.assertFalse(missing, f"Missing permissions: {missing}")
- Verify the hunk line counts are right (
-91,7 +91,6) — they are consistent with a single-line deletion.
Bottom line
The change is syntactically fine, but functionally it weakens the test without documenting the new expected behavior. Replace the deletion with an explicit negative assertion (or add the replacement permission), reconcile count, and clean up any now-unused enum/migration references.
delete: knowledge export skills on the backend