Hi,

this is the scenario:

I mantain music community site. We are going to have two main roles for our registered user - musician and user. Then we are going to have two types of relations - friend and fan. And now - user role can create one way fan relationships with musicians as well as two-way friend relationships with other users. However, musicians are not allowed to create two-way relationships between each other.

Is this doable using your module?

Thanks,
Petiar.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alex.k’s picture

Yes it's doable with additional code work. Right now all relationship types are accessible to everyone. This would need an admin setting with a kind of a matrix allowing certain types for certain roles. I've been wanting to do this feature, but so far it has not been great priority. Any development help would be great, and would move this forward, though.

petiar’s picture

Status: Active » Closed (fixed)

Thanks for the update. I might be able to have a look into the code and check what could I do but I can't promise any effort as I am not very familiar with coding for Drupal yet. But maybe this could be the way how to move forward. ;-) We'll see...

Manuel Garcia’s picture

Title: Is it possible to limit relations per user roles? » Extend role access to configure "which roles are allowed to receive this relationship"
Version: 6.x-1.0-beta8 » 6.x-1.x-dev
Component: User interface » Code
Category: support » feature
Status: Closed (fixed) » Active

OK I'm switching this to a feature request for dev, and changing the title accordingly.

I think the basic idea would be the same as #228206: Different types of relationships per role type, only that feature (already in) is to configure what roles can request the relationship. This is the other way around, what roles can receive the relationship.

I assume this could be doable in an extra module, through hook_user_relationships_type($op, &$relationship_type), but I think user_relationships would gain a ton of flexibility with this in it.

I'd be willing to look into it, but I'm new to the api and would need a bit of guidance as to how to go about doing it...

alex.k’s picture

Would appreciate you taking it on. You are right, I think the implementation will be similar to the issue you quoted. If you look at the commit (http://drupal.org/cvs?commit=176372 unfortunately it fixes several issues at once, so it's hard to tease apart):
* most changes revolve around a new function user_relationships_api_can_request http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/user_relati...
* an addition to user_relationships_types_load http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/user_relati... that loads the permissions.
* data is stored in a new table user_relationship_type_roles. I would suggest creating a similar new table to keep the impl simple.
* one example of one check in the code for the permission would be http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/user_relati...

Manuel Garcia’s picture

Status: Active » Needs review
FileSize
19.19 KB

Thanks alex.k for the info =)

I went ahead and spent a couple of hours on this, and here's a patch that I think is already working, at least as far as I have tested it. Hopefuly it will work nicely with the other permission settings for roles etc.

The patch unfortunately came out with some cruft I guess coming from my editor... sorry if it's a bit hard to read :X

Bilmar’s picture

Status: Reviewed & tested by the community » Needs review

Hello,

Thank you for this patch! This is exactly what I have been looking for!
I used terminal to patch but received 2 errors (seen below).
Also got error messages in drupal pasted below.
Are you or others also experiencing the same errors?

adhoc:untitled Franky$ patch -p0 < user_relationships-327624.patch
patching file user_relationships_api/user_relationships_api.api.inc
patching file user_relationships_api/user_relationships_api.install
patching file user_relationships_ui/user_relationships_ui.actions.inc
patching file user_relationships_ui/user_relationships_ui.admin.inc
patching file user_relationships_ui/user_relationships_ui.admin_actions.inc
patching file user_relationships_ui/user_relationships_ui.module
Hunk #2 FAILED at 44.
Hunk #3 succeeded at 69 (offset -4 lines).
Hunk #4 succeeded at 245 (offset -4 lines).
Hunk #5 succeeded at 304 with fuzz 1 (offset -4 lines).
Hunk #6 succeeded at 378 (offset -4 lines).
Hunk #7 succeeded at 680 (offset -4 lines).
Hunk #8 FAILED at 810.
2 out of 8 hunks FAILED -- saving rejects to file user_relationships_ui/user_relationships_ui.module.rej

