I am looking for a way to assign domain access to a user after he has updated a node.

This should work exactly like "rules_action_set_node_domain - Set domain to a node".
But instead of "Set domain to a node" it must "Set domain to a user"
And the user is the user id (node author) of the node created.

Why I need this feature. Well if you user node reference and want to enable the user to publish his referenced content to the same domains as his parent node, there is no way to do it.

Here is an example: Lets say you have a content type gallery, and you have a node reference field that reference image content types. Now you create a Gallery called Birds, with some arguments (rules_action_set_node_domain) it publish the node to birds.com. Now you create a image node that reference to your birds node, but you can not select to publish this content to birds.com

You need to give the user permanent access to birds.com in his user account when he created the gallery node, in this way he can select if he want to publish referenced image nodes to birds.com or not.

"rules_action_set_user_defaults_domain - set a given role access to a given domain" Is not what I want, I want user access to a given domain

Any Help Please

Comments

vlooivlerke’s picture

Here is my first try but I must be doing someting wrong. I need it to insert the new domain_id with the node uid in the domain_editor table.

domain_rules.rules.inc line 41 ...function domain_rules_action_info() {

    'rules_action_set_user_domain' => array(
      'label' => t('Set domain to a node user'),
      'module' => 'Domain',
      'arguments' => array(
        'node' => array(
          'type' => 'node',
          'label' => t('Content'),
        ),
      ),
      'eval input' => array('subdomain'),
    ),

Line 159

function rules_action_set_user_domain($node, $settings) {
    
    $domain = domain_lookup(NULL, $settings['subdomain'], TRUE);

    if ($domain['domain_id']) {
        $node->domains[$domain['domain_id']] = $domain['domain_id'];
    	$domain_id = $domain['domain_id'];
        $uid->node['uid']; 
    
      db_query("INSERT INTO {domain_editor} (domain_id, uid, settings, status) VALUES (%d, '%s', %b, 1)", $domain_id, $uid, $settings);
    }
    else {
      db_query("UPDATE {domain_editor} SET status = 1 WHERE domain_id = %d AND uid = '%s'", $domain_id, $uid);
    }

    // Clear the cache.
    cache_clear_all();
  }

I know the problem is in this top part of the code, I dont know exactly how to insert into a database properly and i dont know how to get the correct uid from the current node.

domain_rules.rules_forms.inc line 88

function rules_action_set_user_domain_form($settings = array(), &$form) {

  $form['settings']['subdomain'] = array(
    '#type' => 'textfield',
    '#title' => t('Domain address'),
    '#default_value' => $settings['subdomain'],
    '#description' => t("The domain address"),
  );
}

Hope this help to get this on the roll.

shushu’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Component: Documentation » Code
Assigned: Unassigned » shushu
Status: Active » Fixed

Hi @vlooivlerke, thanks for the offer of the new feature.
I implemented it in the 6.x dev branch, and it seems to work as you requested.
I try to avoid any direct db queries, hence my solution is a bit different.
Please try out the new version (should be in http://drupal.org/node/1660478 in couple of hours), and let me know if it works for you.

Regards,
Shushu

vlooivlerke’s picture

Thanks @Shushu

It works perfect for me :)

edit: must say it is very well done, thanks again.

shushu’s picture

No problem. I will try to release a "final" version in few days, including 7.x version.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

roeneman’s picture

Subscribing, I hope you will get around to the 7.x version shortly. Would be great. Thanks!

shushu’s picture

Version: 6.x-1.x-dev » 7.x-1.1

Done, hopefully works as expected on D7 as well.
Please try the latest 7.x-1.1
And please notify in case of a problem
Regards,
Shushu

roeneman’s picture

The D7 version works at my system! Great, thanks shushu.

This option is probably very usefull for all cases where users are created by/through Rules, while running Domain Access. Without setting a domain for a user such user is of no much use, in my experience.

One hint when starting to use this: The 'set domain to a user' option takes url's as addresses but without the protocol (like: example.com and so without the http:// /). Therefore replacement [site:url-brief] works (note the 'brief' part).

Cheers.

tparc’s picture

Issue summary: View changes

The above comment should be documented somewhere besides here...just saying. At least I haven't seen it anywhere else.