Skip to content
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

[5.x]: "User not authorized to create this element." after cancelling the creation of a block on matrix field #15015

Closed
brionwolf opened this issue May 16, 2024 · 2 comments
Assignees
Labels

Comments

@brionwolf
Copy link

brionwolf commented May 16, 2024

What happened?

Description

  • Clicking away or clicking "cancel" while creating an entry in a drawer for a matrix field works as expected (cancelling the creation of that block), but clicking the "add block" button again will throw a "User not authorized to create this element." error.

Steps to reproduce

  1. Create a matrix field, with at least one entry type.
  2. Set a Max Entries value (ie: 1 or 2).
  3. Set the view mode to "As an element index" or "As cards"
  4. Add the matrix field to another field layout for testing.
  5. Create or edit an entry with the matrix field.
  6. Click the button to add a new block to the matrix field
  7. Once the entry create drawer opens, cancel the creation of the entry.
  8. Repeat steps 6 and 7 until you have done so once-more than the "Max Entries" value.

Expected behavior

  • I should be able to cancel and/or add a block from the matrix field as many times as I want.

Actual behavior

  • Craft throws an error stating "User not authorized to create this element.", and the element cannot be recreated.
  • If the Max Entries value is greater than 1, one of the "canceled" entries may appear as a draft entry after reloading the page, or attempting to save.
  • If the matrix block is nested in the field layout of another matrix block I occasionally have to delete and create the parent block to resolve the error.

Screen captures:

animated image of a craft control panel reproducing an example of the error

Stack Trace:

yii\web\ForbiddenHttpException: User not authorized to create this element. in craft/vendor/craftcms/cms/src/controllers/ElementsController.php:2186
Stack trace:
#0 craft/vendor/craftcms/cms/src/controllers/ElementsController.php(194): craft\controllers\ElementsController->_createElement()
#1 [internal function]: craft\controllers\ElementsController->actionCreate()
#2 craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#4 craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('create', Array)
#5 craft/vendor/craftcms/cms/src/web/Application.php(349): yii\base\Module->runAction('elements/create', Array)
#6 craft/vendor/craftcms/cms/src/web/Application.php(650): craft\web\Application->runAction('elements/create', Array)
#7 craft/vendor/craftcms/cms/src/web/Application.php(311): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#8 craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#9 craft/web/index.php(12): yii\base\Application->run()
#10 {main}

Craft CMS version

Craft Pro 5.1.3

PHP version

8.3.4

Operating system and version

MacOS Sonoma 14.4.1 (23E224)

Database type and version

MySQL 8.3.0

Image driver and version

GD 8.3.4

Installed plugins and versions

  • CKEditor | 4.0.5
@i-just
Copy link
Contributor

i-just commented May 20, 2024

Hi, thanks for reporting! I raised a PR for this.

@brandonkelly
Copy link
Member

Craft 5.1.5 is out with that fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants