Skip to content

Commit

Permalink
Check inventory quick form access based on configured log type and as…
Browse files Browse the repository at this point in the history
…set.
  • Loading branch information
mstenta committed Jan 6, 2024
1 parent 0dd6e7b commit 4abd727
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions modules/quick/inventory/src/Plugin/QuickForm/Inventory.php
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\farm_quick_inventory\Plugin\QuickForm;

use Drupal\asset\Entity\AssetInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
Expand All @@ -27,9 +28,7 @@
* label = @Translation("Inventory"),
* description = @Translation("Record asset inventory adjustments."),
* helpText = @Translation("Use this form to increment, decrement, or reset the inventory of an asset. A new log will be created to record the adjustment."),
* permissions = {
* "create observation log",
* }
* permissions = {}
* )
*/
class Inventory extends QuickFormBase implements ConfigurableQuickFormInterface {
Expand Down Expand Up @@ -100,6 +99,21 @@ public static function create(ContainerInterface $container, array $configuratio
);
}

/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {

// Check to ensure the user has permission to create the configured log type
// and view the configured asset.
$result = AccessResult::allowedIf($this->entityTypeManager->getAccessControlHandler('log')->createAccess($this->configuration['log_type'], $account));
if (!empty($this->configuration['asset'])) {
$asset = $this->entityTypeManager->getStorage('asset')->load($this->configuration['asset']);
$result = $result->andIf(AccessResult::allowedIf($asset->access('view')));
}
return $result;
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 4abd727

Please sign in to comment.