Skip to content

Commit 35e765d

Browse files
authored
Merge pull request #3831 from craftcms/feature/pt-2355-4x-duplicate-action-for-edit-product-does-check-permission
Fixed #3819 product duplication not checking permissions
2 parents 1b40aeb + 6723a9d commit 35e765d

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes for Craft Commerce
22

3+
## Unreleased
4+
5+
- Fixed a bug where Edit Product pages would allow duplication for users that didn’t have permission to duplicate the product. ([#3819](https://github.com/craftcms/commerce/issues/3819))
6+
37
## 4.7.2 - 2024-12-18
48

59
- Fixed a bug where the Edit Order page wasn’t showing order errors.

src/controllers/ProductsController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ public function actionSaveProduct(bool $duplicate = false): ?Response
360360
*/
361361
public function actionDuplicateProduct(): ?Response
362362
{
363+
$product = ProductHelper::productFromPost($this->request);
364+
if (!Craft::$app->getElements()->canDuplicate($product)) {
365+
throw new ForbiddenHttpException('User is not permitted to duplicate this product');
366+
}
367+
363368
return $this->runAction('save-product', ['duplicate' => true]);
364369
}
365370

src/templates/products/_edit.twig

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
}
2424
] %}
2525
{% if product.id %}
26-
{% set formActions = formActions|push({
27-
label: 'Save as a new {type}'|t('app', { type: product.lowerDisplayName() }),
28-
redirect: '{cpEditUrl}'|hash,
29-
action: 'commerce/products/duplicate-product'
30-
}) %}
26+
{% if canDuplicate(product) %}
27+
{% set formActions = formActions|push({
28+
label: 'Save as a new {type}'|t('app', { type: product.lowerDisplayName() }),
29+
redirect: '{cpEditUrl}'|hash,
30+
action: 'commerce/products/duplicate-product'
31+
}) %}
32+
{% endif %}
3133
{% if canDelete(product) %}
3234
{% set formActions = formActions|push({
3335
action: 'commerce/products/delete-product',

0 commit comments

Comments
 (0)