0

I want to allow anonymous user to access all the pages depending on a particular session set. These pages can be:

  1. Node - both published and unpublished
  2. Views pages
  3. Taxonomy terms
  4. custom hook menu urls etc I am able to handle node pages using hook_node_access. But is there any common hook and any other approach that allows me to grant access for all the pages. Also, for views if there is no permission for anonymous user, I should be able to grant permission depending on a session set.
10
  • No there’s no common hook for that, you’ll need to hook into each thing that you want to control access for separately. For entities you could override the access callback for every type, but views and custom pages aren’t entities. Or relax permissions if it can be done in a way that makes sense for your requirements
    – Clive
    Jan 25 '18 at 10:47
  • @Clive Relax permissions? What do you suggest for views and custom pages?
    – neha
    Jan 25 '18 at 10:58
  • Assign them a permission that anonymous users have. For example Access Content is available to anon users in most sites. I don’t know what a “session set” is so I’m making assumptions about your requirements
    – Clive
    Jan 25 '18 at 11:16
  • Requirement is : Even if view pages do not have permission for anonymous user, if there is a hash code/token in the url like ?hash=ABC then anonymous user should be able to browse the site anonymously and access all the pages (views pages, custom urls etc). If the user access the url with hash code I set a session like $_SESSION['xyz'] = 'token_value'. If this session is set i.e until user closes the browser user can access the pages.
    – neha
    Jan 25 '18 at 11:36
  • Oh right, no there's no easy way to do that. Off the top of my head, patching user_access would be the simplest method. But it ill be bad for performance; you'll have to make sure pages aren't cached for anonymous users, which is obviously not a good thing
    – Clive
    Jan 25 '18 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.