Use standard entity permissions

This commit is contained in:
Paul Weidner 2023-08-10 17:13:28 -07:00 committed by Michael Stenta
parent 3505e80124
commit 18db434a68
7 changed files with 11 additions and 12 deletions

View File

@ -4,6 +4,7 @@ type: module
package: farmOS package: farmOS
core_version_requirement: ^9 core_version_requirement: ^9
dependencies: dependencies:
- entity:entity
- drupal:taxonomy - drupal:taxonomy
- farm:asset - farm:asset
- farm:farm_log_quantity - farm:farm_log_quantity

View File

@ -1,5 +1,5 @@
farm_quick: farm_quick:
config_permissions: config_permissions:
- configure quick forms - update quick_form
default_permissions: default_permissions:
- view quick forms index - view quick_form

View File

@ -1,4 +0,0 @@
view quick forms index:
title: 'View quick forms index'
configure quick forms:
title: 'Configure quick forms'

View File

@ -4,7 +4,7 @@ farm.quick:
_controller: '\Drupal\farm_quick\Controller\QuickFormController::index' _controller: '\Drupal\farm_quick\Controller\QuickFormController::index'
_title: 'Quick forms' _title: 'Quick forms'
requirements: requirements:
_permission: 'view quick forms index' _permission: 'view quick_form'
farm_quick.quick_form: farm_quick.quick_form:
path: /quick/{quick_form} path: /quick/{quick_form}

View File

@ -20,6 +20,8 @@ use Drupal\farm_quick\QuickFormPluginCollection;
* plural = "@count quick forms", * plural = "@count quick forms",
* ), * ),
* handlers = { * handlers = {
* "access" = "\Drupal\entity\EntityAccessControlHandler",
* "permission_provider" = "\Drupal\entity\EntityPermissionProvider",
* "form" = { * "form" = {
* "configure" = "Drupal\farm_quick\Form\ConfigureQuickForm", * "configure" = "Drupal\farm_quick\Form\ConfigureQuickForm",
* }, * },

View File

@ -98,8 +98,8 @@ class ConfigureQuickForm extends EntityForm {
return AccessResult::forbidden(); return AccessResult::forbidden();
} }
// Check the configure quick forms permission. // Check the update quick_form permission.
$configure_form_access = AccessResult::allowedIfHasPermissions($account, ['configure quick forms']); $configure_form_access = AccessResult::allowedIfHasPermissions($account, ['update quick_form']);
return $quick_form->getPlugin()->access($account)->andIf($configure_form_access); return $quick_form->getPlugin()->access($account)->andIf($configure_form_access);
} }

View File

@ -34,8 +34,8 @@ class QuickFormTest extends FarmBrowserTestBase {
$this->drupalGet('quick'); $this->drupalGet('quick');
$this->assertSession()->statusCodeEquals(403); $this->assertSession()->statusCodeEquals(403);
// Create and login a test user with access to the quick form index. // Create and login a test user with access to view quick forms.
$user = $this->createUser(['view quick forms index']); $user = $this->createUser(['view quick_form']);
$this->drupalLogin($user); $this->drupalLogin($user);
// Go to the quick form index and confirm that access is granted, but no // Go to the quick form index and confirm that access is granted, but no
@ -50,7 +50,7 @@ class QuickFormTest extends FarmBrowserTestBase {
// Create and login a test user with access to the quick form index, and // Create and login a test user with access to the quick form index, and
// permission to create test logs. // permission to create test logs.
$user = $this->createUser(['view quick forms index', 'create test log']); $user = $this->createUser(['view quick_form', 'create test log']);
$this->drupalLogin($user); $this->drupalLogin($user);
// Go to the quick form index and confirm that access is granted, and the // Go to the quick form index and confirm that access is granted, and the