Comments

vtcore created an issue. See original summary.

vtcore’s picture

I know this is related with #2773645: Allow hook_entity_field_access() to grant field-level access to User fields: 'forbidden' -> 'neutral'. The patch provided is a workaround for user fields. Also it alters the access of the "user_role" entity in order to show role names in admin/people.

adamps’s picture

@vtcore Thanks for the issue and patch. I am reluctant to commit a workaround patch until we have tried really hard to get the core fix applied. However it certainly is useful to have the patch available for anyone would like to use it.

As a starting point, please can you review and test my patch in #2773645: Allow hook_entity_field_access() to grant field-level access to User fields: 'forbidden' -> 'neutral', then mark it as RTBC, with an endorsement for how it is an important fix?

You say your patch "also alters the access". Please can you explain more? Do you mean that your patch provides some extra function that the patch in #2773645: Allow hook_entity_field_access() to grant field-level access to User fields: 'forbidden' -> 'neutral' does not? If so, please can you separate out the parts of the patch that are a workaround and the parts that ought to be committed even if the core patch gets applied?

vtcore’s picture

StatusFileSize
new65.77 KB

Sorry about the quick and dirty patch. The patch at #2773645: Allow hook_entity_field_access() to grant field-level access to User fields: 'forbidden' -> 'neutral' works fine for the field's access. However the role names are not shown (see attached screenshot). The first part of the patch is for that function administerusersbyrole_user_role_access(). I'll split the patch in two:

I marked the core issue as RTBC.

vtcore’s picture

Patch for roles access.
Implements hook_ENTITY_TYPE_access for the user_role entity type. If the operation is 'view' we check the permission 'access users overview' provided by administerusersbyrole.
The default core permission that is checked is 'administer permissions' which is for viewing, adding, editing and deleting roles, and we don't want to give that to our "low-privilege" admins just to be able to see which role is assigned to a user.

vtcore’s picture

Workaround for #2773645: Allow hook_entity_field_access() to grant field-level access to User fields: 'forbidden' -> 'neutral'
Implements hook_entity_field_access_alter and changes the :default AccessResult if administerusersbyrole allowed it.

  • AdamPS committed 6bb689a on 8.x-2.x
    Issue #2826379 by vtcore: Show role names in admin/people
    
adamps’s picture

Committed the patch for show role names in admin/people, thanks.

adamps’s picture

Status: Active » Postponed

Remainder of issue for missing fields is marked as postponed pending a determined attempt to get the fix applied to core.

adamps’s picture

The core issue #2773645: Allow hook_entity_field_access() to grant field-level access to User fields: 'forbidden' -> 'neutral' is now marked as "needs tests". If anyone can help with that, please go ahead and upload a patch.

nyariv’s picture

The commit in #7 does not work for me. It seems the hook does not get called at all for non admins.

adamps’s picture

@nyariv It's still working fine for me. Please check #2807021: Drupal 8 roadmap - did you definitely apply the patch for #2773645: Allow hook_entity_field_access() to grant field-level access to User fields: 'forbidden' -> 'neutral'?

nyariv’s picture

@AdamPS I enabled administerusersbyrole_hack and it did not help. If it is possible to apply a workaround through that module, it would be preferable to applying a patch to core, at least as a temporary solution.

adamps’s picture

Status: Postponed » Active

Right now the "hack" module does not help with #2773645: Allow hook_entity_field_access() to grant field-level access to User fields: 'forbidden' -> 'neutral' but I agree that's a good idea.

nyariv’s picture

@AdamPS Is there a code snippet I can use until it is committed? Nevermind, I didn't notice #6.

nyariv’s picture

When filtering for a user name in the user management page you get 'page not found' if you do not have admin permissions. All other filters work. This applies to both #6 patch and core patch.

adamps’s picture

@nyariv thanks for the report please can you open a new issue?

adamps’s picture

Title: Some fields and roles are not shown in admin/people » Role names not shown in admin/people
Issue summary: View changes
Status: Active » Fixed
adamps’s picture

@nyariv thanks I see your new issue for #16. Please can you also raise one for #13? It is definitely helpful to me that we are getting back to one issue for each bug / patch / commit.

I have marked this issue as fixed because #5 has been committed.

nyariv’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.