When accessing a user's MySite page (e.g. /mysite/123/view) for the very first time I get a redirect loop. The loop is caused by mysite_page(123,TRUE) calling theme_mysite_create_help on line 622 which in turn calls mysite_page(0, FALSE) on line 2747. The latter results in a call to drupal_goto('mysite/'.$user->uid.'/view') on line 702, redirecting the browser to the very same page (/mysite/123/view).

I've attached a patch fixing this issue.

CommentFileSizeAuthor
mysite_2.patch496 bytessos4nt

Comments

agentrickard’s picture

I have a feeling that permission configuration causes this error, since I've never seen it before.

What permission settings do you have for the MySite access control? What role is user 123?

agentrickard’s picture

Status: Needs review » Postponed (maintainer needs more info)

I cannot replicate this error.

My suspicion is this problem occurs when someone other than the user tries to look at their MySite page before it has been created.

There must be something else going on here, because look at the existing code: (#comments are added for clarity)

 
  # we use the given UID to check for a MySite page
  $sql = 'SELECT uid, title, layout, style, format, status, theme FROM {mysite} WHERE uid = %d';
  $mysite = db_fetch_object(db_query($sql, $owner->uid));

  # by default, show data is Off
  // access control set by the user 'status' flag
  $show = FALSE;

  # If the user's ID matches the MySite owner's ID, run this check
  // if the user is looking at the MySite data
  if ($user->uid == $owner->uid) {
    $show = TRUE;
    if ($pageview) {
      // get any system messages waiting for this user
      mysite_message($owner->uid);

      // this user has no page, give them help making one
      if ($mysite->uid == 0) {
        $output = theme('mysite_create_help', $owner);
        # this return stops the function cold
        return $output;
      }
    } 
  }

  # I think this may be the problem.  If $user->uid != $owner->uid && can 'administer mysite' we try to render the page....
  # since the page doesn't exist, $mysite->status == 0 and other users will be denied.
  // access checks: can this user view this data?
  else if (user_access('administer mysite') || ($mysite->status == 1 && user_access('view all mysites'))) {
    $show = TRUE;
  }

It looks like this may occur IF you have 'administer mysite' permissions AND no page has been created yet, but I could not duplicate the error.

agentrickard’s picture

Title: Default view results in redirect loop » MySite view results in redirect loop

Title change: 'default view' means something else in the MySite context. It means the MySite user page to show at path 'mysite/default' (which is unrelated to this issue).

sos4nt’s picture

Priority: Critical » Minor

Thanks for your help. The user (role) didn't have permission to "view all mysites" and that caused the redirect loop. I changed the permissions and now everything is fine.

However, I think it would be better to show an access denied page if the user doesn't have permission to view his or her own MySite page.

agentrickard’s picture

I'm still a little confused by this behavior, and it probably needs to be corrected.

User 123 is looking at his/her own page: 'mysite/123/view'? And has the 'edit own mysite' permission but not 'view all mysites'?

sos4nt’s picture

That's right. User 123 with "edit mysite" permission and without "view all mysites" permissions gets this redirect loop when accessing mysite/123/view. This only happens as long as there's no MySite database entry for this user.

Everything works as expected when setting the "view all mysites" permission, i.e. default MySite page with "start by customizing the settings for your personal page" message.

agentrickard’s picture

Status: Postponed (maintainer needs more info) » Fixed

Confirmed and fixed in HEAD.

My fix is slightly different, as if requires two changes to IF statements.

Line 565:
if ($user->uid > 0 && user_access('edit mysite')) {

Line 628:
else if (user_access('administer mysite') || $mysite->uid == 0 || ($mysite->status == 1 && user_access('view all mysites'))) {

sos4nt’s picture

Great, thanks!

agentrickard’s picture

Status: Fixed » Closed (fixed)

Fixed in 5.x.2.3