1

I'm using Drupal 7.43 and I have to create a special user, with access to a single page (a Views page) and nothing else.

What would be the best approach for this situation?

Note: The view is already made (I show a custom content type made in a custom module). The website is private (the only thing an anonymous user can see is the login page).

2
  • You must provide more information about the setup. Which Drupal version are you using? What do you want to show in that View (nodes, users or some other entities)? Does the website need to have some publicly accessible pages, or is it completely private? I can provide you with some suggestions, but would need to know these things first. Feb 26, 2016 at 17:25
  • I'm using drupal 7 (7.43). The view is already made (I show a custom content type made in a custom module). The website is private (the only thing an anonymous user can see is the login page). Thanks for the help! Feb 29, 2016 at 12:43

1 Answer 1

1

Not sure if it is the "best" approach, but for sure a "possible" approach for this would be to use the Rules module for this. All you'd have to do is to create a (rather basic) rule like so:

  • Rules Event: Drupal is initializing.
  • Rules Conditions (both must be true):

    • Check if the user's Id (uid) or user's name matches your "special user".
    • If the URL being accessed (= "site:current-page:url") does NOT match with the URL of your "single (Views) page"
  • Rules Action: Perform a redirect to your "single (Views) page".

Done ...

Happy Rules-ing!

Note: Obviously, this rule only takes care of what that special user is allowed to use as URLs (while logged in). If that user does not login (yet) or logs out again, then anything an anonymous user is allowed to navigate to will also be available to this not-yet-logged-in-user. For whatever that is not allowed as an anonymous user, you must ensure that the permissions for anonymous users are set to deny such access.

3
  • Thanks for the approach. Because the View I want to show has exposed filters, I had to make a little change to your answer: I made the second condition to be 'custom PHP code' and checked arg(0) to be the url of the View. Feb 29, 2016 at 13:59
  • Hm, interesting, and merci for accept. I imagine the "custom PHP code" is only a few lines at max? If you're willing to share it via an extra comment here, I'd be happy to further massage that also in my answer. Feb 29, 2016 at 14:03
  • Yes, it's just a return statement. return arg(0) == 'theURL'; The condition is denied, so that when the URL is NOT the one I want, it returns true, and the user is redirected. Feb 29, 2016 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.