Drupal error=>
* user warning: Table 'drupal.user_relationship_type_roles_receive' doesn't exist query: SELECT rtid, rid FROM user_relationship_type_roles_receive ORDER BY rtid, rid in /f1/content/example/public/sites/all/modules/user_relationships/user_relationships_api/user_relationships_api.api.inc on line 88.
* user warning: Table 'drupal.user_relationship_type_roles_receive' doesn't exist query: SELECT rtid, rid FROM user_relationship_type_roles_receive ORDER BY rtid, rid in /f1/content/example/public/sites/all/modules/user_relationships/user_relationships_api/user_relationships_api.api.inc on line 88.

Manuel Garcia’s picture

What version of the module are you patching?

I tried the patch with the latest dev release, from the module directory, run:

manuel@manuel-laptop:~/Desktop/user_relationships$ patch -p0 < user_relationships-327624.patch 
patching file user_relationships_api/user_relationships_api.api.inc
patching file user_relationships_api/user_relationships_api.install
patching file user_relationships_ui/user_relationships_ui.actions.inc
patching file user_relationships_ui/user_relationships_ui.admin.inc
patching file user_relationships_ui/user_relationships_ui.admin_actions.inc
patching file user_relationships_ui/user_relationships_ui.module
manuel@manuel-laptop:~/Desktop/user_relationships$ 

I get no errors. Make sure you are using the lates dev release, and you are runing the patch command from the module's directory.

ALSO: MAKE SURE TO RUN UPDATE.PHP AFTER APPLYING THE PATCH!

Bilmar’s picture

Thank you Manuel Garcia - I was able to successfully patch the module.
I spent 3 hours testing the patched module but was unable request relationship:

Setting-
Role A is allowed to request Friend relationship
Role B is allowed to receive Friend relationship

As user with Role A I try to request friend relationship to user with Role B, but getting "You may not create any more relationships to this user." when request link is clicked. Both Role A and Role B do not have any relationship to one another or any other user.

Is there additional steps necessary for this patch to work that I am overlooking?

Thanks for your support!

Manuel Garcia’s picture

Thanks for reviewing the patch trupal218 =)

I've found a problem that is now fixed. The links to apply for the relationship with the user are now showing up properly.

However, I'm getting an error that I have no idea where it's coming from, You may not create any more relationships to this user. when trying to request a relationship. Very weird.

I've revised all the changes I'm making, and realy can't find what's going wrong. Perhaps the module maintainer can review it and figure out what's going on...

Bilmar’s picture

I am still getting the same message as well.

I think this addition will allow great flexibility for the module and I would be at the front of the line to test your patch my current site as well as on a fresh Drupal install for any future versions of the patch to give you feedback.

I hope someone will be able to take a look and comment on the issue.

Thanks!

Manuel Garcia’s picture

OK, new day, new ideas and new hope! (lol)

I think I finally got it working, problem was that the user_relationships_api_can_receive function was getting just a UID for the $requestee, and I was not validating against that to load the user if it was the case. Hence it was returning false. So now it's validating all arguments in that function properly, and should work just fine.

Note that I've only tested this with just the api and ui modules enabled, and not with all combinations, so testing would be nice from you guys =)

Let me know how it goes!

Bilmar’s picture

Awesome! I have tested your latest patch with multiple roles/users and on a Drupal fresh install as well as my current website. It looks to be working perfectly testing from end-user =D

Manuel Garcia’s picture

Status: Needs review » Reviewed & tested by the community

Great, thanks again for testing trupal218 =)

Can we get this commited?

Bilmar’s picture

Status: Needs review » Reviewed & tested by the community

Hi Manuel Garcia,

If your schedule allows, could you please take a look at feature request I raised at http://drupal.org/node/598938

I hope others will be able to test your patch soon =)

Thanks!

pritch20001’s picture

Hi, this looks great, is it going to be added to the module?

alex.k’s picture

Yep, absolutely. I totally appreciate the patch. I'd like to put out another RC and then hopefully 1.0 before adding new features. Or else we'll never get to a stable release. That's the reason there are a few patches already waiting to be included.

skizzo’s picture

Just installed latest User Relationships dev (6.x-1.x-dev 2009-11-09)
Unfortunately the patch user_relationships-327624.2 does not apply cleanly.
I would really appreciate if someone can bring it in line with the latest dev. Thx.

