After editing nodes user is redirected to the main domain

NeuZeitgeist - February 28, 2008 - 14:18
Project:Domain Access
Version:6.x-2.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:patch (to be ported)
Description

When user edites his own node on his own domain (http://user.mysite.com) after editing he is automaticaly redirected to the main domain http://mysite.com
How should I configure Domain access module so that user stays on his own domain http://user.mysite.com?
Thank you

#1

agentrickard - February 28, 2008 - 14:53

Try turning off the "New content settings:" under Admin > Build > Domain

New content settings:
[ ]  Show on all affiliate sites
[x] Only show on selected sites
If set, this value will automatically assign new content to all sites.

If that doesn't work, give the users the 'view domain publishing' permission and set the following:

Content editing forms: *
[ ]  Pass the default form values as hidden fields
[ ]  Take user to the default domain
[x] Take user to their assigned domain
[ ]  Show user their publishing options

If _that_ doesn't work, please send me a real url where I can test this.

(Oh, and please use example.com -- that's what it is for.)

#2

agentrickard - February 28, 2008 - 15:39

To be clear. This happens when:

-- The node is assigned to more than one domain.
-- SEO optimization is turned on.

What happens is that the user is redirected to the first domain match. This happens after the node is submitted.

When the Domain Source module is working correctly (see http://drupal.org/node/227003), this problem should fix itself, as the "source" domain for the link should be set to the user's domain.

It might also be possible to force this behavior, by setting a #redirect via hook_form_alter.

#3

agentrickard - February 28, 2008 - 16:07

You might try adding this code to domain_form_alter

<?php
   
// Some options will be passed as hidden values, we need to run some checks on those.
   
if ($form['#node']->nid) {
     
$raw = $form['#node']->domains;
    } 
    else {
     
$raw = $default;
    }

   
// New code here -->
   
if ($form['#node']->nid) {
     
$form['#redirect'] = substr(domain_get_uri($_domain), 0, -5); 
    }
  
// end new code.

  
$options = array();
?>

#4

NeuZeitgeist - February 28, 2008 - 17:51

I'm lost in this module that is why I created new topic here http://drupal.org/node/228055 where I explane my tasks.
Thank you for your reponses.

#5

torgosPizza - February 28, 2008 - 18:08

That snippet of code worked for me, FYI - I am no longer redirected to the main site after creating a node on a subdomain.

#6

agentrickard - March 2, 2008 - 00:16
Status:active» needs review

Does it work in all cases and should it be added to the main module?

Testing needed.

#7

NeuZeitgeist - March 2, 2008 - 14:27

I added this code to domain.module in line 1125 and so on but it didn't work for me.
For torgosPizza. Could you explaine how did you add the code and what configuration of Domain access you had.

#8

torgosPizza - March 2, 2008 - 21:46

I just added it as agentrickard shows here. Although I only found one spot to add it to, perhaps there are others I missed. Either way it appears that I can create content on sub.example.com and it directs me to sub.example.com instead of www.example.com (which is the default domain).

#9

agentrickard - March 12, 2008 - 00:58
Status:needs review» needs work

For the moment, I'm calling this behavior "by design." Though that is debatable.

What happens is that the form submission sends the user to the first matching "source" domain. The correct use of Domain Source should eliminate this issue.

I am keeping this open, but it will not be part of the 5.x.1.1 release unless more testing is done.

#10

gcassie - June 11, 2008 - 15:58

I'm having a similar problem, but it is at node creation instead. Users are being kicked back to the primary domain, and they seldom have rights to view their newly-created content on this domain. I am using SEO, and that's what's weird: the action on the forms is the absolute URL with the correct subdomain. Previews remain on the correct subdomain, and so do comments, but node creation boots back to root.

Any thoughts? I am going to keep investigating. I tried the above patch, but it didn't help, I think because at node creation we don't have a nid yet so it gets bypassed?

#11

agentrickard - June 11, 2008 - 18:30

And that is for a node assigned to 'all domains', right?

#12

gcassie - June 11, 2008 - 18:49

Nope, only assigned to the current, active domain. I thought it might be tied to the OG integration somehow, but I've tested it with content types that aren't in the "audience targeting system", and it happens there too.

Can devel track all the hook_nodeapi hoops a node jumps through on its way to being created?

#13

agentrickard - June 11, 2008 - 20:10

no, but it can report all redirects that you are given

#14

gcassie - June 11, 2008 - 22:25

Okay, enabling that I can see this is happening for other forms, not just node creation. If I go to http://sub.example.com/admin/settings/devel, I can see that is also the form action. Then somewhere along the line after submission, a drupal_goto is fired that brings me back to http://example.com/admin/settings/devel.

It still isn't happening with edits or comments. That is, those go to the correct subdomain still.

I checked with devel_forminspect to see if they were getting a #redirect property and they don't seem to be.

Also I've just noticed it stops happening if I turn off SEO.

#15

gcassie - June 11, 2008 - 23:00

It appears the forms that don't redirect to the root domain are the ones where drupal_redirect_form() gets called during their submission.

#16

agentrickard - June 11, 2008 - 23:07

Sounds like you are very close to an actual solution.

#17

gcassie - June 12, 2008 - 03:52

This change makes content published to all domains default to being shown on the current domain instead of the root, which I rather like for my uses. It also mean the admin forms stay on the current domain.

<?php
           
//$base_url = rtrim($root['path'], '/');
           
$base_url = $_domain['scheme'] . '://' . $_domain['subdomain'];
?>

Node creation is tied to this line in settings_custom_url.inc somehow:

<?php
            $base_url
= rtrim($domain[$nid]['path'], '/');
?>

That is also tied to node viewing though; changing it like the one above makes all content links write to the current domain, even if the user doesn't have view rights there. So I need to look into a way of detecting if we're coming in from the node creation form here.

#18

gcassie - June 12, 2008 - 14:13

Here we go. With this modification to settings_custom_url.ing, users are staying on the current domain after node creation now, and admin forms also stay on the current domain. It seems to have the side effect of forcing many more links to the current domain while in the admin screens, but since the admins on my site have rights to view everything everywhere, I don't foresee this being a problem.

<?php
         
if ($domain[$nid] != -1 && $domain[$nid]['domain_id'] != $_domain['domain_id']) {
           
$absolute = TRUE;
           
// In this case, the $base_url cannot have a trailing slash
           
$referer = explode('/', referer_uri());
            if (
arg(0) == 'node' && arg(1) == 'add')
             
$base_url = $_domain['scheme'] . '://' . $_domain['subdomain'];
            else
             
$base_url = rtrim($domain[$nid]['path'], '/');
          }
        }
       
// If strict SEO rules are enabled, we set "all affiliate" links to the root domain.
        // Only needed if we are not on the root domain.
       
else if ($seo && $_domain['domain_id'] != $root['domain_id']) {
         
$absolute = TRUE;
           
// In this case, the $base_url cannot have a trailing slash
           
if (arg(0) == 'admin')
             
$base_url = $_domain['scheme'] . '://' . $_domain['subdomain'];
            else
             
$base_url = rtrim($root['path'], '/');
        }
?>

#19

agentrickard - June 12, 2008 - 14:39

I wonder how this relates to the patch in http://drupal.org/node/268779 -- though that would have to be backported to the 5 branch.

I think this line:

            if (arg(0) == 'node' && arg(1) == 'add')

Might also need to apply to edits, and such.

            if (arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))

#20

gcassie - June 12, 2008 - 15:21

I'll review that issue, thank you.

It's weird, but node edits don't have this issue. Neither do comments.

#21

agentrickard - June 12, 2008 - 16:02

What does devel tell you about redirects?

#22

agentrickard - June 24, 2008 - 20:07
Assigned to:NeuZeitgeist» Anonymous
Status:needs work» needs review

I actually think we can fix this in hook_form_alter(), at least for Drupal 5.

See attached.

AttachmentSize
domain_redirect.patch 715 bytes

#23

agentrickard - June 24, 2008 - 20:14

The last patch does not account for node/add. Neither does this one.

AttachmentSize
domain_redirect.patch 745 bytes

#24

gcassie - July 2, 2008 - 23:51

Sorry, I was on vacation. I will try these out and report back. Thanks very much.

#25

coldice4678 - September 6, 2008 - 18:02

I am using DA for 6.4 and I had the same problem arise and it happened when my created role ("siteowner") had the "view domain publishing" ticked which I am still confused why that redirect problem happen. But for me it was as simple as unticking it.

#26

SwoopNStash - March 14, 2009 - 22:00
Version:5.x-1.0» 6.x-2.0-rc6

I am having the same problem in 6.x-2.0-rc6. I do not have SEO installed. View Domain Publishing is not ticked. Was the patch in #23 incorporated into version 6? Is there some other solution to this?

#27

agentrickard - March 16, 2009 - 00:25

There is not. We are still looking for the best-case solution.

#28

agentrickard - March 23, 2009 - 15:54
Category:support request» bug report
Status:needs review» postponed (maintainer needs more info)

I just tried to replicate this issue in HEAD and could not.

Can someone document steps for duplicating this issue in HEAD or rc6?

#29

RAFA3L - April 12, 2009 - 05:31

I have same problem here when a user create a new node in his subdomain, the form redirect to the main domain with an Access denied message. Each user domain must create only his own nodes and keep in his subdomain.

#30

agentrickard - April 12, 2009 - 19:08

I will try to replicate.

#31

agentrickard - April 12, 2009 - 21:06
Status:postponed (maintainer needs more info)» needs review

I could only replicate this error if the node was assigned to 'all affiliates', which should not throw an access denied.

There does not seem to be any way to stop this behavior, since node_form_submit() explicitly sets the redirect value.

It seems that you can prevent this behavior by setting DA's 'Default source domain' setting to 'Do not change domain'.

The attached patch also seems to work, but needs testing to make sure it doesn't cause any unusual errors.

AttachmentSize
227947-post-node.patch 1.09 KB

#32

RAFA3L - April 13, 2009 - 04:43

Hello agentrickard,

The patch didn't work.

This is my configuration:

Drupal 6.10 with only the modules Domain Access rc6 and Views active. I test it with the HEAD version too.

My user have:

Domain access settings:
[] domain.com
[x] user.domain.com

Roles:
[] authenticated user
[x] editor

// ------------------------------------------------

New content settings:
[ ] Show on all affiliate sites
[x] Only show on selected sites

Content editing forms:
[ ] Pass the default form values as hidden fields
[ ] Take user to the default domain
[x] Take user to their assigned domain
[ ] Show user their publishing options

Default source domain:
Do not change domain <----- If I change it to any other option nothing happend. Ever redirect to the main domain.

// ------------------------------------------------

In node settings/Domain node types: unchecked all

In node settings/Domain node editing: unchecked all

In permissions I have only checked this under my editor role:

delete domain nodes
edit domain nodes
set domain access

// ------------------------------------------------

Notice that the snipped in #3 fix the problem only when edit a node

// ------------------------------------------------

The idea of my site is to have a group of users (role) with his own subdomains, where each one only can create nodes under his domain. All work fine exept that after create one is redirected to the main domain with the Access denied error.

I hope this information is useful

#33

RAFA3L - April 13, 2009 - 05:12

I found the problem!!

I did a fresh install of Drupal and Domain Access and in the process I notice that in some moment I set $base_url to "http://www.mydomain.com" this is the cause of the redirect!

#34

agentrickard - April 13, 2009 - 13:56

OK. #32 and #33 are not directly related to this issue, then.

#35

mrgoltra - May 27, 2009 - 00:11

subscribing..

#36

agentrickard - June 28, 2009 - 16:16

This is not going in unless it gets tested. This is a very minor error that happens in rare cases.

#37

scottrigby - August 4, 2009 - 19:51

@agentrickard: I'm experiencing the same issue using DA 6.x-1.2

I've tried the suggestions per #30
✓ select 'Only show on selected sites' under 'New content settings'
✓ make sure user's role has 'view domain publishing' permission
✓ select 'Take user to their assigned domain' under 'Content editing forms'
✓ set DA's 'Default source domain' setting to 'Do not change domain'.
✓ make sure settings.php did not set a $base_url

But i still get the same results - after creating a node published to the secondary domain, the user is redirected to the primary domain.

I'll be happy to try the patch in #31, but - is do the changes in this patch necessarily need to apply to the 2.x version? I ask because 1.x is stable while 2.x is still RC, and we're experiencing this problem on a fairly large, live site. We could upgrade to 2.x, but I want to ask your advice about this first.

#38

agentrickard - August 4, 2009 - 20:44

6.x.2 is stable enough for production.

#39

ezraw - August 6, 2009 - 20:45

Following up on #37. I am working on the same site with scottrigby:

* We have two domains.
* We are publishing the node to the first domain.
* After node creation the user is redirected to the second domain.
* The user receives an access denied message because the node isn't published to the second domain.

We solved this by turning off the SEO optimization option.

It seems like the SEO optimization option for Domain Access creates a canonical URL for the node based on the primary domain and redirects to that (agentrickard - is that the case?).

#40

agentrickard - August 6, 2009 - 21:38

In most cases, yes, if the node is assigned to All Affiliates and the default domain. Otherwise it goes to the first match.

Does that patch in #31 do anything?

#41

agentrickard - October 24, 2009 - 20:18

OK, this is not going in to the 6.x.2.0 release.

#42

agentrickard - October 24, 2009 - 20:18
Status:needs review» postponed (maintainer needs more info)

#43

agentrickard - October 24, 2009 - 21:34
Status:postponed (maintainer needs more info)» needs review

Here is one more try at a patch. Reviews? Please?

AttachmentSize
227947-redirect.patch 3.18 KB

#44

agentrickard - October 24, 2009 - 22:15

Better patch, without a logic error and a simpler return.

AttachmentSize
227947-redirect.patch 3.22 KB

#45

agentrickard - October 31, 2009 - 18:16
Version:6.x-2.0-rc6» 6.x-2.x-dev
Status:needs review» patch (to be ported)

Final version, committed to HEAD.

AttachmentSize
227947-redirect.patch 3.86 KB

#46

scottrigby - October 31, 2009 - 18:31

@agentrickard: hi and thanks for all of this work - ezraw & I would have loved to test this on the site we experienced issues with except we're currently not in a position to do that - we'll keep this issue on our radar and give feedback when we can :)

#47

agentrickard - October 31, 2009 - 18:40

This should work just fine. It sets a $_SESSION token and uses that to read the proper redirect.

 
 

Drupal is a registered trademark of Dries Buytaert.