How to redirect path for specified roles?

CommentFileSizeAuthor
#6 path_redirect_roles.patch7.23 KBneochief

Comments

dave reid’s picture

Status: Active » Postponed

Right now there's no conditional matching besides the path for redirections, so there's no possible way to redirect by roles. For now I'm going to leave as postponed as it would require a significant addition to the schema as well as the interface. Also, I'm not sure how useful others would find this feature as well, since this is the first time it's been requested. I'd like to sit on this for a bit and see if it gathers more interest.

Also marked #449126: Redirect by role? as a duplicate of this issue.

Trunkhorn’s picture

I like the idea of this since a lot of the access modules don't attack the issue for some generalized pages that I'd like to protect, and this is the only module to my knowledge with the potential to attack it at the path level.

Are their any other modules that do this already?

dave reid’s picture

@Trunkhorn: This wouldn't be an appropriate module for denying access to certain paths. I'll do a little research to see if I can find a better solution for you.

Trunkhorn’s picture

I agree with that completely and understand the intent of this module is to allow redirects in a standards-based way in respect to w3c, so I don't disagree with your decision not to mess with it for this module.

Unfortunately it's my only lead for path level access denial at the moment, so I would definitely appreciate hearing what you find.

SerenityNow’s picture

Hi-

I just wanted to weigh in and say that redirection by role would be very useful to me also. I see that you have said it's beyond the scope of your module, but I'd appreciate any guidance you could give with regard to the best way to achieve this.

For what it's worth, I think there would probably be quite a bit of interest in redirection by role - the use case for this is that you would want to redirect anonymous/unregistered users to a signup/registration page if they try to access certain paths.

click on a link to download a file -> redirect to registration page 'download_reg.html'
click on a thumbnail of an image that links to fullsize version -> redirect to registration page 'image_reg.html'
click on post comment button -> redirect to registration page 'comment_reg.html'
click on article in certain category -> redirect to registration page 'category_reg.html'

You get the idea - are there othe rmodules that can accomplish this type of functionality?

neochief’s picture

Status: Postponed » Needs review
StatusFileSize
new7.23 KB

Hello, guys. Here's a patch for 6.x to do that. Please review and mark "RTBC" if it works for you. For me it does.

gsemko’s picture

Status: Needs review » Reviewed & tested by the community

Works fine for me too

greggles’s picture

Just browsing the queue and saw this - it seems like the wrong solution in the wrong module to me. I suggest looking into true node access solutions.

dave reid’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

After consideration, I agree with greggles. I doubt that very many existing module users would find this functionality useful. Probably the easiest way to accomplish this would to implement a custom_url_rewrite_inbound() in your site's settings.php:

function custom_url_rewrite_inbound(&$path, $original_path, path_language) {
  if (preg_match('!comment/reply/\d+!', $path) {
    $path == 'comment_reg.html';
  }
  // etc...
}

If someone wants to put in a solution for a smaller module that allows this via extending path_redirect, go for it.

neochief’s picture

Hey Dave. I'd love to write a small module on top of Path Redirect, but obviously, it's not possible, as Path Redirect doesn't provide necessary hooks (in _path_redirect_check()).

As a result, it should be separate module, which duplicates administration interfaces of Path Redirect. But why we need to make a clone with only difference in conditions functionality? From my point of view, it worth to be in module. At least, we can thing about hooks in _path_redirect_check().

Trunkhorn’s picture

This is the only solution to attack this at a path level, and needs to be taken seriously. Arguments such as "I don't know that many will find it useful" are really over-assuming.

boftx’s picture

I have a situation where I need to display a single menu item, but send a user to different pages based on roles. This would seem to be the right module to use if it had the capability.

josjreyes’s picture

I really like the idea pitched by #5, especially the: click on a link to download a file -> redirect to registration page 'download_reg.html' .

Instead of the registration page, I'd like to see it redirect to the user login page. I've seen this functionality is widely employed by peer-reviewed journal websites. Personally, I would find this very useful.

bmango’s picture

I know that this thread is a little bit old now, but I had a similar need to redirect pages based on the user role. I didn't want anonymous users to access certain pages. In particular some views, which because of the content access permissions, were coming up blank, and I wanted to redirect them to the registration page. I found I could just put in a few lines of code at the top of my template file and this solved the problem. The code I used was:

<?php
	if (in_array('anonymous user', array_values($user->roles))) {
		$dest = $_SERVER['REQUEST_URI'];
		$dest = substr($dest,1); //this removes preceding slash from string
		$path[]='vote'; //example paths to hide from anonymous users...
		$path[]='volunteer';
		$path[]='papers-list';
		$path[]='event-register';
		$path[]='replays-list';
		$path[]='how-to-upgrade';
		$path[]='membership-renewal';
		if (in_array($dest, $path)) {
			return drupal_goto('members-only'); //this line re-directs to custom access denied page.
		}
	}
?>

There may be other ways to achieve the same thing, but this worked the best for me.

I also posted a solution for redirecting/preventing user downloads (#13 and mentioned in #5) at Filefield Download Permission.

marktheshark’s picture

My $0.02:

In most of my sites nodes are used for storing data, but views with fields are used for the actual presentation.

Search results may return nodes matching the search criteria, thus I would want to redirect the node link to e.g. a view.

However I don't want the redirect to also occur for user 1.

Any way to support this without enhancing this module to be role-aware?

Thank you

Seijun’s picture

I realize this thread is old, but I was wondering if the code in #14 would work with D7, and if it would be possible to implement using blocks?