Plugin architecture for field access permissions + Integration with Friendlist

mercmobily - September 27, 2008 - 12:09
Project:CCK Field Privacy
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:obsidiandesign
Status:closed
Description

Hi,

I am the developer of FriendList:

http://www.drupal.org/project/friendlist

I'd like to integrate with your module (D6)
Can you point me to:

* An example of an integration
* The relevant documentation
* Any additional information

...?
Thanks!

Merc.

#1

4drian - September 27, 2008 - 20:54

Woot! Go merc.

#2

obsidiandesign - September 27, 2008 - 21:03

Merc,

You wouldn't have to make FriendList 'integrate' with cck_field_privacy. This module checks to see (currently only from Buddylist, but the concept would be the same for other modules) if the viewing user is 'friends' with the user who created the content. If the field permission is set to 'buddies', and the viewing user is a 'buddy', then the field is displayed.

So, the real question, I guess, is what API is in place in Friendlist to gather the current friends of the node's author & what format those friends are returned in.

Thanks in advance for your help.

Bryan

#3

mercmobily - September 28, 2008 - 04:16

Hi,

FriendList has a very simple function:

friendlist_api_relation_status_get($requester, $requestee, $rtid)

However, I must say... I think your approach needs to be more generalised. At the moment, there is "Friend", "User Relationships" and "FriendList" out there. I am talking to the "Friend" author and it looks like he's willing to merge his userbase into FriendList.

But... I _really_ think you would be _much_ better off generalising the way you check if permissions are allowed. I don't think you want any module-specific code in your module.

A good way to go about it could be:

  $all_good=TRUE;
  foreach (module_invoke_all('cck_field_privacy_access', $request,$requestee) as $access_result ) {
    if(! $access_result){   
       $all_good=FALSE;
    }
  }

That way, my module would have to implement a hook called hook_cck_field_privacy_access() which will return TRUE or FALSE.

That way, in fact, *any* module can set access level. Note that in the function above access is granted by default -- however, if any one of the hooks returns FALSE, then access to the field is denied.

Please let me know if you are happy with this approach -- if you are, I will develop the hook _immediately_ so that you can install Friendlist (it will take 2 minutes) and test things out.

Bye,

Merc.

#4

obsidiandesign - September 28, 2008 - 14:19

Merc,

I really do like the proposed approach - I guess the main roadblock is the need to get ALL of the modules that generate user->user relationships to implement such a hook so the cck_field_privacy module could work. In terms of the 2.x version of cck field privacy, this approach could be a good idea, and users looking to use cck field privacy could file issues with the different modules that can be used with cck field privacy asking for a similar implementation. I would be willing to help module maintainers with that, of course.

Bryan

#5

mercmobily - September 28, 2008 - 16:41

Hi,

Now, you are talking about a 2.X version... are you talking about a possible 6.2.X version which would come after a 6.1.X version?
If so, I beg you to consider using the code above for 6.1.X instead. A lot of people at FriendList will want the functionality, and I don't really see the point of getting people to wait. Consider that Buddylist2's successor for D6 is very likely to be FriendList...

I am happy to send you the working integration code for FriendList pretty much immediately. I am sure Alex.k of User Relationships would do the same.

Bye,

Merc.

#6

obsidiandesign - September 28, 2008 - 17:07

Well, since there's no 6.x-1.x really, it would fall under a 6.x-1.x version, once it's tested - guess I should have worded that better. For 5.x compatibility, it would go into 5.x-2.x, so users that are using BuddyList could still use the module under 5.x. Once/if BuddyList implemented such a hook, then it would work with 6.x as well, along with FriendList and UR.

Bryan

#7

mercmobily - September 28, 2008 - 18:48

Hi,

OK about the versions -- sorry :-D

FriendList only exists for D6. So, I won't be able to give you an example hook.

About 5.x... I am not sure what to suggest. I would go the same route as I suggested, add yourself the hook for buddylist (which you basically already have), and ask the developers of Friend and User Relationships to support your hook!

