Add permissions for views exposed filters

Created on 7 January 2021, over 4 years ago
Updated 18 April 2023, over 2 years ago

Also add an option to the FILTER CRITERIA

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΈπŸ‡°Slovakia Jozef 95

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΈπŸ‡°Slovakia coaston

    Hello matsbla,

    I just tested path #6 it does not work for the latest version with D10 support.
    I can see the option in exposed filters now and I can configure the role, but nothing happens. Still visible for everyone.

  • Assigned to ad0z
  • Status changed to Needs work over 1 year ago
  • πŸ‡΅πŸ‡±Poland ad0z

    Exposed filters access handler check has to be run before view build phrase as exposed filter form is build there.
    I think we can clearly run field handlers remove at that point as well, I don't see a point we could not.
    I've prepared solution for that, based on my research and @matsbla work.
    I've pushed working solution for me on related issue's fork, and tomorrow I will prepare browser tests as well, to make sure it is working as expected.

  • Merge request !6Resolve #3191345 "Add permissions for" β†’ (Open) created by ad0z
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • πŸ‡΅πŸ‡±Poland ad0z

    Added tests, GitLab CI, fixed phpcs and phpstan issues, pipeline is passing successfully on the issue fork. Review needed and some manual testing as well.

  • Assigned to ad0z
  • Status changed to Needs work over 1 year ago
  • πŸ‡΅πŸ‡±Poland ad0z

    I think I found a bug, when user has no access to filter criteria - filter criteria is not applied to the view, I suppose it should not happen as view should be working as expected still. I will take a look at this.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • πŸ‡΅πŸ‡±Poland ad0z

    I thought about it more and I think it's working as expected, when user has no permission to filter whenever it's exposed or not, it should be not applied, that's make sense more We can discuss it if you think differently, but I am moving issue to needs review now.

  • πŸ‡¬πŸ‡§United Kingdom lincoln-batsirayi

    Hey @ad0z so I've got a use case for what you've described in your comment above. Essentially we've got a restricted usage field on all media items and we want to use the field to filter content if you’re a site admin on the media views. All other roles should not have access to the filter although it's default value of "Exclude" should still apply so that they don't see media items they aren’t supposed to. I was initially trying to do this through a custom form alter hook but ran into the issue you’ve described even when i disabled the filter and when i installed this module i realised that it also had that very same issue...

    I'm not exactly asking for this to be made as a fix on this issue as it is a niche usecase but i did wonder if you had any ideas of how it could be resolved?

  • πŸ‡΅πŸ‡±Poland ad0z

    Hi @lincoln-batsirayi,
    Not sure if I got your scenario, but what if you use this module and add the filter you want twice:
    - One for admin(show filter)
    - One which negate admin(apply exclude option)
    Then as administrator "Exclude" filter won't be applied, and you will be able to to see all options.
    As non admin the "Exclude" will be applied and filter it out.

    There is quite few approaches to apply some custom logic for view based on roles.
    I think you might use hook_views_pre_view to get rid of exposed filter/filter based on conditions.
    There is hook_views_query_alter which might be helpful to alter view query based on some custom logic.

  • πŸ‡¬πŸ‡§United Kingdom lincoln-batsirayi

    Thanks @ad0z the suggestion of creating 2 filters and using this module worked, thanks a lot :)

Production build 0.71.5 2024