Download & Extend

Unable to subscribe user from a group

Project:Organic groups
Version:7.x-1.x-dev
Component:og.module
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

After a user has subscribed to a group, they can not then unsubscribe from it. When they click the subscribe link, they go to /group/node/{nid}/unsubscribe.

<?php
function og_ungroup($gid, $entity_type, $entity, $save = TRUE) {
 
$entity = og_load_entity($entity_type, $entity);
 
$property = OG_AUDIENCE_FIELD;

  if (!empty(
$entity->{$property})) {
   
$wrapper = &$entity->{$property}[LANGUAGE_NONE];

   
$existing_key = FALSE;
    if (!empty(
$wrapper)) {
      die(
dpr($wrapper));
      foreach (
$wrapper as $key => $value) {
        if (
$gid == $value['gid']) {
         
$existing_key = $key;
          break;
        }
      }
    }
?>

Array
(
    [0] => Array
        (
            [gid] => 1
            [state] => 1
            [created] => 1323344147
        )
)

So, it's looking up the OG_AUDIENCE_FIELD attached to the user entity, checking if there is a value in it that corresponds to the group that we are trying to unsubscribe them from, and if so it will then proceed to unset that value, thus unsubscribing them from the group.

I don't fully understand the purpose of the groups audience field on the user entity, but in my case, even after subscribing to the group, this field has no value. Should it?

Comments

#1

I tried editing the user account, and manually setting the value of the groups audience field on their profile to the group that they had subscribed to. After doing that, I could unsubscribe them without issue.

So...

1) what is this Group Audience field on the User entity?

2) Why doesn't it get set when a user subscribes to a group, since it seems that the only way to unsubscribe is if this field is set correctly?

3) This group audience field on the user entity is a single value field (at least, there is a select list on the profile page, so only one value can be selected. What if a user is subscribed to more than one group?

#2

My bad - I had field permissions set on the og group audience field, and this was preventing the value being set correctly when joining a group. However, I think there should be a mechanism to prevent users from being able to join a group, if the field is not accessible - otherwise you end up with broken subscriptions that can not be unsubscribed.

#3

Category:bug report» support request
Status:active» fixed

> However, I think there should be a mechanism to prevent users from being able to join a group, if the field is not accessible

Oh, you are going to love #1342632: Deprecate OG group entity :)
http://drupalcode.org/project/og.git/commitdiff/47e458387ead217b0e4d2143...

#4

I noted that the Group field on the User object was set to only permit 1 value... which meant that the first group the user joins worked fine, but anything after that... OG couldn't add the group membership to the user object, so it couldn't remove it. Funny that the symptom is that unsubscribe links don't work, but there you go.

#5

Status:fixed» closed (fixed)

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

nobody click here