When do you need me to write the hook for you? I don't mean to be pushy -- I just have no idea how much longer it will be before a D6 version will be available :-D

Bye!

Merc.

#8

obsidiandesign - September 28, 2008 - 18:59

There is a D6 module, you just have to check it out of CVS currently. I guess I can add it to the project page, it just hasn't been tested. I quickly upgraded it using the Deadwood module, so I'm not sure it 100% works yet. With this added development, though, I guess it would be a good way to start getting bugs out while dealing with the changes to how CCK Field Privacy is using other modules.

I'll add it as a -dev only to the project page, but I don't know how long it will be before it will show up on the page. I could email you a .tgz of the current files if that would help.

Bryan

#9

obsidiandesign - September 28, 2008 - 19:00

Looks like the .tar.gz file was already created, but I hadn't marked it to show the -dev release. So, it's on the project page now.

#10

mercmobily - September 28, 2008 - 19:05

Hi,

OK, no worries. I will implement the hook in FriendList within the next couple of days. After that, you will need to actually install FriendList (it's really simply, just the API and the UI) and see if my hook is 1000% OK.

Is that a good route for you?

Thanks!

Merc.

#11

obsidiandesign - September 28, 2008 - 19:09

Sounds great - I look forward to it!

Bryan

#12

mercmobily - September 29, 2008 - 04:51

Hi,

OK... done!
I am ready to roll. It should be pretty straightforward for you to test things out.:

* Install friendlist_api, friendlist_ui and friendlist_access_integration

* Get two users to be friends. To do that, just visit a user's profile page and click on "become friends" as admin, for example

* Lock a field with your module

* See if it gets locked :-D

You can get Friendlist's CVS, or wait for the snapshot.

Thank you!

Merc.

#13

mercmobily - September 29, 2008 - 15:35
Title:Integration with Friendlist» Plugin architecture for field access permissions + Integration with Friendlist

Hi,

I am changing the title, since this is no longer about not depending on FriendList, but adding a plug-in architecture for any type of friends module (and in fact any module that wants to give access to fields)

FriendList just happens to be the first module that supports it because it's the one I develop.

Bye,

Merc.

#14

obsidiandesign - September 30, 2008 - 04:13
Assigned to:Anonymous» obsidiandesign

I'll test this as soon as I can, just didn't have an opportunity tonight. Thanks Merc for the great work.

Bryan

#15

mercmobily - September 30, 2008 - 04:47

Hi,

Anytime Bryan.
I hope you won't have any problems with the code I provided, and that my plugin works as intended :-D

Merc.

#16

DaniOrama - September 30, 2008 - 14:14

Would this also work for User Relationships? That would be great!

#17

mercmobily - September 30, 2008 - 17:35

Dani,

It will once Alex.k writes a 3 line plugin -- he will simply copy more or less the one I did for FriendList.The same applies to the other "relation" modules, even though I wouldn't hold my breath since for D6 the maintainers have gone a little depasarecidos.

Bye,

Merc.

#18

DaniOrama - September 30, 2008 - 20:52

If will try to contact Alex. I told him I cannot offer many help with code (I'm relative new with drupal development) but I'll try to help after I finish my last website (I really need to finish it this weekend)

In another recent issue it's said that using the module without Buddylist installed gives some warnings, it's that solved? (it's not totally related with this issue but it seems this one is for discussing the implementation of several relations modules)

I think Friendlist could be integrated with User relationships, it would be easier to everyone, but that's also not the point of this issue.

PS: it's desaparecidos :D

#19

obsidiandesign - October 1, 2008 - 02:38

Merc,

I have to hand it to you - it works absolutely great. And you're right - it is much cleaner (and easier on my end) to have the hook structure rather than me trying to code for every different type of user relationship module.

Thanks again for this update - if needed, I can help propose in other issue queues a patch that will implement such a hook like Merc did.

Bryan

#20

obsidiandesign - October 1, 2008 - 02:44
Status:active» needs review

Also, since the code has been implemented into the Drupal 6 dev version of CCK Field Privacy, I think it's appropriate to mark this issue 'Needs Review' simply because I need people to test it out. Separate issues can be filed in the respective queues to get other modules to implement the hook.

Bryan

#21

mercmobily - October 1, 2008 - 03:04

Hi,

"I think Friendlist could be integrated with User relationships, it would be easier to everyone, but that's also not the point of this issue."

FriendList has a solid architecture, well written and commented code, full documentation, a fantastic system to keep track of relation statuses, a workflow-oriented status system, a cleaner- relation-oriented API, an improved database structure, and full integration with Views and Rules.

It *cannot* be integrated.

Have you considered using FriendList instead?

Bye,

Merc.

#22

mercmobily - October 1, 2008 - 03:06

Hi,

Bryan, that's fantastic!
Just to check it: you installed FriendList, and my hook responded "as expected"?

If so, I'll get Marius to test the integration... but we might actually be _done_ -- yay!

Thank you for being so responsive about this.

Bye,

Merc

#23

obsidiandesign - October 1, 2008 - 03:12

Merc,

Yes, it worked exactly as you said it would (I tested with and without being buddies. Used the code you proposed almost verbatim (changed a couple variable names), and it all worked great. Thanks for your help - it's always far easier to be responsive when others contribute to the effort!

Bryan

#24

mercmobily - October 1, 2008 - 03:24

Hi,

That's so cool. I am glad to hear that!
This change will also benefit User Relationships, which is great.

DaniOrama: the best thing to do is to open a request on User Relationships, pointing out this code:

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/friendlist/...

This will give Alex a VERY clear template on how to write the hook for CCK integration.

Thanks!

Merc.

#25

mercmobily - October 1, 2008 - 03:26

Hi,

@obsidiandesign: can I ask you a favour?
Can you get the latest DRUPAL-6--1 version of the integration module, and see if still works if you have your testing environment still up?
I moved the hook out of the admin.inc file (not sure why it had landed there) and want to make I didn't stuff anything up...

Thanks!

Merc.

#26

DaniOrama - October 1, 2008 - 11:27

Merc, I'll try Friendlist as soon as I can, right now I'm working nonstop on a website :D I hope I'll be a bit more free in the weekend and I'll try to help with the testing.

I've read http://groups.drupal.org/node/14625, it was really helpful but the list is incomplete, there are many features from user relationships not shown (integration with privatemsg, invite, etc... and also the main difference is that in User relationships there is no limit for the kind of relations between users)

Friendlist is the best option if you want just that, 2 kind of relationships (fan and friend), but if you want something complex with different kind of relationships, access and actions regarding them, User relationships is better in my opinion. Right now, Alex has started with it so he needs a bit more time to port it fully to D6.

PS: please, correct me if I'm wrong, I'm not familiar with friendlist module.

#27

mercmobily - October 2, 2008 - 17:07

Hi,

(Apologies to the CCK field access permission for the little intrusion)

>Merc, I'll try Friendlist as soon as I can, right now I'm working nonstop on a website :D I hope I'll be a bit more free in the weekend and
>I'll try to help with the testing.

OK.

> I've read http://groups.drupal.org/node/14625, it was really helpful but the list is incomplete, there are many features from
> user relationships not shown (integration with privatemsg, invite, etc... and also the main difference is that in User relationships
> there is no limit for the kind of relations between users)

The comparison is with the Drupal 6 version of the module. Since the User Relationship maintainer edited the comparison as well, I can only assume that those integrations don't exist for the D6 version.

> Friendlist is the best option if you want just that, 2 kind of relationships (fan and friend), but if you want something complex with
> different kind of relationships, access and actions regarding them, User relationships is better in my opinion.

...? Friendlist can have as many relationship types as you like. In that, the modules are the same. "Access and actions"... right now, only FriendList interfaces with Rules.
I am not sure what you are basing your opinion on. But it doesn't sound very informed.

> Right now, Alex has started with it so he needs a bit more time to port it fully to D6.

Good on him,

> PS: please, correct me if I'm wrong, I'm not familiar with friendlist module.

Ah, OK. I think the best thing to do is install it, and play with it.

Merc.

#28

DaniOrama - October 1, 2008 - 18:32

Hey Merc, I'll try friendlist as soon as I can and then I'll write a support request issue on your module. As I told before, I haven't used it yet. My opinion was based just on the module description and the issue queue. I should have written "...but the list 'seems' incomplete...".

Anyway, I'll play with it a little and I'll ask you then. I think it's better letting this issue clean and just for the integration. Sorry for starting to ask irrelevant things. :)

PS: I have told Alex about your code, it's on the way. Thanks!

#29

IceCreamYou - October 1, 2008 - 22:30

Any chance this plugin architecture will be backported to D5? I can't upgrade to D6 until a few more crucial modules are ported, and this module would still be useful to me...

If not... if I can backport it, could it be included? No promises here, I'm pretty short on time.

#30

obsidiandesign - October 2, 2008 - 04:12

It can be backported, yes, but there still needs to be issues filed for each integration module to implement such a hook. I would recommend holding off on 5.x until we get a few more 6.x setups done. It's not a large amount of code specific to this module (or the others, really), so it will be very easy to backport.

Bryan

#31

mercmobily - October 2, 2008 - 04:55

Hi,

I agree... let's see how much traction it gets from other modules. I think it will, because it's just such a nice way of doing it...

Merc.

#32

asak - October 3, 2008 - 09:10

You guys are the best.
Subscribing.

(I'm here for cck privacy + user relationships + D5 ...)

#33

bensemmel - November 12, 2008 - 22:08
Category:support request» bug report

Hi,
I know 6.dev isn't stable, however I wanted to try the 6 dev version together with the friendlist module. But after installing the cck privacy module I get two errors:

1. It can't create menus - On the module admin page I get
Missing argument 1 for cck_field_privacy_menu() in .../sites/all/modules/cck_field_privacy/cck_field_privacy.module on line 41.

2. It still calls buddylist - On the Frontpage I get a white screen and:
Fatal error: Call to undefined function buddylist_get_buddies() in .../sites/all/modules/cck_field_privacy/cck_field_privacy.module on line 75

Can you please have a look at this...

Thank you
Ben

#34

obsidiandesign - November 13, 2008 - 04:14

Something's up in the 6.x tarball, I'll fix it tomorrow afternoon.

#35

obsidiandesign - November 15, 2008 - 00:50
Category:bug report» feature request

The commit did not occur properly for the 6.x branch. I've re-committed the changes, which will take effect in the next tarball roll. In the meantime, you can check out the module using CVS to get the 6.x branch for testing. Thanks for the heads up.

Bryan

#36

bensemmel - November 15, 2008 - 13:00

Hi Bryan,

thank you for this, unfortunately it doesn't work with the new tarball neither. But I took the files from CVS and it worked. Thank you. However you have a small bug in the .install file, therefore the table "cckfp" isn't created...
I'm not a programmer, but by comparing with other .install files it seems that "$schema = array();" is missing in line 8.

Hope that helps
Thank you
Ben

#37

obsidiandesign - November 15, 2008 - 20:16

I've added the $schema line, as recommended, and the module installs correctly & works with FriendList as expected. Used a brand new install as a test and things worked very well. Let me know if you have any luck getting it up & running, if so I'll release a 6.x-1.x stable release.

#38

bensemmel - November 16, 2008 - 12:27

Everything works fine now.

Thank you again...

#39

obsidiandesign - November 16, 2008 - 19:41
Status:needs review» fixed

Marking this issue fixed, since the hook is now used in a stable Drupal 6.x version. Again, any support people can give to issues on other projects to implement the hook will help integrate with other systems.

#40

System Message - November 30, 2008 - 21:33
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.