Closed (fixed)
Project:
Drupal Commons
Version:
7.x-3.x-dev
Component:
Email Notifications
Priority:
Major
Category:
Feature request
Assigned:
Issue tags:
Reporter:
Created:
3 Sep 2013 at 00:45 UTC
Updated:
18 Feb 2014 at 18:50 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
stevehutchison commentedok - got it working. Added this function to a custom module.
function cm_overrides_og_membership_insert(OgMembership $og_membership) {
// Get account and groups
// Only check for common_groups
if ('og_user_node' === $og_membership->field_name && 'node' === $og_membership->group_type
&& 'user' === $og_membership->entity_type) {
// Get flow flag + email flow flag
$flag = flag_get_flag('commons_follow_group');
$email_flag = flag_get_flag('email_group');
// Get account
$account = user_load($og_membership->etid);
// Flag user
$flag->flag('flag', $og_membership->gid, $account, TRUE);
$email_flag->flag('flag', $og_membership->gid, $account, TRUE);
}
}
Comment #2
ezra-g commentedThis seems like a great feature request.
Comment #3
daniel-san commentedThis would be a very helpful feature. I was just trying to figure out how to do this and came across your post. Thanks.
Scenario (in case it helps people understand why this would be helpful)
Comment #4
daniel-san commentedaccidentally duplicated when saving initial comment.
Comment #5
breity commented+1! This is a great request. And thanks a lot for override function @stevehutchison! I'm using it for now in my installation.
Comment #6
daniel-san commentedTested out custom module in comment #1 and it worked perfectly. Whether or not this feature is added to Drupal Commons, it was a great help and I appreciate you taking the time to post this for others.
For those that need info for implementing this into their own module, you need to create a custom module and use the name of the module at the beginning of the function (og_membership_insert).
Therefore, my module is name is "commons_autofollow" and so I changed the function at the beginning to:
Just in case someone needs the extra info on how to use it. Have a great day.
Dan
Comment #7
WebSinPat commentedI am using the function in #1 and it seems like it's working for me. thanks.
Just wanted to note a few points about how the timing of a user becoming a follower plays out in a couple of the scenarios:
- when a user becomes part of an open group, i suppose the og_membership is created when a user posts to the group and thus becomes a contributor. At which point, per the auto-follow function, they become a follower of the group. Depending on what the open group is, I can foresee situations where someone might want to just post once or twice but not follow everything in the group, since they might not see themselves as "joining" but rather just contributing a post. In which case they can unfollow themselves easily enough.
- in the case of joining a moderated group initiated by the user, the og_membership is created when the user requests membership which may not be at the same time the membership is approved. Per the auto-follow function, they become followers of the group immediately upon requesting membership. Which probably makes an equal amount of sense as the alternative of tying following to active status.
- for a moderated or private group when a user is added to a group by an admin, the user becomes a follower at the same time, which is just as I would expect.
In case this is helpful for anyone down the line wanting behavior similar to this feature request but needing to precisely control the timing of becoming a follower.
Comment #8
behoppe333 commented+1 for this being a feature. Thanks all for posting this code and the explanation.
Based on @websinpat's explanation, I suggest one improvement: In the case of user requesting membership in a moderated group, auto-follow should happen when the request is approved, not when the request is made.
I have a moderated group with content hidden from non-members, and I want auto-follow, and I don't want auto-follow to open up an email security hole that allows non-members to see group content. (I.e., Pending members are definitely not members.)
Comment #9
japerryThis should be easy to do. Adding it to my queue
Comment #10
behoppe333 commentedPer @daniel-san #6 I made custom module commons_autofollow and that works on my test site. (Thanks!) But when I enable the module on my production site I get a systemic "no tokens available" error which I describe here. When I disable my custom module, then tokens work again. I am not a programmer. This is my first-ever custom module. Any newbie-oriented advice appreciated.
Comment #11
WebSinPat commented@behoppe333, i'm pretty newbie too, but took a quick look, and i'm sorry but have no idea what might be going on. it's weird because the autofollow module code doesn't even seem to touch tokens. And in my case the code seems to work fine on both my dev and live sites. My only suggestions would be general ones about tracking down what might differ between your live and test sites, like: sever config differences if they are on different hosts, different modules enabled/disabled, any other code/patch differences, any config changes you made one place and not the other, etc. sorry, not very helpful.
Comment #12
tleavitt commentedIt seems that the same thing could be accomplished using Rules, rather than a custom module:
Is there any reason not to take such an approach, from a Drupal Commons perspective?
Comment #13
FunkMonkey commentedtleavitt: I was looking at doing roughly the same thing with Rules as well. We want to have everyone that creates an account to automatically Follow a couple of groups (School District News for example).
I imported the Rule you have above but it is way over my head. Do you know how I might adapt that to just Follow a specific group (or a few groups) when a user is added or edited? I've only done very simple things with Rules.
In the Conditions, the Status = Active makes sense to me. Not sure I understand the need to make sure the group is a node in the second one though. I sorta kinda think I understand part of the Actions section.
Could you provide a little more info on that Rule and how it works? Thanks.
Comment #14
tleavitt commented@FunkMonkey -
I created the rule above using the Rules UI module. The precise text I posted is a bit above my head too, in that form. ;-)
I included validation that the group is a node because that's what the flag is for, and because it seemed to be included in the originally-posted code. However, this may be unnecessary - I'm pretty new to Drupal, and don't have a great handle on the object model yet.
The rest of the rule:
* Creates a new variable of type "node" equal to the new og_membership's group - I couldn't dig any deeper in the group's properties using Rules UI, so this was necessary.
* Sets the email_group and commons_follow_group flags, same as the module in comment #1
To answer your question regarding following a specific group or groups... I suspect that a similar approach could be used with the "Fetch entity by ID" or "Fetch entity by attribute" actions available in Rules UI, instead of setting the variable equal to the group for the newly-created og_membership.
Does that make any sense?
Comment #15
FunkMonkey commented@tleavitt: Awesome! Thanks. I was also having trouble getting what I needed in the UI. Your solution makes much more sense now. I'll give the 'Fetch entity" stuff a try. I didn't read the module thoroughly.. I think that's why I didn't understand setting the email_group and commons_follow_group flags.
So, yes, that makes sense. And it probably a better solution than a custom module since it can be adapted easily for similar uses cases and can be exported.
Comment #16
WebSinPat commentedjust wanting to bump this and see the status with respect to an Official Commons Solution. I'm using a custom function as suggested in #1, which is working fine, though there are a couple of timing quirks not worked out yet as suggested in #7 and #8. I haven't tried the Rules-based solution yet to see if that handles the corner cases better.
Anyway this just seems like a pretty standard feature that I think should get into the commons codebase one way or another.
Comment #17
ezra-g commentedOur 3.9 radar is pretty full at this point, but I'd really like to see this issue resolved, so adding to our radar in the hopes we can fit it in for the next release. If someone can file a patch, that would increase the chances of this being included in 3.9 :).
Comment #18
ezra-g commentedThis seems like behavior that most users would reasonably expect, so bumping to major priority.
Comment #19
ezra-g commentedComment #20
ezra-g commentedHere's a patch for this functionality which takes into account:
- Unfollowing a group when a membership is deleted or changes status from "approved".
- Enforcing membership status (eg, blocked, pending, approved) with flagging and unflagging.
- Memberships being updated (eg, when going from one status to another)
It would be great to get a review here :).
Comment #21
WebSinPat commentedthe patch in #20 works like a dream for all the different scenarios I tried out. :)
Comment #22
ezra-g commented#20 is committed. Thanks! http://drupalcode.org/project/commons.git/commit/ca593c2