Hi,
I'm building a module that reformat (basically simplify the way) domain access options are presented to the user when editing a node.
Doing so, I had to delete 'domain_access' and 'node_access' tables, and rebuild node access rights.
I thinks the way rights were rebuilt is wrong. Let's explain why:

My config is as follows:
Domain DA has id 0 (it's primary domain).
Domain DB has id 2.
Content type CTA is set to be published by default for "all affiliates" (from admin/build/domain/advanced)
Content type CTB is set NOT to be published by default for "all affiliates"

So, when a new CTA node is edited, :
"all affiliates" and "current domain" are checked by default as domain publishing options.
After saving, domain_access table will show for nid=1234:
1234 0 domain_id
1234 0 domain_site
node_access table will show:
1234 0 domain_id 1 1 1
1234 0 domain_site 1 0 0

And when a new CTA node is edited :
"current domain" is checked by default as domain publishing options.
After saving, domain_access table will show for nid=1235:
1235 0 domain_id
node_access table will show:
1235 0 domain_id 1 1 1

This is the way it has to be, right?

The problem is that when rebuilding node access rights after emptying 'domain_access' and 'node_access' tables, behavior is different. I get for all nodes whether there are CTA or CTB:
domain_access table:
(nid) 0 domain_id
node_access table:
(nid) 0 domain_id 1 1 1

No domain_site realm at all!

How I fixed it in domain.module:
Line 1064, I replaced:
$node->domain_site = FALSE;
by:
unset($node->domain_site);

(if $node->domain_site is initialized here then domain_node_access_records won't work as expected)

Then:
Line 1215, I replaced:
$node->domains = array($_domain['domain_id'] => $_domain['domain_id']);
by:
$node->domains = array(-1 => -1);

(When rebuilding rights, $_domain['domain_id'] = 0 instead of -1, so domain_node_access_records doesn't work as expected. Setting -1 does the default behavior: access is granted on primary domain).

Doing so, everything works as expected.
For me it look like a bug, but maybe I'm missing something.
Let me know.

Comments

agentrickard’s picture

Title: Seems like incorrect behavior when rebuilding node access rights. Am I wrong? » Truncating {domain_access} breaks node access rebuild
Category: bug » support

Drupal can't rebuild node access rights correctly if the {domain_access} table is empty, because you have deleted all the stored information about what domain a node belongs to.

If you rebuild node access with no records in {domain_access}, it uses the default behavior. See sections 2.4 - 2.6 of README.txt.

This works correctly and follows the APIs.

If you want to alter this behavior, don't hack the module, use hook_domainrecords() and custom code. Note that -1 is used for domain_site throughout the module because the FormsAPI won't let you pass a 0 value, so anytime that data comes from a form, the -1 has to be converted to a zero.

Changing title. When you look at the new title, you will understand why your rebuild fails.

See http://api.drupal.org/api/group/node_access/6

If you want to batch re-assign existing nodes to complex rules, use Domain Content.

anrikun’s picture

But what happens when installing Domain module and nodes already exist?
Sorry to ask the questions. I should try by myself :-)

I still think that something would go wrong if rebuilding rights after installing Domain on a site with existing nodes
This part inside domain_node_access_records (see below) may not work as expected, for the reasons I wrote (please check my code) in my first post:

  if (!isset($node->domain_site)) {
    // We came from a separate source, so let's set the proper defaults.
    $node->domain_site = variable_get('domain_node_'. $node->type, variable_get('domain_behavior', DOMAIN_INSTALL_RULE));
    // And the currently active domain.
    $node->domains = array($_domain['domain_id'] => $_domain['domain_id']);
  }

But as I said before, I have to try before telling that!

agentrickard’s picture

Status: Active » Closed (works as designed)

Read the documentation cited above. You are asking for complex behavior that cannot be controlled on module installation. And your failure to understand that is really angering me.

anrikun’s picture

Sorry, I didn't mean to upset you.
I did read the documentation.
I just wanted to provide some feedback and maybe help to improve the module on installation.

agentrickard’s picture

Title: Truncating {domain_access} breaks node access rebuild » Allow complex rules on install
Category: support » feature
Status: Closed (works as designed) » Postponed

Considering that this is the first request for this in 2+ years, I would accept a patch. Othwerwise, you can implement the logic in hook_domainrecords() in a custom module.

A patch would need to include documentation.

Retitling and re-categorizing. I don't have time to work on this.

agentrickard’s picture

Status: Postponed » Closed (won't fix)