#patch -p0 --dry-run < user_relationships-327624.2.patch
patching file user_relationships_api/user_relationships_api.api.inc
Hunk #2 FAILED at 176.
Hunk #3 succeeded at 233 (offset 19 lines).
Hunk #5 succeeded at 332 (offset 19 lines).
Hunk #7 FAILED at 472.
2 out of 7 hunks FAILED -- saving rejects to file user_relationships_api/user_relationships_api.api.inc.rej
patching file user_relationships_api/user_relationships_api.install
Hunk #1 succeeded at 57 (offset 1 line).
Hunk #3 succeeded at 123 with fuzz 1 (offset 17 lines).
patching file user_relationships_ui/user_relationships_ui.actions.inc
Hunk #2 FAILED at 51.
Hunk #3 succeeded at 197 (offset 25 lines).
1 out of 3 hunks FAILED -- saving rejects to file user_relationships_ui/user_relationships_ui.actions.inc.rej
patching file user_relationships_ui/user_relationships_ui.admin.inc
Hunk #3 succeeded at 201 (offset 7 lines).
patching file user_relationships_ui/user_relationships_ui.admin_actions.inc
Hunk #1 succeeded at 92 (offset 7 lines).
patching file user_relationships_ui/user_relationships_ui.module
Hunk #2 FAILED at 44.
Hunk #4 succeeded at 257 with fuzz 2 (offset 8 lines).
Hunk #5 succeeded at 308 with fuzz 1.
Hunk #6 succeeded at 390 (offset 8 lines).
Hunk #7 succeeded at 685 (offset 1 line).
Hunk #8 FAILED at 815.
2 out of 8 hunks FAILED -- saving rejects to file user_relationships_ui/user_relationships_ui.module.rej
Manuel Garcia’s picture

I will bring it up to date when there is intention of actualy commiting it.
So far the maintainer wants to keep new features in stand by until they get a stable release out unfortunately.

hellomobe’s picture

Would love to see this implemented...any updates on status?

edit: I added the patch by hand to the user_relationships-6.x-1.0-rc3 version. Works great -- I just had to change the database update to 6103 not to conflict with the 1602 update. thank you Manuel!

hellomobe’s picture

Manuel - this really is fabulous. Thank you. I have found a need to allow authenticated users to receive relationship 'A', but not allow a vendor (who by default is also an authenticated user) to receive relationship 'A'. Is there a way to add this additional level of filtering?

fehin’s picture

Would also love to have this patch in 5x. Can someone please help? Thanks.

Manuel Garcia’s picture

@hellomobe: Nope, since both users have the same role assigned, they get the same settings. Only way around that is to assign every user a role when they register, and then use that for the relationship A.
See http://drupal.org/project/autoassignrole

@fehin: Sorry, but no. You should really consider upgrading to d6, as d5 will soon be go to not supported when d7 comes out.

YK85’s picture

+1 subscribing - any chance of seeing this patch added to User Relationships core module as a stable release was available after this patch was put on hold?

Sounds like a very cool feature and great work Manuel Garcia!

john.money’s picture

Patch #11 rerolled against 6.x-1.x-dev (2010-Feb-23). All credit goes to Manuel Garcia for the patch -- I only updated so it applies cleanly.

Don't forget to run update.php after applying patch.

YK85’s picture

thanks for continuing Manuel Garcia's great work!
tested and works perfectly!

can the maintainer of UR please let us know if there is a chance of seeing this in the next dev =)

thanks!

robby.smith’s picture

i had the opportunity to test the patch and it looks good
thanks for the original patch and the re-roll!

+1 for commit

Hoeven’s picture

Hello, when will an update to User Relationship module include this feature?

Thanks,
Egon

alex.k’s picture

Status: Reviewed & tested by the community » Fixed

Committed in http://drupal.org/cvs?commit=366732. Thanks to Manuel Garcia, John Money, and testers.

Manuel Garcia’s picture

awesome news alex.k -> Thanks!

Bilmar’s picture

awesome, thanks to all!

Status: Fixed » Closed (fixed)

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