So far the new beta version is working great.

Perhaps this is possible already, (I've been trying to make Rules do it), but is there a simple or easy way to add to this mod a way to limit not just how many relationships can be created, but how many can be received?

Right now the you can limit the requestor allowing them only so many of that type of relationship, but the requestee is infinite which provides a pretty big loophole if you're using this concept to limit access. Any thoughts?

Comments

mrf’s picture

The creation of the relationship is supposed to fail on either side if that user id has reached its limit.

If I disable the 'include pending' option, I can have an unlimited number of pending relationships, but as soon as I try to approve too many I'll get denied.

Is it possible that pending relationships are throwing this off? I don't remember testing this specific aspect recently, so its possible this is a regression in the 7.x branch.

mrf’s picture

Status: Active » Closed (works as designed)

melandren feel free to re-open this as a bug report if 'include pending' isn't working correctly for you.

dpatte’s picture

Status: Closed (works as designed) » Active

I have a relationship called administrator. Each user (requestee) should be allowed to have up to 1 administrator (requester), but any user (requester) can have multiple users they are administering (requestees).

I cannot see how to handle this with this module, or am I missing something?

Thanks

neograph734’s picture

Issue summary: View changes

The user_relationship_limits_relationship_count() function is called twice to check the requesting user and the requestee user. But the query appears to only check the requesting user as of:

$sql = "SELECT COUNT(*) FROM {user_relationships} WHERE requester_id = :uid AND rtid = :rtid";

I've managed to improve the check by changing this to:

$sql = "SELECT COUNT(*) FROM {user_relationships} WHERE (requester_id = :uid OR requestee_id = :uid) AND rtid = :rtid";

Which now throws an error if one person requests a relationship where the requestee has reached its limit. BUT only after the entry is stored in the database. Which means that if multiple people request a relationship with the same user at the same time, the check still fails and the requestee still exeeds its limit.

I tried to lock the database with lock_acquire in user_relationship_limits_user_relationships_presave(), and release it in a new function user_relationship_limits_user_relationships_save() which is called after saving the relationship. This however did not work.

The only way I got this to work was by adding

    if (!lock_acquire('user_relationship_lock')) {
      lock_wait('user_relationship_lock');
      return FALSE;
    }

to the beginning of user_relationships_save_relationship in the user_relationship.module and releasing the lock right before the return using

    lock_release('user_relationship_lock');

Since the user_relations module does not require locking I doubt we will be able to convince them to include these locks.