Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna created an issue. See original summary.

michaelpetri’s picture

It would be a honor :) Let me know when it's released so i can remove this helper module from my current project.

DamienMcKenna’s picture

Title: Merge into Metatag? » Allow each tag to have its own permission (merge Metatag Access)
Project: Metatag Access » Metatag
Version: » 8.x-1.x-dev
Component: Miscellaneous » User interface
Category: Task » Feature request
Issue tags: +Needs tests

Awesome, thank you!

I'm debating whether this should be a submodule or whether it should follow the D7 method of just having an advanced setting to enable / disable it..

We'll also need to add some tests.

michaelpetri’s picture

Can i write the tests? I have not yet written any tests for drupal modules, could be good exercise for me.

DamienMcKenna’s picture

Absolutely! The general idea for tests for this functionality would be to verify that each meta tag has its own permission, that it displays correctly on the permissions page, and works correctly (the fields are hidden/visible appropriately). Thanks!

DamienMcKenna’s picture

Status: Active » Needs review
FileSize
240 bytes

I renamed the module to something more specific (Metatag File Grained Permissions) and turned it into a patch, this way we have something to build from.

DamienMcKenna’s picture

Status: Needs review » Needs work

Back to needing tests.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
5.6 KB

I barfed the patch. This should be better.

DamienMcKenna’s picture

Status: Needs review » Needs work

Needs tests.

michaelpetri’s picture

Hi,

sorry for my long absence. We had a big relaunch in our company and there wasn't much free time for coding... :/

Anyway! I want to write this test asap. How to get startet?
Is this a good resource https://docs.acquia.com/article/lesson-102-unit-testing
Any additions?

Regards
Michael

michaelpetri’s picture

After a bit of research i'd write the test based on the WebTestBase Class.

I'd implement the following test scenarios:

  • Grant all or some permissions and check the node add form.
    => Expecting MetaTag Options available.
  • Revoke all permissions and check the node add form.
    => Expecting no MetaTag Options available.

In my setUp method i would:

  • Create a user
  • Create a node type

So far my plan, any additions?

Best regards
Michael

DamienMcKenna’s picture

Hey there, thanks for continuing to work on this.

Working off the node form should be enough, just add 'node' to the $modules list and create the content type during setUp().

I would suggest adding one test method that grants some permissions and then confirms which ones are enabled / disabled. You could then add another test method that gave the user the permission to create content but none of the meta tag permissions, just to see what happens for them. For bonus points X-) maybe add a test method to see if the global configuration is affected - ideally it shouldn't be, so maybe metatag_fine_grained_perms_field_widget_form_alter should be adjusted to also check the 'administer meta tags' permission?

Thanks!

michaelpetri’s picture

Thanks for your feedback i will start working on this after work. I will share my results asap.

DamienMcKenna’s picture

Status: Needs work » Postponed

Bumping this 'til after 1.0.

DamienMcKenna’s picture

Status: Postponed » Needs review

8.x-1.0 is out, so this is fair game again.

Rolf van de Krol’s picture

I found a few bugs in the code in the patch, so I fixed those. Attached is the new patch

  • The machine names of the permissions were based on the names of the tags, but the permissions were used with the key in list of definitions. I changed the internal names of the permissions to the keys of the definition.
  • In the form, all elements were handled, instead of only the elements that represent a group. Now, the form elements with intro and tokens are ignored by the form_alter funciton.
DamienMcKenna’s picture

Status: Needs review » Needs work

@Rolf: Excellent! I'll try to work on some tests for this soon, given the implications of this functionality I don't want to commit it without having some test coverage.

mvwensen’s picture

Current patch works great for me!

leonardpg’s picture

Has there been any movement to finish testing and roll this feature into the module? We're migrating to D8, and I would really like to limit the metatag fileds available to non-admins. Thanks!

TwiiK’s picture

Patch in #16 works great and does what I expected coming from Drupal 7. Without the ability to filter the available meta tags for clients I feel it's just too much noise to be usable. This sub module does what I need.

Not to mention that the original "administer meta tags" permission doesn't even distinguish between access to the meta tags settings form or just the ability to change meta tags on nodes.

Alex G’s picture

Not sure where this is in regards to getting tests run against it but patch definitely still works.

Would be good to get this committed after testing as it's a commonly needed feature for the module.

Not sure if DamienMcKenna will be able to assist with that?

