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

Additional logic in determing access level #122

Open
jasonpartyka opened this issue Nov 28, 2018 · 14 comments
Open

Additional logic in determing access level #122

jasonpartyka opened this issue Nov 28, 2018 · 14 comments

Comments

@jasonpartyka
Copy link

Problem

Sometimes the ability to update/create content that is controlled by a term needs to be restricted further. As an example:

  • A term representing group "A" exists, but due to business reasons new content may not be assigned to this group. The term cannot be removed as the association needs to be kept intact because of reporting, theme, et al. Let's call this the 'deprecated' group.
  • Content part of "group A" may still be updated, with the deprecated group intact. However, only users who are members of the deprecated group may update it. The content may still in group "A", but if ownership is changed, it must go to a group that is not deprecated.

Proposed Solution

In the generic case, provide a way that a developer can write additional logic to further restrict if access is denied.

There are two ways we could go about this, and both involve updating Drupal\workbench_access\Plugin\EntityReferenceSelection\TaxonomyHierarchySelection::getReferenceableEntities method to execute the chosen pattern.

  1. Create a service class to provide the logic. The developer then writes a service class do to provide the logic.
  2. Provide an 'empty method' (for lack of a better term) that be used in a Plugin class that inherits from TaxonomyHierarchySelection and then implements this method. This 'empty method' would simply always say access is allowed in the default implementation within TaxonomyHierarchySelection.

Other solutions

These other solutions have been considered and have their own drawbacks:

  1. Validate on save. This would preserve data integrity, but presents a sub-optimal user experience as the user may choose an option that is believed to be valid.
  2. Completely override Plugin w/o inheriting from class. This is possible, but requires keeping an eye on the copied class instead of leveraging OO patterns.

I will need to make this alteration for our own needs, so I'd like to do it in a sustainable way that could be incorporated back into the module.

@larowlan
Copy link
Collaborator

larowlan commented Nov 28, 2018 via email

@agentrickard
Copy link
Owner

agentrickard commented Nov 28, 2018

It's probably the plugin alter. Note that the class @jasonpartyka is mentioning here just controls the autocomplete selection of terms. We're really looking back a step at the alterForm() method for the plugin class.

Drupal\workbench_access\Plugin\AccessControlHierarchy\Taxonomy\AlterForm

@larowlan
Copy link
Collaborator

larowlan commented Nov 28, 2018 via email

@jasonpartyka
Copy link
Author

So, getReferenceableEntities is only used to determine autocomplete and is not called for form validation? If that's correct then the proposed solution is incomplete.

@larowlan
Copy link
Collaborator

larowlan commented Nov 29, 2018 via email

@jasonpartyka
Copy link
Author

Yeah, so then why not create a service so that the custom access logic is written just once? But, I don't see a validation plugin in workbench access either. Did I miss it? I'm looking at 8.x-1.0-beta2

@larowlan
Copy link
Collaborator

larowlan commented Nov 29, 2018 via email

@jasonpartyka
Copy link
Author

Gotcha. So I'm totally overthinking it then. :-)

@agentrickard
Copy link
Owner

All that said, I'm not certain that we handle Validation correctly via plugins -- unless @larowlan is saying that core already handles that for us.

This is an area of the code where changes from D7 to D8 have me a bit behind.

@larowlan
Copy link
Collaborator

larowlan commented Dec 3, 2018 via email

@agentrickard
Copy link
Owner

I believe we do in the case of the autocomplete -- because in that case we swap out the selection plugin in its entirety. I'm not entirely certain that the standard form alter that we do for other field types adds this validation step.

@jasonpartyka
Copy link
Author

So, I don't see any Validation plugins in in the src/Plugin directory. This would handle any widget used for term selection, correct?

@jasonpartyka
Copy link
Author

So -- I'm picking this issue up again. @agentrickard and @larowlan, do you believe there is any value in providing a generic solution?

@agentrickard
Copy link
Owner

Very probably, but I haven't given it much thought.

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

No branches or pull requests

3 participants