-
Notifications
You must be signed in to change notification settings - Fork 5
feat: registry_admin_only_crud opt-out per action (#298) #302
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
base: 19.0
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -57,6 +57,11 @@ fetchRestriction(); | |
| // Actions to strip from the action menu when restricted | ||
| const BLOCKED_ACTIONS = ["delete", "archive", "unarchive", "duplicate"]; | ||
|
|
||
| function bypassRegistryRestriction(component) { | ||
| const context = component.props?.context || {}; | ||
| return context.bypass_registry_admin_only_crud === true; | ||
| } | ||
|
|
||
| /** | ||
| * Patch FormController to enforce read-only on registry forms when restricted. | ||
| * | ||
|
|
@@ -69,6 +74,10 @@ const BLOCKED_ACTIONS = ["delete", "archive", "unarchive", "duplicate"]; | |
| patch(FormController.prototype, { | ||
| setup() { | ||
| const modelName = this.props.resModel; | ||
| if (REGISTRY_MODELS.includes(modelName) && bypassRegistryRestriction(this)) { | ||
| super.setup(...arguments); | ||
| return; | ||
| } | ||
| // Check synchronous cache BEFORE super.setup() creates the model | ||
| this._registryRestricted = | ||
| REGISTRY_MODELS.includes(modelName) && _restrictionResult === true; | ||
|
|
@@ -153,7 +162,10 @@ patch(FormController.prototype, { | |
| get modelParams() { | ||
| const params = super.modelParams; | ||
| // Force readonly mode when registry is restricted | ||
| if (this._registryRestricted) { | ||
| if ( | ||
| this._registryRestricted && | ||
| !bypassRegistryRestriction(this) | ||
| ) { | ||
| params.config.mode = "readonly"; | ||
| } | ||
| return params; | ||
|
|
@@ -162,7 +174,11 @@ patch(FormController.prototype, { | |
| get actionMenuItems() { | ||
| const menuItems = super.actionMenuItems; | ||
|
|
||
| if (this._registryRestricted && REGISTRY_MODELS.includes(this.props.resModel)) { | ||
| if ( | ||
| this._registryRestricted && | ||
| REGISTRY_MODELS.includes(this.props.resModel) && | ||
| !bypassRegistryRestriction(this) | ||
| ) { | ||
|
Comment on lines
+177
to
+181
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. |
||
| if (menuItems.action) { | ||
| menuItems.action = menuItems.action.filter( | ||
| (item) => !BLOCKED_ACTIONS.includes(item.key) | ||
|
|
@@ -185,6 +201,9 @@ patch(ListController.prototype, { | |
| if (!REGISTRY_MODELS.includes(modelName)) { | ||
| return; | ||
| } | ||
| if (bypassRegistryRestriction(this)) { | ||
| return; | ||
| } | ||
|
Comment on lines
201
to
+206
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. |
||
|
|
||
| this._registryRestricted = false; | ||
| this._restrictionObserver = null; | ||
|
|
@@ -247,7 +266,11 @@ patch(ListController.prototype, { | |
| get actionMenuItems() { | ||
| const menuItems = super.actionMenuItems; | ||
|
|
||
| if (this._registryRestricted && REGISTRY_MODELS.includes(this.props.resModel)) { | ||
| if ( | ||
| this._registryRestricted && | ||
| REGISTRY_MODELS.includes(this.props.resModel) && | ||
| !bypassRegistryRestriction(this) | ||
| ) { | ||
|
Comment on lines
+269
to
+273
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. Since we return early in if (this._registryRestricted && REGISTRY_MODELS.includes(this.props.resModel)) { |
||
| if (menuItems.action) { | ||
| menuItems.action = menuItems.action.filter( | ||
| (item) => !BLOCKED_ACTIONS.includes(item.key) | ||
|
|
||
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.
Since
this._registryRestrictedis already set tofalsewhen the restriction is bypassed, we don't need to check!bypassRegistryRestriction(this)here. We can revert this to the simpler original check.