Problem/Motivation
Around line 226 in the node_access_example.module file, specifically in the node_access_example_node_access function we have the following line of code:
drupal_set_message(t('Access to node @nid allowed because requester name (@name) is specifically allowed', array('@name' => $node->name, '@uid' => $account->uid)));
There are two replacement variables in the translation string, namely @nid and @name, but the variable array being passed have a different set of variables, namely @name and @uid.
Proposed resolution
The @uid variable '@uid' => $account->uid) should be replaced with '@nid' => $node->nid
Remaining tasks
- Correct Code
- Submit and test patch
Comments
Comment #2
jpdippenaar commentedReplaced the variable
'@uid' => $account->didwith'@nid' => $node->did.When I tested the code, I realised there may be a problem with the logic in the if statement as well. In specific
!empty($node->private)did not make sense. If the variable was set to false,$node->privatewould evaluate to"0", which is not empty. Someone needs to verify the new logic.Comment #3
jpdippenaar commentedComment #4
navneet0693 commentedHi @jpdippennar,
Added
&& $node->privateto check the value of$node->private.isset($node->private)will only check whether$node->privateis set or not regardless of it's value being TRUE or FALSE adding&& $node->privatewill also check value of it and executes the if condition accordingly.Comment #5
jpdippenaar commentedThans @naveet,
Makes perfect sense, and happy that at least I was not completely wrong about the original logic not working.
Comment #6
joshi.rohit100The following things are considered to be empty:
So, I think we don't need that isset clause and empty check is fine
Comment #7
manav commentedTest Results : Pass.
The given patch is fine working for me.
Drupal 7 Version : 7.43
MySQL : 5.5.42
PHP : 5.6.10
Comment #8
mile23$nodeshould always have aprivateproperty. Something's very wrong somewhere else if it doesn't. So we can just say$node->privatewithout theisset().Place the items in the array in the same order they are in the string. Also, we should use the node name instead of the nid.
So: Use the name for both the account and the node.
testNodeAccessBasic(), but it doesn't check the message. It should.Comment #9
vicheldt commentedComment #11
vicheldt commentedI created a MR because I wasn't able to apply the patch, and I also believe MR are easier to handle. So I added the changes that were in the last patch (comment #4) and the points that @Mile23 made, except the tests part, because I'm not sure how to proceed. If anything is incorrect here please let me know, I wanna learn more :)
Comment #12
vicheldt commentedComment #13
sophiavs commentedHi, i'll be doing the changes on tests :)
Comment #14
sophiavs commentedI submitted a new commit, but a new test fail in a file that i didn't change, i will still try to analyze the reason.
Comment #15
sophiavs commentedI'm trying to upload a patch to confirm the test
Comment #16
sophiavs commentedComment #17
lucasscHi! I'll review.
Comment #18
lucasscI applied the patch in #15 for branch 7.x-1.x and works fine, changes in #8 have been made, tests are passing and there's no coding standards problems as well.
Comment #21
jungleThe head is green https://www.drupal.org/pift-ci-job/2596707, no idea why https://www.drupal.org/pift-ci-job/2418880 failed.
Let's go ahead.
Thanks!
Comment #22
jungle