Problem/Motivation

Currently, the verification form is always available, meaning anonymous users will always be able to create users with it. This may not always be desirable, so it would be good to make it permission based.

Additionally, logged in users always skip the verification form at present. Allowing this to be controlled by permissions would make the module more flexible.

Steps to reproduce

Create a verification form and log out. Navigate to the form and verify it is available. Next, log in and navigate to the verification, and observe the user is redirected to the form's destination.

Proposed resolution

Create two permissions "Access verification form _______" and "Skip verification form ______". A follow on task will limit access using them.

Remaining tasks

  1. Add a new class to the /src called VerifyEmailPermissions.
  2. Use the Drupal\Core\DependencyInjection\AutowireTrait in the class (I think this should work - if I'm wrong, a create function will be needed instead).
  3. Add a constructor to that takes a parameter of type Drupal\Core\Entity\EntityTypeManagerInterface and promotes to a property.
  4. Add a public method of the class called "permissions" that should do the following tasks:
    • Initialize permissions as an empty array.
    • Load the storage for verify_email.
    • Query the verify email entities, and for each one add two elements to the permission array, one with a key of "access verify $id" and a translatable value of "Access verification form $tag", and the second with a key of "skip verify $id" and a translatable value of "Skip verification form $tag".
    • Return the array of permissions.
  5. Add an entry to verify_email.services.yml, defined as the fully qualified class name. Autowiring will take care of the properties, but the definition will need the following tag:
      tags:
        - { name: 'user.permission_provider', method: 'createPermissions', provider: 'verify_email' }
    


    Add a permission_callbacks entry to verify_email.permissions.yml, specifying the path to the fully qualified class name and the permission function
  6. In the setup of test VerifyEmailSetupTest, add "administer permissions" to the permissions of the created user.
  7. In testVerifyEmailConfig, add a check after the form creation that loads the /admin/people/permissions page, and checks for the presence of "Access verification form Test verify email" and "Skip verification form Test verify email".

User interface changes

Only the new permissions on the permissions page.

API changes

None.

Data model changes

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

lostcarpark created an issue. See original summary.

nidhi27’s picture

Hii @lostcarpark,

As per https://www.drupal.org/node/3421580 change record changes are currently in draft state. May be we need to use permission_callback. Let me know your suggestion! Thanks!

lostcarpark’s picture

Issue summary: View changes

You're right, I jumped the gun on the service tag.

I have updated the Remaining tasks to specify permission_callbacks instead.

nidhi27’s picture

Assigned: Unassigned » nidhi27

nidhi27’s picture

Assigned: nidhi27 » Unassigned
Status: Active » Needs review

Hii @lostcarpark,

I have created MR !50 for this. Let me know if any changes are needed. Thanks!

lostcarpark’s picture

Status: Needs review » Needs work

This is almost perfect. The only minor issue is that when using AutowireTrait, you don't need a create() function. Autowiring generates one automatically. Just delete create() and we should be ready to merge.

Thanks!

ritarshi_chakraborty made their first commit to this issue’s fork.

ritarshi_chakraborty’s picture

Status: Needs work » Needs review

Hey @lostcarpark, please review the changes.

lostcarpark’s picture

Status: Needs review » Reviewed & tested by the community

Sorry, I missed one small thing on my previous review. The $entityTypeManager currently uses a separate declaration. In PHP 8 this can be replace by property promotion from the constructor.

lostcarpark’s picture

Status: Reviewed & tested by the community » Needs work

Accidentally selected RTBC before I noticed the property promotion issue.

lostcarpark’s picture

You are almost there, but you need to change the name of the constructor parameter from $entity_type_manager to the property name $entityTypeManager.

Thanks for your work on this @ritarshi_chakraborty.

lostcarpark’s picture

Ah, so close!
Just need to update the docblock comment with the new parameter name.

lostcarpark’s picture

Status: Needs work » Reviewed & tested by the community

I have reviewed the changes, and run the tests locally. I also ran the "test only changes" and verified it failed. I did some manual testing to verify the permissions are created for each verification form.

  • lostcarpark committed e426cbf4 on 1.1.x authored by nidhi27
    feat: #3556368 Create custom permissions per verification form
    
    By: @...
lostcarpark’s picture

Status: Reviewed & tested by the community » Fixed

Merged change and verified merge train passed successfully.

Moving to fixed and awarding contribution credit.

Thank you @nidhi27 and @ritarshi_chakraborty for working on this. I think it's a nice improvement to the module.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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