When I edit a node and check "Private" it isnt checked the next time I edit the node. But something is happening though - when I edited a node which wasnt created by my user and checked "Private" I didn't have permission to view the node after that.

Comments

MGN’s picture

This sounds like a duplicate of #360460: rebuilding permissions makes private coherent_access nodes public. My recommendation would be to try the 6.x-1.x-dev version and apply the patches #360460: rebuilding permissions makes private coherent_access nodes public and #360651: Shared posts tab not showing on user account.

This is working well for me...hopefully these patches will be committed soon.

jseffel’s picture

Tried dev-1.x and the patches. No change.

If I check "If checked new nodes will default to private." it almost works. This is the flow in hook_nodeapi for coherent_access:

case 'load':
Pick up the gids (4 of them, mode 0,1,3,7) /* what are the modes? */
rows = Select * from node_access where realm = coherent_access and gid = mode0-gid /* This returns 0-rows if the node is set to private -> private won't be checked unless it is set to be private by default */
if(rows > 0) {
see if it is private
}
else {
use default
}

jseffel’s picture

StatusFileSize
new759 bytes

Found the problem:

Removing -
$grants[] = array(
'realm' => 'coherent_access',
'gid' => $gids[0],
'grant_view' => FALSE,
'grant_update' => FALSE,
'grant_delete' => FALSE,
'priority' => 0,
);

from line 560 fixes the problem.

jseffel’s picture

StatusFileSize
new874 bytes

Ignore patch above...

MGN’s picture

Let me try to restate the problem to make sure it can easily be confirmed. Configure coherent_access so new coherent_access posts are not private by default. Create a new post controlled by coherent access. Edit it, marking it private, has no effect - the post is still public and the checkbox is unchecked when the node is edited.

However, if initially configured so that posts are private by default, coherent access works fine. I can set the post public and/or private on subsequent edits and it works as expected.

The first patch by jseffel doesn't seem to fit the logical flow of the current hook_nodeapi function, glad to see its been dropped.

@jseffel, I don't understand what the second patch is supposed to accomplish, can you explain?

MGN’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Priority: Normal » Critical
Status: Active » Needs review
StatusFileSize
new925 bytes

Ok. I think I see what @jseffel is getting at... The code logic incorrectly assumes that node access grants can be used to deny access, when in fact it only grants access.

    // shared_editing comes in via the form, coherent_access is via hook_node_api op='load'
    if ((isset($node->shared_editing['private']) && $node->shared_editing['private']) ||
        (!isset($node->shared_editing['private']) && $node->coherent_access['private'])) {
      $grants[] = array(
        'realm' => 'coherent_access',
        'gid' => $gids[0],
        'grant_view' => FALSE,
        'grant_update' => FALSE,
        'grant_delete' => FALSE,
        'priority' => 0,
      );
    }
 

I am not sure that this code is needed. It can probably be removed since the grant will never be written when view, update and delete are all FALSE (see http://api.drupal.org/api/function/node_access_write_grants/6), but I am not sure if there is any other reason to keep it?

Anyway, the code in hook_nodeapi doesn't work because the statement
$private = variable_get('coherent_access_default_node_private', 0); // load default node
just resets the private status to the coherent_access admin visibility settings. This is not what we want.

I think this line should be
$private = 1;

This seems to fix the problem.

jseffel’s picture

Rebuilding permissions at admin/content/node-settings sets all nodes to private.

Edit: I set out to apply the patch at http://drupal.org/node/360460 but it conflicts with this patch.

MGN’s picture

Status: Needs review » Needs work

Sorry. I see that the two patches overlap a bit. Its probably easy enough to apply the earlier patch and then go in and set $private = 1 to get the same effect. It doesn't really matter right now, because you are right - rebuilding permissions sets coherent_access nodes to private regardless of the coherent access admin settings. Need a way to distinguish between the absence of a row in node_access (indicating a private node), and a new node.....

MGN’s picture

Status: Needs work » Needs review
StatusFileSize
new1.88 KB

I think the logic should be something like:

{see if the node is in the node access table.}  
      {if so, determine if a mode 0 blanket grant (gid $gids[0]) has been given.}
           {if so its not private, otherwise it is private}
 {else, its either a new node, or the node_access table is being rebuilt - use the default}  

If this is the correct logic, then the problem is

$result = db_query('SELECT count(*) FROM {node_access} WHERE realm = "%s" AND gid = %d', 'coherent_access', $gids[0]);

doesn't check to see if the node is in the node_access table.... it should be

$result = db_query('SELECT count(*) FROM {node_access} WHERE realm = "%s" AND nid = %d', 'coherent_access', $node->nid);

The line $private = variable_get('coherent_access_default_node_private', 0); then makes sense.

In testing this,
* new coherent access nodes are created with private status determined by the default settings
* private status works as expected
* rebuilding the node access table restores coherent_access nodes to default setting

I think this is the expected behavior...at least I don't see how it could behave otherwise without actually storing the $private setting in a coherent_access database table...

Patch against 6.x-1.x-dev .

jseffel’s picture

StatusFileSize
new12.11 KB

You are right - we need an extra table. I had to get this working asap so I did it with an extra table. I've changed to info etc.

I've tested it on our site and it seems to work as expected (atleast as how we expect it)

dougvann’s picture

StatusFileSize
new50.95 KB

Well. I had to use utdanning's version for the situation I was in. BUT it still had the email issue and "Shared Posts" tab did not appear on the user-menu. Lastly, the names of locally used functions did not begin with underscores. Oddly enough, when I added the underscores to the 'access callback' and its function definition, it fixed the missing tab.
So here it is....
Yet another fork of this very useful module.
I will attempt to devote some time to getting the initial module up to snuff, but in the mean time, any one is welcome to use this one.

MGN’s picture

A patch for the shared posts tab is already in the issue queue #360651: Shared posts tab not showing on user account.

jgraham’s picture

Status: Needs review » Fixed

Patch implemented as per #9 thanks, MGN

Status: Fixed » Closed (fixed)

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