Problem/Motivation

The permission "Edit all expense and income transactions" excludes the author field.

If you are not user 1 on the site you can not set the author when creating or editing transactions.

Steps to reproduce

Create a new role "Office"
Add all available permissions that this module offers to the "office" role
give a user the office role
login as user and add a transaction.

The author field will not be available to set.

When the user save the transaction the user is set as the author of the transaction.
When the user edit the transaction the author field is not visible to change

Proposed resolution

Add a new permission

edit author expense_tracker:
  title: 'Edit the author of all expense and income transactions'

Comments

Vlooi Vlerke created an issue. See original summary.

vlooi vlerke’s picture

Status: Active » Needs review

It turns out a permission setting was missing.

Add the following to expense_tracker.permissions.yml

administer expense_tracker:
  title: 'Administer expense and income data'

A new permission will be available to select and this will give you access to set the author.

The code this permission executes is in place at src/EtTransactionAccessControlHandler.php

 /**
   * {@inheritdoc}
   */
  protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {

    $restricted_fields = [
      'uid',
    ];
    if ($operation === 'edit' && in_array($field_definition->getName(), $restricted_fields, TRUE)) {
      return AccessResult::allowedIfHasPermission($account, 'administer expense_tracker');
    }
    return parent::checkFieldAccess($operation, $field_definition, $account, $items);
  }
}
sujan shrestha’s picture

Version: 1.3.5 » 2.0.x-dev
Status: Needs review » Fixed

Fixed in 2.0.x (commit 95ecfcb), released in 2.0.3. The author field checked a permission that doesn't exist (administer expense_tracker). It now checks "Edit all expense and income transactions" or "Administer transactions", so roles with either can see and change the author. A kernel test covers this.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.