Problem/Motivation

Currently there is one permission that handles all access. It would be helpful if we could at least have two permissions. One for global settings and one for editing individual settings for entities.

We should also discuss how fine grained the permissions should be. F.E. we can have permissions generated with a permission callback for every entity enabled?

Proposed resolution

For now split up the global permission on two permissions. One for global settings and one for editing individual entity sitemap's settings.

Remaining tasks

Discuss if the provided patch is satisfactory or if we should create a fine grained permission solution.
Add new tests and/or change current tests depending on the decision.

User interface changes

New permissions will appear in the permissions overview.

API changes

None.

Data model changes

None.

Release notes snippet

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Stefdewa created an issue. See original summary.

stefdewa’s picture

Status: Active » Needs review
StatusFileSize
new1.29 KB
new42.21 KB

Provided patch splits up the global permission in two permissions. One for global settings and one for editing individual entities their sitemap settings. I'll set this to needs review but feel free to set this to needs work and discuss if this solution is acceptable.

kbeck303’s picture

I have tested the patch in comment #2 running Drupal 8.7.6

svdhout’s picture

I can confirm that the patch works on Drupal 8.8 wit simple_sitemap 8.3.5

manuel.adan’s picture

That's a basic support that works but it would be great to set permission per enabled entity type and bundle.

ndf’s picture

+++ b/simple_sitemap.permissions.yml
@@ -2,3 +2,8 @@ administer sitemap settings:
+administer individual sitemap settings:
+  title: 'Administer individual sitemap settings'

This machinename feels a bit off for me. Because when committed its difficult to change, I would prefer to improve this in the issue here.

In other content-management/edit permissions words like "any", "content"/"nodes" and "override" are used.

@seanB came up with administer entity sitemap settings

+++ b/src/Form/FormHelper.php
@@ -194,7 +194,11 @@ class FormHelper {
+    if ($this->getEntityTypeId() === NULL && !$this->currentUser->hasPermission('administer sitemap settings')) {
+      return FALSE;
+    }
+
+    elseif ($this->getEntityTypeId() !== NULL && !$this->currentUser->hasPermission('administer individual sitemap settings')) {

Is this correct? Does this work with either one of the permissions, or does a user needs both permissions. (i will doublecheck manually).

#5
That's a basic support that works but it would be great to set permission per enabled entity type and bundle.

@5 That would be great, but I am fine with doing more granular permission in a follow-up.
Then this issue could only be

provide permission for editing individual settings for entities.
ndf’s picture

Changed the new permission name to edit entity sitemap settings
And fixed a logic error where one could not access the edit-form without the new permission.
Permissions behavior in new patch:
- When on entity-edit form; one must have either 'Administer sitemap settings' or 'Edit entity sitemap settings'
- Otherwise one must have 'Administer sitemap settings'

Status: Needs review » Needs work

The last submitted patch, 7: simple_sitemap-split_up_permission-3033792-7-D8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ndf’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB
new1.3 KB

It's 30 degrees here in Amsterdam and the if-then-conditionals made my mind spin

ndf’s picture

StatusFileSize
new1.7 KB
new1.29 KB
ndf’s picture

StatusFileSize
new1.7 KB
new1.29 KB
seanb’s picture

+++ b/src/Form/FormHelper.php
@@ -205,7 +205,11 @@ class FormHelper {
+    elseif ($this->getEntityTypeId() !== NULL && (!$this->currentUser->hasPermission('edit entity sitemap settings') && !$this->currentUser->hasPermission('administer sitemap settings'))) {

This is kind of hard to read. Maybe we should put things in variables?

$is_entity = $this->getEntityTypeId() === NULL;
$is_admin = $this->currentUser->hasPermission('administer sitemap settings');
$can_edit_entity = $this->currentUser->hasPermission('edit entity sitemap settings');
ndf’s picture

Version: 8.x-3.x-dev » 4.x-dev
Status: Needs review » Active

ndf’s picture

Status: Active » Needs review
mrshowerman’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

I can apply the patch from the MR on 4.1.1 nicely and it seems to do what is desired. But in 4.1.2, the patch no longer applies.

immaculatexavier’s picture

Assigned: Unassigned » immaculatexavier
immaculatexavier’s picture

Assigned: immaculatexavier » Unassigned
mrshowerman’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

Should work with 4.1.2 now.

Andreas Hansson’s picture

deleted

Andreas Hansson’s picture

StatusFileSize
new2.47 KB

Made a patch for the same issue before we found out that this issue already existed.

Patch #20-2 is not built on #11, and also it will not enable the option to regenerate the sitemap when saving a node if you are not administrator.

Patch #20-2 is from current -dev branch, seems #11 wont apply anymore.

Status: Needs review » Needs work
joshahubbers’s picture

Patch-file of #19, because .diff can change if more changes are pushed to the mr.

joshahubbers’s picture

caspervoogt’s picture

Status: Needs work » Needs review

Thanks everyone for the work on this important change to this module. I tested the patch from #24 and it worked for me, on PHP 8.1 / Drupal 9.5.8 / simple_sitemap 4.1.4. Looks good to me. This was marked 'needs work' but it doesn't look like it needs work. I changed it to 'Needs review' but if I am wrong please feel free to set it back to 'needs work'. RTBC in my book.

joncjordan’s picture

Note that the patch will cause fatal errors with the simple_sitemap_engines module, since Drupal\simple_sitemap_engines\Form\FormHelper extends Drupal\simple_sitemap\Form\FormHelper.

Fatal error: Declaration of Drupal\simple_sitemap_engines\Form\FormHelper::formAlterAccess(): bool must be compatible with Drupal\simple_sitemap\Form\FormHelper::formAlterAccess(Drupal\Core\Entity\EntityFormInterface $form_object): bool in /app/web/modules/contrib/simple_sitemap/modules/simple_sitemap_engines/src/Form/FormHelper.php on line 63

johan_vm’s picture

StatusFileSize
new2.88 KB

I couldn't apply the MR 38 patch to I checked out the branch locally and merged 4.2.1 and made a diff.

This patch should work for 4.2.1

stefdewa’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Barcelona2024

Reviewed MR38, tested manually and it works!

  • walkingdexter authored b36e1da2 on 4.x
    Issue #3033792 by ndf, mrshowerman, Andreas Hansson, stefdewa,...

walkingdexter’s picture

Status: Reviewed & tested by the community » Fixed

Simplified and committed, thanks! Thoughts from #21 are respected. Credits saved for the guys from #3441488: New permission to only edit entity sitemap settings .

Status: Fixed » Closed (fixed)

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