When creating a new node, flag_friend_access form alters in a little check box. Then when the node is submitted, it has this checkbox property that we use in the node_access_records hook
/**
* Implementation of hook_node_access_records().
*/
function flag_friend_access_node_access_records($node) {
if ($node->flag_friend_access) {
// DO STUFF
}
But when a node access is being rebuilt, it does a node_load() and on node_load there is no association between flag_friend_access and the node, so $node->flag_friend_access doesn't exist.
Thus, no access control is applied from flag_friend_access and the node is Viewable by all.
So the task at hand is to create a database table that is uid | nid. On node_load() set $node->flag_friend_access = db_result(db_query("SELECT uid from {table} where nid = %d"))
Comments
Comment #1
dicreat commentedsubscribe
Comment #2
sirkitree commentedJust a note that this will require an install file for flag_friend_access.
Comment #3
sirkitree commentedchange to component category
Comment #4
sirkitree commentedHow's this look? Do we need an update hook for users to run who already have this installed?
Comment #5
Scott Reynolds commentedWhen do you insert into that table ;-)
Comment #6
sirkitree commentedhook_nodeapi -> insert should be fine right?
I know you mentioned that you can edit a node and change the checkbox - but actually you can't currently, so insert should be fine for now I think, yes?
Comment #7
Scott Reynolds commentedyou probably need the update as well otherwise you leave the current users no chance to fix their setup.
Comment #8
sirkitree commentedOk, if that is the case, what was the reasoning for putting the check in hook_form_alter() here:
if ($form['#node']->type . '_node_form' == $form_id && empty($form['#node']->nid)) {we should remove the last check there right? and give it a default value drawn from where? the new access table? or simply node_access? is there some node access code to use there for default value?
Comment #9
Scott Reynolds commentedthe purpose of that check was actually for this problem. That is, a node's flag_friend access setting couldn't be changed after it was created.
Now that we are creating table for it, we can remove that empty($nid) check and pull the default value from the table.
Comment #10
sirkitree commentedHere's another pass at this.
Comment #11
Scott Reynolds commentedwell I don't like the function with a 'type'. I would have just written a function to fetch the uid and then the #default_value => !empty(flag_friend_access_get_uid($nid))
The static cache should be $uids = array(); if (!isset($uids[$nid]), because you could call this function with different nids.
doing the
$access = flag_friend_access_default($node->nid, 1);at the top of nodeapi is most wrong. What if the $op == 'view' and $op == 'load' never happened? we just did a db call for 'Viewing' a cached node. This happens on a std drupal install, if you display the same node several times on the page. $op == 'load' happens once and is static cached in the node_load() function.I think I will have some time today to write the patch.
Comment #12
Scott Reynolds commentedalso typo VALUE != VALUES in op insert/update
Comment #13
Scott Reynolds commentedHere we are, an improved patch. Key is to call node_access_acquire_grants() when the node flag access stuff is changed.
Comment #14
rc2020 commentedNote: I also wrote a function to determine whether or not the node has access permissions set on it or not. It needs to be modified to include og_groups access grants, but if you need to use a conditional of whether or not the node is indeed restricted to friends only, this function may help:
Comment #15
Scott Reynolds commentedA.) this has nothing to do with og
B.) it would be way more efficient to use the table provided in the above patch.
C.) you have a security hole in that function
I could call flag_friend_access_check("DELETE FROM {users}"); and delete your entire users table.
Comment #16
rc2020 commented@SR -
Sure. This wasn't the main queue for placing that function, I just put it in because I was directed to this thread after I solved my own issue. I'm not an expert on this stuff.
Comment #17
rc2020 commentedThis patch looks to flag_friend_access.install, which isn't included in either the RC or Dev release. Will the older version of flag_friend upgrade fine to this, or do I need to uninstall and reinstall?
Comment #18
dingbats commentedsubscribing
Comment #19
rc2020 commentedI have been unable to apply this patch as it's looking for a file called flag_friend_access.install.
Is there something I am missing here? I've applied numerous patches before but I always have the file it's looking for.
What should I do?
Comment #20
Scott Reynolds commentedThe file doesn't exist this patch creates it. patch handles it just fine
patch -p0 -i /path/to/file.patch
Comment #21
kewlguy commentedFor the life of me I cannot sort out how to apply this patch. Funny, I've applied over 20 patches to my drupal install though these instructions seem to be sadly too complicated for this dumbie.
I've tried the method quoted above, though, since the file does not exist what file, exactly, am I supposed to point the patch to? And, where is the < that I have seen and used in every other patch that I have applied?
Comment #22
Scott Reynolds commentedthe -i is in place of that
You can if you would like
patch -p0 < flag_friend_486704-12.patchFor a more exhaustive overview of the patch command: http://drupal.org/patch/apply and http://linux.about.com/od/commands/l/blcmdl1_patch.htm
Sometimes patch doesn't work properly for some people I have found that the file doesn't get placed into the proper directory in a number of different situations. Creating patches with new files like this one where flag_friend_access.install doesn't currently exist tend to be the tougher ones.
Comment #23
sirkitree commentedPut the patch file within flag_friend/flag_friend_access/
run
patch -p0 -i flag_friend_486704-12.patchThis creates the flag_friend.install file and patches flag_friend_access.module
Patches are typically created in the module's root directory, but there are simply ways around it if they are not.
I did the above and the patch applied cleanly for me.
Will commit this to 1.x and 2.x
Comment #24
kewlguy commented#sirkitree
Thank you very much for the instructions. I very much appreciate your patience and understanding.
Comment #25
dreadfulcode commentedI do not have access to linux commands. Is there another way to apply this patch?
Comment #26
kewlguy commented#dudeoflife
Is you site hosted on a linux/unix box (pretty much the standard for a drupal site)? If so I am guessing that you are using a windows based computer yourself? If you are on windows and you need to access the command line on a hosted site you can always install an ssh tool such as Putty.
After you install putty, and do a little reading of the manual, you will find that you can ssh into your site and apply the patch.
If you regularly use ftp for your files you are really going to enjoy the putty client because the file transfers of modules and patches from drupal.org are oh so much faster.
Make sure that you investigate the pageant program that comes with putty because it can make the logins much easier that having to type in your login information all the time.
Hope this help you out!
Comment #27
quiptime commented@sirkitree,
your post #23.
What is your problem to include the available patchcode in the actual contributed module releases?
Please read my post http://drupal.org/node/484394#comment-2742126
The actual contributed releases of flag friend access module are bad. Very bad.
So bad because they do not work. To do something is not good for Drupal. It is not good for the reputation of Drupal.
@sirkitree, I will watch you and the flag friend access module .
Comment #28
Scott Reynolds commented@quiptime
Your attitude is far worse for Drupal's reputation then a marginally broken *RELEASE CANDIDATE* module.
Comment #29
sirkitree commentedLOL, srsly? Are you like threatening me quiptime?
Comment #30
quiptime commented@Scott Reynolds,
the contributed code of flag friend access module is not marginally broken - it is completely broken.
@sirkitree,
I want to threaten anybody. I want that works the module.
Please remember, you are a member of Lullabot. Is that the modus operandi of Lullabot - to contribute broken modules?
Why do not you just answer my question?
Comment #31
sirkitree commented@quiptime: have you tried this patch? are you saying it is still broken after this patch is applied? if so, can you please provide some constructive feedback? I've not gotten to committing this just yet because I've been busy working for Lullabot.
Comment #32
quiptime commentedNot the patch code has bugs. I did not say that. The contributed code has bugs. The errors are known and a solution is there.
But the solution is not available in the contributed modules. That is what I criticize.
The (errors) bugs are so obvious that one not a specialist must be seen to them. You simply try to use the module. And that's what I did.
Next, I looked at the code of the contributed module versions. And pardon me, but this is little bit stupid:
That is not logical. What do you if you later at a node might change the friend access?
What is it? No default value.
=========================================================
I need this module. But it must work. I will test the patch and report constructively. Is that OK?
Comment #33
dreadfulcode commentedHey quip-
May I suggest for you to rework the module? I mean, the code is all right here. It IS open source, you know. Maybe you have more spare time than these other cats who bang out line after line of code for these broken modules.
Comment #34
dreadfulcode commented#kewlguy
I don't think I would be able to do that with my shared hosting plan thru hostgator. However, if I am wrong, the implications of this program could be huge- as in setting up a ffmpg service.... Thanks for the heads up, in any case.
Comment #35
kewlguy commentedIs flag_friend_access supposed to have no index in the database? When I look in my site docs I see a warning for " Indexes: No index found". Is this correct?
Comment #36
Scott Reynolds commentedAhh your right its missing the primary key property in the hook_schema. it should be
Comment #37
dreadfulcode commentedSo in other words: don't mess this this latest patch?
Comment #38
kewlguy commented#dudeoflife
I installed the module, then applied the patch, of which there are instructions in the above posts and then I went into my tool for mysql and confirmed that the table exists, then while viewing the structure of the table "flag_friend_access" and looking to the row for "nid" I clicked on the icon that has the screen tip for "Primary Key" and it made the last fix for me.
TIP: I use cpanel to get to myphpadmin for mysql. ** ALWAYS MAKE A BACK UP **, It's in cpanel as well, or plesk whichever you have on a hosted set up. If you use a Mamp or Lamp set up on your computer is should not be too hard to find in the set up.
This is not the actual method that many programmers would use it is more of an administrators way of solving a problem without digging into the module install file and making the change and submitting a patch. PHP and creating myql scripts are way beyond my thinking style so it is the way I find I go.
Having said all that you can look into a search for 'drupal+create a module' and in the handbooks, I saw a decent tutorial here to see how to make what appears to be a simpler change to the module.install file.
You could always do a search for the latest handbook page using the terms "create a patch" and you may find that it is a very viable way to contribute back for all the awesome 'free' code here.
Or, do similar to what you said and "don't mess with this module", kewl?
Thank you for contributing!
Comment #39
sirkitree commentedOk, added the index this should be good now.
Comment #40
sirkitree commentedcommitted to 1.x-dev: http://drupal.org/cvs?commit=345698
porting to 2.x-dev
Comment #41
sirkitree commentedcommitted to 2.x-dev: http://drupal.org/cvs?commit=345708
Comment #42
dreadfulcode commentedThanks again for the explanation, kewlguy!
I'm gonna dig in learn more about this here concept of patching. I am very comfortable working with php as well as mysql scripts-- this concept of using shell commands is a whole new concept with me.... I gather that it does to code what I like to do manually. Really interesting and powerful stuff.
As far as this patch is concerned, I'll give it a go as and post the results on this thread. Soon, hopefully.
Free the software!