question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Add roles" placeholder is missing if the role is deleted or `edit_posts` capability is revoked

See original GitHub issue

Bug Description

Bug bash issue: https://app.asana.com/0/1202258919887896/1202443593793369 please see Asana task for background

Steps To Reproduce:

  • Using the User Role Editor plugin, add a custom user role and provide edit_posts capability to that role to be available in the DS settings user roles.
  • Set the custom role to a module in the DS settings.
  • Delete the custom role.
  • Or revoke the edit_posts capability.
  • Go to the DS settings modal.

Actual: The module with the custom role set is currently empty, which is expected. However, the Add roles placeholder is missing. That’s due the role is still available in the _googlesitekitDashboardSharingData.settings[module].sharedRoles array. The current logic checks the length of that array and displays the placeholder.

Expected: Add roles placeholder should be visible if the role is deleted or the edit_posts capability is revoked.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The shared roles of a module must always be a subset of the list of all current shareable roles
    • Non-shareable roles should be filtered out accordingly when saving module sharing settings and when reading/loading the value on the backend

Implementation Brief

In includes/Core/Modules/Module_Sharing_Settings.php:

For reading data from the backend, the following steps are taken:

  • Within the Module_Sharing_Settings::get method, call the filter_shared_roles method to get the filtered list of shared roles.
  • Return the filtered list of shared roles within the sharing_settings.

For saving data to the backend, the following steps are taken:

  • Similarly to the above, the Module_Sharing_Settings::get_sanitize_callback should use the filter_shared_roles method to get the filtered list of shared roles.
  • Return the filtered list of shared roles within the sanitized_option.

Test Coverage

  • In tests/phpunit/integration/Core/Modules/Module_Sharing_SettingsTest.php, update the test_get and test_get_sanitize_callback tests to add coverage for the above scenario.

QA Brief

  • Follow the provided steps to reproduce, and ensure that the “Add roles” placeholder is present, after deleting/revoking the edit_posts capability for a custom role.

Changelog entry

  • Ensure the user role select always displays properly based on current shareable roles.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14

github_iconTop GitHub Comments

2reactions
techanvilcommented, Aug 23, 2022

Hi @hussain-t, here’s a bit of commentary on the IB so far.

The option_ and default_option_ filters are applied after the value is read from the database. So, in order to filter when writing to the DB we should in fact augment the Module_Sharing_Settings::get_sanitize_callback method.

Also because option_ / default_option_ are applied after reading from the DB, the change you have suggested to get_all_shared_roles should not be necessary.

Mind you another consideration is, seeing as we will be updating Module_Sharing_Settings::get_sanitize_callback to filter on write, maybe we should apply the filter-on-read to Module_Sharing_Settings::get rather than having this filtering logic spread across Module_Sharing_Settings and Module. So we could have a reusable filter_shared_roles helper method in Module_Sharing_Settings and then call that in both get_sanitize_callback and get

1reaction
mohitwpcommented, Oct 7, 2022

@aaemnnosttv Sorry, It was a typo. Just updated my comment. Yes there is no error showing anymore. Above mentioned issue is resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Orchestrator Roles deleted accidentally - Help
Hi I have accidentally deleted the roles in orchestrator(“https://platform.uipath.com/”). ... Is there anyway this can be revoked? regards.
Read more >
Admin role removed. I just removed a custom role f...
Admin role removed. I just removed a custom role from my instance, but i lost some other roles automatically.
Read more >
Discourse Version 2.6 - releases
The attribute is discourse-url not data-discourse-url; Staff can create and edit posts even if a topic is in slow mode.
Read more >
How to restore deleted WordPress user roles
How to restore lost user roles · 1st variant – install “P” at the test WordPress site. Look into the “Custom Capabilities” section...
Read more >
SportsPress Pro Changelog
2.6.13. Fix - Missing functionality with Gutenberg enabled. ... Tweak - Display links to add new duties and officials if empty. Tweak -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found