update report data permission not working

Created on 20 September 2023, 9 months ago
Updated 27 October 2023, 8 months ago

Problem/Motivation

Users with the 'update report data' permission still can't see the update report data button if they are not user 1.

The code for deciding to show the button or not is currently, if($uid == 1 || in_array('update report data', $userRoles)) {...}, which means it is looking at the user's roles, not the permissions of the user.

Proposed resolution

Change the code to look for if the current user has the correct permission rather than looking for the permission name in the user's roles list.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom Belazoth

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Belazoth
  • @belazoth opened merge request.
  • Status changed to Needs review 9 months ago
  • πŸ‡¬πŸ‡§United Kingdom Belazoth

    I have made a merge request with the change that will hopefully fix this issue. This is also a patch with the same changes for those who might want to use the fix before it gets merged.

  • πŸ‡¬πŸ‡§United Kingdom Belazoth

    I have updated the patch and merge request as I noticed that even if you had the permission 'update report data' you could not update the report data as it was looking for a different permission.

  • Status changed to Needs work 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom welly

    Looks pretty good to me. I would say it'd probably be preferable to inject β†’ the AccountProxy service rather than using Drupal::currentUser but can see the module was previously using that method to get the user. The class is well set up for dependency injection so I think it might be worth doing that.

    That's the only thing I would suggest, otherwise looks good.

    I'll put this in "Needs work" for now - if you feel like using dependency injection for the current user/accountproxy service then please do otherwise perhaps someone else can take a look and move it to RTBC?

  • Status changed to Needs review 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom Belazoth

    Thanks for the suggestion Welly. I have updated the patch and the merge request, let me know if everything you have any other suggestions.

Production build 0.69.0 2024