Skip to content

fix: correct workspace permission role for model creation - #7957

Merged
wxg0103 merged 1 commit into
v3from
pr@v3@fix_model_permission
Nov 17, 2026
Merged

wxg0103 merged 1 commit into
v3from
pr@v3@fix_model_permission

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: correct workspace permission role for model creation

PermissionConstants.MODEL_CREATE.get_workspace_permission_workspace_manage_role(),
RoleConstants.WORKSPACE_MANAGE.get_workspace_role(),
RoleConstants.USER.get_workspace_role(),
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of the diff:

The change replaces MODEL_EDIT with MODEL_CREATE in the second permission argument. A few observations:

  1. Likely a bug (or intentional fix — needs confirmation):
    The first argument already uses MODEL_CREATE.get_workspace_permission(). Having both arguments reference MODEL_CREATE means MODEL_EDIT is no longer checked at all on this endpoint (which appears to be ModelSetting, suggesting edit/update semantics). If this endpoint handles updates, dropping MODEL_EDIT is 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.

  2. Duplicate-style permissions are redundant:
    Check the semantics of has_permissions — does it require all permissions or any? If it requires any one to pass, then having two near-identical MODEL_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.

  3. Consistency with view name:
    ModelSetting reads as a configuration/update endpoint. The permission set should reflect the operation: create vs. edit vs. manage. Verify against the HTTP methods handled by ModelSetting (POST/PUT/PATCH/DELETE). Ideally use method-specific permission checks (e.g., branch on request.method) rather than a single flat list.

  4. 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.

  5. 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.

@wxg0103
wxg0103 merged commit e5dc7ed into v3 Nov 17, 2026
3 of 4 checks passed
@wxg0103
wxg0103 deleted the pr@v3@fix_model_permission branch November 17, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants