Repository navigation
fix: enforce the UCP permission matrix #313
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
Open
Johannes Berthel (joberthel)
wants to merge
1
commit into
fix/admin-ucp-file-persistence
from
fix/205-ucp-admin-acl
+924
−75
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import template from './sw-sales-channel-detail.html.twig'; | |
| import './sw-sales-channel-detail.scss'; | ||
| import { coreShipsAgenticCommerce } from '../../../../core-feature'; | ||
| import { mergeAgenticFileDrafts, saveAgenticFileConfigurations } from '../../agentic-file-persistence'; | ||
| import { currentAdminVersion, isVersionAtLeast, useMtComponents } from '../../agentic-commerce/admin-version'; | ||
| import { | ||
| defaultForm as ucpDefaultForm, | ||
| normalizeConfig as ucpNormalizeConfig, | ||
|
|
@@ -103,13 +104,54 @@ export const swSalesChannelDetailOverride = { | |
| : 'sw.sales.channel.detail.agenticCommerceStatistics'; | ||
| }, | ||
|
|
||
| canViewUcpInsights() { | ||
| return this.acl.can('ucp.viewer'); | ||
| }, | ||
|
|
||
| salesChannelDetailTabs() { | ||
| const tabs = this.$super('salesChannelDetailTabs'); | ||
| if (!Array.isArray(tabs) || !this.isAgenticCommerce || this.canViewUcpInsights) { | ||
| return tabs; | ||
| } | ||
|
|
||
| return tabs.filter((tab) => tab.name !== 'sw.sales.channel.detail.productExportInsights'); | ||
| }, | ||
|
|
||
| shouldRenderAgenticCommerceTab() { | ||
| const typeId = this.salesChannel?.typeId ?? this.$route.params.typeId; | ||
|
|
||
| return this.acl.can('ucp.viewer') | ||
| && (isTransactionalSalesChannelType(typeId) || this.ucpState.transactional); | ||
| }, | ||
|
|
||
| isUcpConfigRoute() { | ||
| return this.$route.name === 'sw.sales.channel.detail.agenticCommerce'; | ||
| }, | ||
|
|
||
| usesMeteorComponents() { | ||
| return useMtComponents(); | ||
| }, | ||
|
|
||
| supportsVueRouterViewSlot() { | ||
| // Vue Router 4 (Shopware 6.6+) supports the scoped router-view slot. | ||
| return isVersionAtLeast(currentAdminVersion(), 6, 6); | ||
| }, | ||
|
|
||
| shouldRenderAgenticCommerceContent() { | ||
| return (!this.isAgenticCommerce | ||
| || this.$route.name !== 'sw.sales.channel.detail.productExportInsights' | ||
| || this.canViewUcpInsights) | ||
| && (this.$route.name !== 'sw.sales.channel.detail.agenticCommerce' || this.shouldRenderAgenticCommerceTab); | ||
| }, | ||
|
|
||
| allowSaving() { | ||
| if (this.isUcpConfigRoute) { | ||
| return this.acl.can('ucp.editor') || this.acl.can('sales_channel.editor'); | ||
| } | ||
|
|
||
| return this.$super('allowSaving'); | ||
| }, | ||
|
|
||
| // Widened to include AC channels so they reuse the product-export blocks. | ||
| // $super() is skipped — it is unreliable during the create flow in 6.5/6.6. | ||
| isProductComparison() { | ||
|
|
@@ -289,7 +331,7 @@ export const swSalesChannelDetailOverride = { | |
| // the page before this write, which replaces `ucpState.form` with the stored, | ||
| // not yet updated config. | ||
| async saveUcpState(salesChannelId, form) { | ||
| if (!form || !salesChannelId) { | ||
| if (!form || !salesChannelId || !this.acl.can('ucp.editor')) { | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -421,7 +463,8 @@ export const swSalesChannelDetailOverride = { | |
| } | ||
|
|
||
| if (this.pendingAgenticFilesReload | ||
| && this.pendingAgenticFilesReload === this.salesChannel?.id) { | ||
| && this.pendingAgenticFilesReload === this.salesChannel?.id | ||
| && this.acl.can('sales_channel.editor')) { | ||
| this.isLoading = true; | ||
| this.isSaveSuccessful = false; | ||
| try { | ||
|
|
@@ -434,10 +477,40 @@ export const swSalesChannelDetailOverride = { | |
| } | ||
| } | ||
|
|
||
| if (this.isUcpConfigRoute && !this.acl.can('sales_channel.editor')) { | ||
| if (!this.acl.can('ucp.editor') || !this.ucpState.loaded) { | ||
| return; | ||
| } | ||
|
|
||
| const salesChannelId = this.salesChannel?.id; | ||
| const form = ucpNormalizeConfig(this.ucpState.form); | ||
| const hasUcpChanges = JSON.stringify(form) !== JSON.stringify(ucpNormalizeConfig(this.ucpState.savedForm)); | ||
|
Contributor
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. nitpick (non-blocking): This adds a third copy of the UCP dirty check to The same comparison is at lines 514 and 556. I suggest a |
||
| this.isSavingUcp = true; | ||
| this.isLoading = true; | ||
| this.isSaveSuccessful = false; | ||
|
|
||
| try { | ||
| if (hasUcpChanges && !await this.saveUcpState(salesChannelId, form)) { | ||
| return; | ||
| } | ||
|
|
||
| this.isSaveSuccessful = true; | ||
| if (salesChannelId && hasUcpChanges) { | ||
| this.refreshUcpPreview(salesChannelId); | ||
| } | ||
| } finally { | ||
| this.isSavingUcp = false; | ||
| this.isLoading = false; | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (!this.isAgenticCommerce) { | ||
| const salesChannelId = this.salesChannel?.id; | ||
| const form = this.ucpState.loaded ? ucpNormalizeConfig(this.ucpState.form) : null; | ||
| const hasUcpChanges = form | ||
| && this.acl.can('ucp.editor') | ||
| && JSON.stringify(form) !== JSON.stringify(ucpNormalizeConfig(this.ucpState.savedForm)); | ||
|
|
||
| // Keep core validation and Storefront theme assignment in the save chain. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
issue: Save does nothing when the UCP config failed to load.
ucpState.loadedonly turnstrueoncegetConfighas answered. After a failed request it staysfalse.allowSavingstill enables Save for aucp.editoron this tab. A click then returns here without a request, a notification or a spinner.Could you keep Save disabled until
ucpState.loadedistrueon this route?