Hi there,
For a module I'm developing I need to restrict access to nodes, but I'm lost somewhere between node_access_example.module and Node access rights on the api pages.
Currently I have this part working:
A user clicks a button and without realising it, a node is created and with hook_node_access_records a new record is added to the node_access table, where the gid is the uid of the user and the realm is business_proposal which is always the same. Finally grant_view is set to 1, the other are set to 0.
Now what I don't really understand is how to actually restrict access to that node so that only the node author can view his own node, while access for others is not allowed.
I tried this (grabbed pieces from examples I found):
function uc_business_proposal_node_grants($account, $op) {
if ($op == 'view' && user_access('view own business proposal product', $account)) {
$grants['business_proposal'] = array(1);
}
return $grants;
}view own business proposal product is listed in hook_perm.
Can somebody help me?
Thansk in advance!
Comments
You also need to write
You also need to write function for the hook "hook_node_access_records"
Thanks, but I already have
Thanks, but I already have it, that's the function that writes the data to the node_access table.
Should I also add an item to the hook_menu?
Still looking for the answer,
Still looking for the answer, here is my hook_node_access_records() function:
And it seems like this would be all I need to make this work, but it doesn't:
It seems so simple, but I don't understand why it isn't working. Can somebody please help?
Thanks!
Looks almost perfect...
Looks almost perfect...
1. Try rebuild permission after each code change in functions at admin/content/node-settings/rebuild
2. Try slightly higher priority, May be other modules over right your priority. Make it 1
I already found a solution by
I already found a solution by using the Private module and simply writing values to that table would help, but it was a workaround.
I uninstalled the Private module, rebuilt the permissions, restored my original code with only the priority set to 1 and it seems to be working! I will give it another try on a fresh installation to see if it are not some remains of the private module still doing their work.
Thanks for your help!
Yes that did the trick, it
Yes that did the trick, it works perfectly!
Thanks again!