Port shield-page callback page to the module from d7 to d8

  1. An Event Subscriber that will take care that whether to redirect the user based on the conditions.
  2. A page where user will be redirected to.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

naveenvalecha created an issue. See original summary.

naveenvalecha’s picture

alan-ps’s picture

Assigned: Unassigned » alan-ps

I will look at this.

alan-ps’s picture

Assigned: alan-ps » Unassigned

I think it can be closed as all necessary work for configuration entity was done in child issue. We need edit/delete management pages for shield page configurable, but there are another issues for this:
https://www.drupal.org/node/2780217
https://www.drupal.org/node/2780221

naveenvalecha’s picture

This is the default callback page where we redirect the user to if it does not have access. So this task needs two things
1. An Event Subscriber that will take care that whether to redirect the user based on the conditions.
2. A page where user will be redirected to.

Do you need more clarity on it. Feel free to reach on IRC : naveenvalecha

alan-ps’s picture

Assigned: Unassigned » alan-ps

Thanks for explanation. I will look at this!

naveenvalecha’s picture

Issue summary: View changes
alan-ps’s picture

Assigned: alan-ps » Unassigned
Status: Active » Needs review
FileSize
6.93 KB

This is a patch.

naveenvalecha’s picture

Status: Needs review » Needs work

Thanks for the efforts

  1. +++ b/src/EventSubscriber/ShieldPageSubscriber.php
    @@ -0,0 +1,59 @@
    +    if (\Drupal::currentUser()->hasPermission('bypass shield pages protection')) {
    

    Inject the Current user service here.

  2. +++ b/src/EventSubscriber/ShieldPageSubscriber.php
    @@ -0,0 +1,59 @@
    +    $shield_pages = \Drupal::entityQuery('shield_page')
    

    Same as bove. inject the service here.

  3. +++ b/src/EventSubscriber/ShieldPageSubscriber.php
    @@ -0,0 +1,59 @@
    +      ->condition('path', \Drupal::service('path.current')->getPath())
    

    same here, inject the service here.

  4. +++ b/src/EventSubscriber/ShieldPageSubscriber.php
    @@ -0,0 +1,59 @@
    +      if (isset($_SESSION['_shield_pages'][$shield_page])) {
    

    instead of $_SESSION, use the request object to get and set in the session.
    e.g.
    see here https://www.drupal.org/node/2380327

alan-ps’s picture

Assigned: Unassigned » alan-ps

I will look at this today.

alan-ps’s picture

Assigned: alan-ps » Unassigned
Status: Needs work » Needs review
FileSize
4.86 KB
8.88 KB

fixed

naveenvalecha’s picture

Status: Needs review » Needs work
FileSize
131.19 KB
401.22 KB

Setting it to N/W
I have tested it thorougly and its not working
Testing Steps :

  1. Enable the module.
  2. Go to the configuration page(admin/config/system/shield-pages/settings) and change the Shield page settings to per page settings See in screenshot below.
  3. Go to the Shield listing page(admin/config/system/shield-pages)
  4. Add a new shield page for node 1 See the configuration in atached screen below.
  5. Grant the permission 'Access password screen page' to anonymous user.
  6. Now access the node/1 page using anonymous user and boom! its accessible to the user.
alan-ps’s picture

Assigned: Unassigned » alan-ps
alan-ps’s picture

Assigned: alan-ps » Unassigned
Status: Needs work » Needs review
FileSize
12.2 KB
3.25 KB

I added additional path validation (path has to start with a slash) + field_prefix, which will help to fill field correctly.

alan-ps’s picture

Can we commit the patch above is all is fine?

naveenvalecha’s picture

Assigned: Unassigned » naveenvalecha

Added to my todo list