DamienMcKenna’s picture

Initial test to make sure the site doesn't blow up after enabling the module.

Status: Needs review » Needs work

The last submitted patch, 22: metatag-n2782797-22.patch, failed testing. View results

neclimdul’s picture

Need to actually take a look at this but just got to say

+++ b/metatag_fine_grained_perms/tests/src/Functional/SiteStillWorks.php
@@ -0,0 +1,54 @@
+class SiteStillWorks extends BrowserTestBase {

<3

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
8.3 KB

I renamed the module "metatag_extended_perms" and renamed the base permission "access metatag" instead of "access metatag tag" to make it slightly less verbose, and I improved the documentation slightly.

Dave Reid’s picture

Another solution for filtering the list of visible meta tags: #3108108: Allow which metatags are visible on the field widget to be editable

mxr576’s picture

Because #25 introduces a new submodule I like this more than #3108108 which currenctly changes definition of existing services that is going to break deploys on dowstream projects. Although, I must admin the test in #25 is useless :)

DamienMcKenna’s picture

Rerolled, and added D9 compatibility.

DamienMcKenna’s picture

Assigned: Unassigned » DamienMcKenna

I'll work on some improved test coverage for this.

DamienMcKenna’s picture

I renamed and repurposed the test file to check for each of the main module's meta tags.

DamienMcKenna’s picture

This adds a check to make sure that user 1 can see all of the meta tags, even if the permissions don't allow it, and makes sure that a person with limited access can only see certain fields.

In short, this should be pretty perfect now.

DamienMcKenna’s picture

Oh, evidently some things were missed in the last patch, sorry about that.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. Thank you all, especially michaelpetri.

DamienMcKenna’s picture

Dakwamine’s picture

Hello! I have just stumbled upon this issue. I am looking for a solution for this use case: as a content editor, I want to see only meta tag fields which I have rights to edit them. By any chance, does this new module responds to this use case?

DamienMcKenna’s picture

@Dakwamine: Yes, it does.

Dakwamine’s picture

Thank you very much! I am feeling lucky today. :) Good job, everyone! 👏

Berdir’s picture

A bit late to the party, this is interesting, but the amount of of permissions this is going to add is going to be a deal-breaker for a lot of sites, including ours. Especially if you add modules like schema_metatag to the mix.

Couldn't this be opt-in like field_permissions has been for a while, where you can enable permissions per group or even tag and possibly also have it share the same permissions. It's quite a bit more complicated, but I think the majority of sites aren't going to need 100 permissions that they can each uniquely assign, they're going to have 1-3 sets/levels of metatags that they want to make accessible for their different user roles.

It also only partially addresses the performance aspect of this, as the hidden form elements still need to be processed by the form builder.

Some approaches I've seen introduce the concept of filtering definitions, then not having permission from them could already skip them from being instantiated and preparing the form. Of course yet another complication is that there might be values that need to be persisted even if the current user doesn't have access.

What we did in our project is to have a list of "restricted metatags" and all those are then behind a single permission check.

I'm fully aware that I'm late with that comment, now that it has been committed like this.

DamienMcKenna’s picture

I'm open to ideas for making this easier to handle, please feel free to open new issues and we can discuss them. And thank you, I appreciate the concern over not wanting to make things even harder for site admins.

  • DamienMcKenna committed 555054c on 8.x-1.x
    #2782797 by DamienMcKenna: Added missing $defaultTheme test variable.
    
Dakwamine’s picture

@Berdir In a nutshell, did you assign tags to a (dynamic/static?) permission (working on field level permissions?), and then, assign this permission to a role?

I have a little site with relatively few enabled options, so it did not occurred to me that this could become a hassle to administer... Good catch!

Berdir’s picture

We have one setting that's a list of restricted/hidden metatags and then a form alter that hides them, similar to what this module added.

Looks like this:

```
'foo_module.settings:restricted_metatags':
- basic.abstract
- advanced.geo_placename
- advanced.geo_position
- advanced.geo_region
- advanced.icbm
- advanced.robots.index
- advanced.robots.follow
- advanced.robots.noarchive
... (pretty long list)
```

Not sure what the best middleground between the this (which might not be flexible enough for some sites) and the permission-per-element would be. One thing to note is that our form alter can even go deeper than the plugin level, in the example above you can see that we're hiding all but two options of the robots checkboxes.

Status: Fixed » Closed (fixed)

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