From the short content creation form on a group homepage, I click to "go to full form". The url is node/add/post?og_group_ref=6 but the group reference field is not populated. I would expect the field to be prepopulated. I am able to type in the name of the expected group into the groups reference field and it appears as an autocomplete suggestion.

Marking as critical since this could cause users to mistakenly think they are posting content into a group when in fact the content is getting posted site-wide.

Comments

RobKoberg’s picture

In commons_bw_partial_node_form, you simply need to add a query param for og_group_ref=$group_id

ezra-g’s picture

@RobKoberg, I'm not sure that I follow how what you're proposing would fix the problem. Can you file a patch with your proposed changes?

ezra-g’s picture

I'm able to reproduce this with some groups but not others. With the default content installed with Commons, I can reproduce on the Engineering group, but not the Boston group.

devin carlson’s picture

@ezra-g I'm not able to reproduce this on a fresh install with any of the post types and any of the default groups (engineering team, Boston, New York City) or any custom groups I create.

RobKoberg’s picture

Sorry... I see what you are saying (og_group_ref is already being set). On a dev build from about a half hour ago, I can reproduce with the engineering group too, but not Boston. Doesn't really make sense. The only difference I see between the groups is the one that is not prepopulating has admin as the author.

Creating a new group as a regular user, then set to published as admin, and back as a regular user using the Go to full form *does* prepopulate.

