Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions for the Contact module shown on /admin/config/people/permissions do not match the permissions shown on /admin/structure/contact/settings #6117

Closed
kiamlaluno opened this issue May 16, 2023 · 6 comments · Fixed by backdrop/backdrop#4472

Comments

@kiamlaluno
Copy link
Member

/admin/config/people/permissions allows to change the permissions each roles have, including the permissions for the Contact module.

screenshot

On /admin/structure/contact/settings, there is a Permissions fieldset that allows to change the Contact module's permissions each role has.

screenshot

The permissions shown in those pages do not match: On /admin/config/people/permissions, the Administrator role does not have the Use the site-wide contact form, which I expressly removed, while on /admin/structure/contact/settings, that permission is still given after I removed it from /admin/config/people/permissions.

Steps to reproduce

  • Install the Contact form
  • Visit /admin/config/people/permissions
  • Deselect the checkbox shown for Use the site-wide contact form for the Administrator role
  • Click on Save permissions
  • Visit /admin/structure/contact/settings
  • Check which checkboxes are selected

Expected behavior

Since the permissions for the Contact module have been changed on /admin/config/people/permissions, the change should be reflected on /admin/structure/contact/settings.

@olafgrabienski
Copy link

Confirmed on a vanilla demo site:

Contact module permissions changed at admin/config/people/permissions are not reflected on admin/structure/contact/settings.

(But permissions changed at admin/structure/contact/settings are reflected on admin/config/people/permissions.)

@kiamlaluno
Copy link
Member Author

kiamlaluno commented Jul 11, 2023

I found out what is causing this issue. user_admin_permissions() uses the following code.

foreach ($roles as $role_name => $role) {
  // Build arrays for checked boxes for each role.
  if (in_array($perm, $role->permissions)) {
    $status[$role_name][] = $perm;
  }
}

It shows a selected checkbox only when the permission has been assigned to the role.

contact_form_permissions() uses the following code.

foreach ($roles as $role_name => $role) {
  // Builds arrays for checked boxes for each role. Always select the Admin
  // role on new forms.
  if (in_array($perm, $role->permissions) || ($role->name == $admin_role)) {
    $status[$role_name][] = $perm;
  }
}

It shows a selected checkbox for the admin role, even when it does not have that permission.

@indigoxela
Copy link
Member

I can also confirm the problem (hardly ever use the Contact module).

Seems like that code got copied over from Taxonomy, but that special handling for admin role is only needed for vocabs, where each one has its own set of permissions. And only when a new one gets created.
The whole situation with contact forms is different.

And I can confirm, that the PR fixes it properly. 👍 Many thanks @kiamlaluno for finding and filing a PR.

@kiamlaluno
Copy link
Member Author

That explains why the comment said Always select the Admin role on new forms.

@bugfolder
Copy link

Code reviewed, LGTM.

@quicksketch
Copy link
Member

Thanks @kiamlaluno, @olafgrabienski, @indigoxela, and @bugfolder! I merged backdrop/backdrop#4472 into 1.x and 1.26.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants