Add a condition to filter by current user role

Created on 24 April 2018, over 6 years ago
Updated 10 June 2024, 4 months ago

In some cases we need to show something only for the store's staff.
Add a condition to filter by user role (not order customer role).

Feature request
Status

Fixed

Version

2.0

Component

Other

Created by

🇺🇦Ukraine max-kuzomko

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.

  • 🇺🇸United States rszrama

    Thanks, this is great. Definitely needs to be in for the exact use case mentioned.

    A couple minor tweaks I'd request before we commit:

    1. Rename the condition current_user_role.
    2. Rename the class CurrentUserRole to match (along with the related comments).
    3. Relabel the condition User role.
    4. Let's introduce a new more general category called Current request.
    5. I don't think we need the weight; I'd just remove it.

    My rationale for the machine name / label mismatch is that I think "Current request" makes sense as a group (think it's better than "Global" or "Context"), and we don't need the redundant "current" in the label ... but it still makes sense to identify in the code.

    My only other consideration is that since we're adding this new, we might like the opportunity to build operator selection into it. Right now the configuration element is titled Allowed roles, but we could make this two elements:

    1. Matching strategy radios element with options User must have a selected role, User must have all selected roles, and User must have none of the selected roles
    2. Roles checkboxes element with the various roles as options.
  • First commit to issue fork.
  • Merge request !259[#2965067]: Add a condition to filter by user role → (Merged) created by dww
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 4 months ago
    793 pass
  • Status changed to Needs review 4 months ago
  • 🇺🇸United States dww

    Addressed most of #6, but not the fancy roles operations stuff at the end. Converted to MR, hiding patches.

  • Pipeline finished with Success
    4 months ago
    Total: 515s
    #177448
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 4 months ago
    793 pass
  • 🇺🇸United States dww

    Implemented the separate 'Matching strategy' radios and corresponding logic changes in evaluate(). Also replaced the deprecated user_role_names() call with the recommended alternative. Light local testing is working well. Probably wants automated tests, but I don't have time for that now (about to board a flight).

  • 🇺🇸United States dww
  • Pipeline finished with Success
    4 months ago
    Total: 441s
    #177463
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 4 months ago
    793 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 4 months ago
    793 pass
  • Pipeline finished with Canceled
    4 months ago
    Total: 215s
    #177489
  • Pipeline finished with Success
    4 months ago
    Total: 516s
    #177492
  • 🇮🇱Israel jsacksick

    Let's just shorten the keys to "any", and "all", no need for the redundant "role" in there.
    We also need tests.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 4 months ago
    793 pass
  • 🇺🇸United States dww

    - Shortened the keys
    - Added the missing config schema

    Y'all can write tests if you need them. I'm way out of time on the project where I need this functionality, and it's working fine for me.

    Cheers,
    -Derek

  • Pipeline finished with Success
    4 months ago
    Total: 632s
    #179139
  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 4 months ago
    787 pass, 2 fail
  • Pipeline finished with Success
    4 months ago
    Total: 485s
    #180357
  • Pipeline finished with Skipped
    4 months ago
    #181420
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 4 months ago
    794 pass
  • Status changed to Fixed 4 months ago
  • 🇮🇱Israel jsacksick

    Thanks everyone! Merged!

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

Production build 0.71.5 2024