Here is were it does not work (seems like any group created by the admin user):
* If I create a group as admin, and in the same form instance set the group to be published, (or not, doesn't matter)
* if you did not publish, publish the group
* then as a regular user, going to full form *does not* prepopulate
* It does prepopulate when going to full form as admin. I also unpublished and republished the group. The regular user still does not get the group prepopulated.

As I said, it does not make sense as the og_group_ref query param is there and set correctly in the query string. Not sure why an admin created group has this problem?

devin carlson’s picture

Okay, I can now duplicate this using the steps outlined by RobKoberg in #5. The key is creating the group as an admin, publishing it and then, as a regular user, going to the full form.

ezra-g’s picture

Assigned: Unassigned » ezra-g
ezra-g’s picture

Some initial triage:

In commons_groups_entityreference_default_value(), the value is correctly set from the URL as far as $ids around line 584ish, but group IDs are not passed onto the $items array because the og_user_access($target_type, $target_id, "create $entity->type content") conditional is coming back false.

In commons_groups_og_user_access_alter(), we check if the user is a member of the group specified for prepopulation: if (og_is_member($group_type, $group->nid, 'user', $account)) {.

Note, separately from the present issue, I believe this should actually specify the active membership type, rather than any membership type.

In my environment, I'm testing with the default content user "Lisa Rex" whose uid is 6. Lisa only gets successful URL prepopulation with group 1. Not surprisingly, that's the only group of which she is a member:

select * from og_membership where entity_type = 'user' and etid = 6 and group_type = 'node';
+----+----------------------------+------+-------------+-----+------------+-------+------------+--------------+----------+
| id | type | etid | entity_type | gid | group_type | state | created | field_name | language |
+----+----------------------------+------+-------------+-----+------------+-------+------------+--------------+----------+
| 12 | og_membership_type_default | 6 | user | 1 | node | 1 | 1374700268 | og_user_node | en |
+----+----------------------------+------+-------------+-----+------------+-------+------------+--------------+----------+

The group permissions appear to be the same for all groups on the site: non-members don't have "Create Post content" in the UI, though it appears in commons_groups_og_user_access_alter(), we do dynamically assign users the "create $type content" permission when field_og_subscribe_settings is set to "anyone". It seems like this should be reflected in the group permissions UI and the relevant checkboxes disabled if we're going to override their values from what users set.

In commons_groups_og_permission_alter(), we override the names of the "subscribe" and "subscribe without approval" permission to use the word "contribute" instead of subscribe.

I was expecting to see "contribute without approval" granted to all roles for groups where field_og_subscribe_settings is set to 'anyone' but that's not the case.

ezra-g’s picture

Status: Active » Needs review
StatusFileSize
new1.46 KB

This patch resolves the issue by granting the "subscribe" and "subscribe without approval" permissions via hook_og_user_access_alter() when group visibility is set to "anyone".

This resolves the missing prepopulation and, in my testing, preserves group access restrictions on prepopulation (eg, the site won't prepopulate a group that you don't have access to contribute to). It would be great to get more functional testing on this. Related: We need better test coverage.

Re:

we do dynamically assign users the "create $type content" permission when field_og_subscribe_settings is set to "anyone". It seems like this should be reflected in the group permissions UI and the relevant checkboxes disabled if we're going to override their values from what users set.

, this would be ideal, but is best left for a followup issue, mainly since hook_og_permission_alter() doesn't provide a way to detect the group entity whose permissions we're configuring. We could certainly discover this through the menu system but that adds enough complexity and isn't critical, thus addressing in a followup issue.

japerry’s picture

Status: Needs review » Needs work
StatusFileSize
new195.27 KB

It looks like there might be some caching issues going on here with the default value. Look at the screenshot below for more information.

japerry’s picture

Status: Needs work » Needs review
StatusFileSize
new2.82 KB

The following patch does the check during the default value function, due to some odd caching issues that produces unreliable results (wrong group IDs getting referenced during the og_access_alter check).

When we do these checks, permissions are followed just for the visible groups. Private and moderated groups will show access denied as usual. Also you can pass in multiple ids to the og_group_ref variable and it'll only pass through the ones that should have access.

dstol’s picture

Status: Needs review » Reviewed & tested by the community

Given the instructions in #5, the patch in #11 solves the pre-population problem.

ezra-g’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.87 KB

due to some odd caching issues that produces unreliable results (wrong group IDs getting referenced during the og_access_alter check

Thanks for the debugging here, japerry!

+++ b/commons_groups.moduleundefined
@@ -577,14 +579,27 @@ function commons_groups_entityreference_default_value($entity_type, $entity, $fi
-      && og_is_group_type($target_type, $target->type)
-      && (og_user_access($target_type, $target_id, "create $entity->type content") || og_user_access($target_type, $target_id, "update any $entity->type content"))) {
+      && (og_user_access($target_type, $target_id, "create $entity->type content")
+        || og_user_access($target_type, $target_id, "update any $entity->type content")

From my perspective, we should either be able to rely on the results of og_user_access() in all cases or not at all. If we think that function is overly restrictive due to caching, then it seems possible that the opposite is true and that the same caching may allow for privilege escalation. Changing the criteria we use to check for access in one place doesn't seem viable here because we'd have to do similar changes before every call to og_user_access().

+++ b/commons_groups.moduleundefined
@@ -577,14 +579,27 @@ function commons_groups_entityreference_default_value($entity_type, $entity, $fi
+  if(!entity_load($target_type, $ids))
+    return $items;

Coding standards for conditionals (brackets, spacing).

Attached is a re-roll of #9 that also removes our $cache = &drupal_static(__FUNCTION__, array());. This is an artifact of #2019137: Saving a group as "Anyone can join" is saved as "Joining requires admin approval" and I believe it's no longer necessary. In my testing I'm not observing issues that japerry identified in #10 with prepopulate or related values being cached, but it would be great to get some validation of that (as well as general og_user_access() restriction smoke testing).

RobKoberg’s picture

I am still not seeing groups get prepopulated after applying the patch in #13. In fact, auto complete is not finding my group. When I use the partial node form, the group does get associated.

RobKoberg’s picture

Also, when going to the full edit page for a node created with the partial node form (where a group was associated), the group is not added to the form. I think this might have been part of the problem with Cannot create public content in a moderated group

debugging...

ezra-g’s picture

I think this might have been part of the problem with Cannot create public content in a moderated group

Agreed. Both issues are related to the user and node access systems, which appear to be malfunctioning in your Commons implementation in ways that can't be reproduced in a stock Commons install. #2057961: Cannot create public content in a moderated group has been marked has "cannot reproduce" so "needs review" still seems like the appropriate status here.

RobKoberg’s picture

This was caused by some weirdness in my features after disabling Trusted Contacts. My content types had the og_user_group_ref still in, but that was not being handled by trusted contacts anymore. The patch works as expected.

ezra-g’s picture

Status: Needs review » Fixed
ezra-g’s picture

Documenting that this led to the regression: #2060633: Access denied following "Join" group link.

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