Repository navigation
fix: correct workspace permission role for model creation - #7957
Conversation
| PermissionConstants.MODEL_CREATE.get_workspace_permission_workspace_manage_role(), | ||
| RoleConstants.WORKSPACE_MANAGE.get_workspace_role(), | ||
| RoleConstants.USER.get_workspace_role(), | ||
| ) |
There was a problem hiding this comment.
Review of the diff:
The change replaces MODEL_EDIT with MODEL_CREATE in the second permission argument. A few observations:
-
Likely a bug (or intentional fix — needs confirmation):
The first argument already usesMODEL_CREATE.get_workspace_permission(). Having both arguments referenceMODEL_CREATEmeansMODEL_EDITis no longer checked at all on this endpoint (which appears to beModelSetting, suggesting edit/update semantics). If this endpoint handles updates, droppingMODEL_EDITis a privilege-escalation risk — users who can only create models could now modify existing ones. If the intent was to mirror the pattern of the first line, that's clear; if it was a copy-paste error, revert it. -
Duplicate-style permissions are redundant:
Check the semantics ofhas_permissions— does it require all permissions or any? If it requires any one to pass, then having two near-identicalMODEL_CREATE.*entries adds nothing and only obscures intent. Clarify whether these are OR-ed (a user only needs one) or AND-ed. Typically decorators like this are OR-based (any matching role/permission grants access), which would make this change effectively a permission broadening. -
Consistency with view name:
ModelSettingreads as a configuration/update endpoint. The permission set should reflect the operation: create vs. edit vs. manage. Verify against the HTTP methods handled byModelSetting(POST/PUT/PATCH/DELETE). Ideally use method-specific permission checks (e.g., branch onrequest.method) rather than a single flat list. -
Naming/maintainability suggestion:
get_workspace_permission_workspace_manage_role()is verbose and hides intent. Consider defining composite constants (e.g.,MODEL_MANAGE_PERMISSIONS) so call sites don't need to duplicate long method chains, reducing the chance of copy-paste mistakes like this. -
Tests:
Add/adjust unit tests asserting non-privileged users (create-only, no edit permission) are correctly rejected on the update path, and that workspace-manage roles still pass.
Summary: If the endpoint is read/create-only, the change is fine but the duplicate MODEL_CREATE calls are pointless. If the endpoint performs edits, this change removes an important authorization check and should be reverted or clarified. Confirm has_permissions combining logic (AND vs OR) before merging.
fix: correct workspace permission role for model creation