We currently use implementations of hook_og_user_access_alter() in Commons Groups and Commons Wikis modules in order to allow authenticated users to post into public groups where they are not yet a member via a single autocomplete/tags style widget.

Let's refactor the field definition to instead use the approach in #1865944: Allow implementing modules to change the My/Other groups selection.

This issue replaces #1818180: Refactor og_group_ref field definition .

CommentFileSizeAuthor
#49 1961296-updating_contribs-49.patch831 bytesitamar
#47 1961296-groups_privacy_settings-47.patch52.23 KBezra-g
#47 interdiff-46-47.patch1.32 KBezra-g
#47 Screenshot_4_25_13_3_49_PM-2.png42.99 KBezra-g
#46 1961296-og-selection-handler-45.patch52.52 KBitamar
#46 interdiff-from-43.diff7.78 KBitamar
#44 1961296-og-selection-handler-43.patch51.08 KBezra-g
#44 interdiff-43.patch22.27 KBezra-g
#43 Screenshot_4_24_13_4_19_PM.png64.96 KBezra-g
#42 1961296-og-selection-handler-42.patch43.25 KBitamar
#42 interdiff-from-40.diff3.96 KBitamar
#40 1961296-og-selection-handler-40.patch43.51 KBitamar
#40 interdiff-from-38.diff1019 bytesitamar
#39 interdiff-from-37.diff1.78 KBitamar
#39 1961296-og-selection-handler-39.patch43.51 KBitamar
#37 1961296-og-selection-handler-37.patch42.88 KBamitaibu
#37 interdiff-37.txt1.22 KBamitaibu
#36 1961296-og-selection-handler-36-2.patch42.91 KBitamar
#36 interdiff-from-34.diff2.13 KBitamar
#34 1961296-og-selection-handler-34.patch41.47 KBamitaibu
#34 interdiff-34.txt885 bytesamitaibu
#33 1961296-og-selection-handler-33.patch41.34 KBamitaibu
#33 interdiff-33.txt3.25 KBamitaibu
#29 interdiff_17.diff26.26 KBitamar
#29 1961296-groups_privacy_settings-29.patch38.23 KBitamar
#25 1961296-groups_privacy_settings-25.patch39.31 KBitamar
#20 1961296-groups_privacy_settings-19.patch38.11 KBitamar
#20 diff_from_17.patch22.98 KBitamar
#17 1961296-groups_privacy_settings-17.patch20.68 KBezra-g
#16 1961296-groups_privacy_settings-16.patch26.48 KBitamar
#14 1961296-groups_privacy_settings-14.patch26.29 KBitamar
#6 1961296-group_privacy_settings-6.patch13.99 KBitamar
#5 1961296-enbale_og_access_fields-5.patch1.62 KBitamar
#4 1961296-commons-og-public-4.patch12.55 KBamitaibu
#4 Screenshot_4_9_13_12_30_PM.png79.87 KBamitaibu
#3 selection_handler-1961296.patch2.82 KBamitaibu

Comments

ezra-g’s picture

Component: Code » Groups
amitaibu’s picture

amitaibu’s picture

Status: Active » Needs work
StatusFileSize
new2.82 KB

Work in progress

amitaibu’s picture

StatusFileSize
new79.87 KB
new12.55 KB

Patch includes the WIP from #1964282: Streamline group privacy settings fieldset

The selection handler is working :)
Screenshot_4_9_13_12_30_PM.png

itamar’s picture

StatusFileSize
new1.62 KB

Patching commons to enable og_access and the OG access fields.

itamar’s picture

StatusFileSize
new13.99 KB

Patching commons_groups:

  • Adding privacy fields to groups and customizing their display.
  • Forcing content of private groups to be private.
  • Adding a selection handler for handling the privacy fields.
amitaibu’s picture

Status: Needs work » Needs review

Ready for review.

amitaibu’s picture

Status: Needs review » Needs work
+++ b/commons_groups.features.field_base.incundefined
@@ -10,6 +10,59 @@
+  $field_bases['field_privacy_settings'] = array(
  • Lets change this name to be field_og_subscribe_settings().
  • This should be moved into commons_groups_field_definition(), so it can be added dynamically to all group-content, as they are enabled.
  • When a user changes the permissions on the permissions page, this field should be synced, accordingly
+++ b/commons_groups.features.field_base.incundefined
@@ -10,6 +10,59 @@
+  $field_bases['field_private_content'] = array(

This field should be moved to commons_groups_privacy() (and all the logic related to it).

This means that we can indeed decouple #5 and move it to it's own issue. for real :)

itamar’s picture

@amitaibu The commons_groups_privacy module is not currently enabled by default. Should we enable it?

amitaibu’s picture

> Should we enable it?

No. They want to avoid having node-access if not needed.

itamar’s picture

@amitaibu There's a slight problem moving the selection handler to commons_group_privacy; The og_group_ref field defined in commons_group is supposed to use that handler.
Perhaps it should use the default OG selection handler and be switched to the group_privacy handler when group_privacy is enabled?

amitaibu’s picture

No the selection handler stays in commons-groups.
Just the private field moves to the privacy module

amitaibu’s picture

When a user changes the permissions on the permissions page, this field should be synced, accordingly

og_group_permissions field should be added on every group, and it's default to be "Override global roles and permissions", and hook_field_access() it, so it's always overridden.
When the field field_og_subscribe_settings value changes, we need to setup the permissions.

Something along the lines:

/**
 * Implements hook_node_insert().
 */
function commons_groups_node_insert($node) {
  $permission = $wrapper->field_og_subscribe_settings->value();
  $og_roles = og_roles('node', $node);

  $anon_rid = array_search(OG_ANONYMOUS_ROLE, $og_roles);

  $permissions = array(
    'subscribe' => $permission == 'join',
    'subscribe without approval' => $permission == 'approval',
  );

  og_role_change_permissions($anon_rid, $permissions);
}

Since we don't have a hook for permissions change, lets form_alter() and remove those option from the UI.

itamar’s picture

Status: Needs work » Needs review
StatusFileSize
new26.29 KB

Patch for commons_groups containing all of the above.

amitaibu’s picture

Minor nitpicks:

+++ b/commons_groups.moduleundefined
@@ -24,6 +32,58 @@ function commons_groups_entity_view($entity, $type, $view_mode, $langcode) {
+  // Wrap the privacy fields with a fieldset.

Return early, and hide field if og_access is disabled.

+++ b/commons_groups.moduleundefined
@@ -456,19 +516,88 @@ function commons_groups_default_rules_configuration_alter(&$configs) {
+ * When the node's group is private, force the node to be private.

node => node's group-content

itamar’s picture

StatusFileSize
new26.48 KB

Including fixes from #15.

ezra-g’s picture

Status: Needs review » Needs work
StatusFileSize
new20.68 KB

Thanks!

I made a few tweaks:

- Removed hard-coded field instances from commons_groups.info and instead added to commons_groups_system_info_alter():

      if (module_exists('og_access')) {
            $info['features']['field_instance'][] = "$entity_type-$bundle-field_og_subscribe_settings";
            $info['features']['field_instance'][] = "$entity_type-$bundle-field_og_access_default_value";
            $info['features']['field_instance'][] = "$entity_type-$bundle-group-group_access";
          }

- I then went to enable Commons Group Privacy module as is currently the workflow for private groups in Commons, but was unable to do so because that module conflicted with Commons Groups. Since we define the OG access control fields in Commons groups with this patch, I removed the Commons Group Privacy module entirely :). Seems like we can instead direct people to enable OG_access.module if they need group access control.

- I added a hook_update_N() implementation to update the Commons Groups feature for users upgrading from a previous version of Commons.

Before I did functional testing, I checked out the latest 7.x-2.x version of OG, meaning I tested *without* the og_group_ref() patch specified in the Commons make file.

- Then, I reverted the Commons Groups feature and created a private group, with the "Joining requires admin approval" setting.
So far, so good!

- With a second, non-admin user account, I went to the newly created private group, and saw that I was presented with a "create post" link.

However, my expectation is that as a non-member of the private group, I should *not* see the create post link when viewing a private group where I am not a member.

It's possible that this patch needs to include an update to the commons_groups_og_user_access_alter() implementation to detect group privacy properly, though my expectation is that it already properly respects group privacy. Note, I believe we still need this implementation of hook_og_user_access_alter() in order to ensure that the content creation links appear on the group homepages for non-group members. It's our new og_commons Entityreference handler that eliminates the need for the patch to OG referenced above.

- I tried to continue with additional functional testing, but when editing the group node, the radios for "Privacy settings" were all disabled/greyed out, even for user 1, so I was unable to continue functional testing,

amitaibu’s picture

+++ b/commons_groups.module
@@ -24,6 +32,64 @@ function commons_groups_entity_view($entity, $type, $view_mode, $langcode) {
+  // Block the subscription field when editing an existing group since there's
+  // currently no hook for changing the actual permissions.
+  if ($form['nid']['#value']) {
+    $form['privacy_settings']['field_og_subscribe_settings']['#disabled'] = TRUE;

I actually thought doing it the other way -- hiding those permissions from the OG-permissions page.

+++ b/commons_groups.module
@@ -217,6 +283,11 @@ function commons_groups_system_info_alter(&$info, $file, $type) {
+            $info['features']['field_instance'][] = "$entity_type-$bundle-field_og_subscribe_settings";

That field should be out-side of Og-access. It's not about access, it's about the subscribe settings (e.g. subscribe with or without approval)

bricel’s picture

Also need to send an email when a message is sent.

itamar’s picture

StatusFileSize
new22.98 KB
new38.11 KB

Re-rolling #17 - See separate diff file.

Patch removes commons_group_privacy and fixes synchronization between the subscription settings field and the relevant permissions.
Not tested at all yet.

Currently the privacy field is not created when the module is installed without og_access. I assume we'll need to add the field manually in case og_access is enabled later, right?

ezra-g’s picture

The same is true for when invitations are sent and accepted.

ezra-g’s picture

Comments #19 and 21 were meant to be on #1975198: [Meta] Trusted Contacts & Private messaging.

I assume we'll need to add the field manually in case og_access is enabled later, right?

If we can detect when og_access is enabled and do a features_revert on the field base and instance components for Commons_groups, that seems ideal.

amitaibu’s picture

> Comments #19 and 21 were meant to be on #1975198: [Meta] Trusted Contacts & Private messaging.

I was just about to write scope creep ;) @ezra can you please open a separate issue for notifications (+ explain there what "accept invitation" means)

> If we can detect when og_access is enabled and do a features_revert on the field base and instance components for Commons_groups,

@itamar, we can hook_modules_enabled() and do the features revert. We need to see the features revert is only on our module, so we don't time out.

ezra-g’s picture

I was just about to write scope creep ;) @ezra can you please open a separate issue for notifications (+ explain there what "accept invitation" means)

Yes -- Please see the referenced issue for full details :).

itamar’s picture

StatusFileSize
new39.31 KB

Re-rolling #20:

- Fixing problems in the subscription field synchronization.
- Creating the privacy field anyway and hiding it when og_access is disabled. (To avoid the need in feature revert when enabling og_access).

Notice that the patch depends on #1975844: Create hooks for notifying when OG role permissions are changed, which is already in OG's dev.

itamar’s picture

Status: Needs work » Needs review

Fixing status.

ezra-g’s picture

@itamar, Thanks for the interdiff - Super helpful!

Does #20 address the functional issues in #17?

Also, looks like some hard-coded field instances crept back into the info file - I made these dynamic with #17:

+features[field_instance][] = node-group-group_access
 features[field_instance][] = node-group-group_group
+features[field_instance][] = node-group-og_roles_permissions
ezra-g’s picture

Cross-post: I reviewed 20 as itamar posted 25 :).

itamar’s picture

StatusFileSize
new38.23 KB
new26.26 KB

Re-rolling #27:

Removing field instances declaration per #27 + Cleanup.

- With a second, non-admin user account, I went to the newly created private group, and saw that I was presented with a "create post" link.

This setting is currently synced with the subscriptions permissions and does not determine the ability to post content to the group.

ezra-g’s picture

Status: Needs review » Needs work

This setting is currently synced with the subscriptions permissions and does not determine the ability to post content to the group.

The workflow in Commons is that when a group is open for membership to all authenticated users, any authenticated user can post into the group before joining, and is automatically added as a member when she first creates a node or comment in the group.

If a group has moderated membership, we should therefore ensure that users cannot post into a group before she has joined. Marking as needs work on that basis.

I'm in #drupal-commons in IRC if you'd like to chat to clarify.

amitaibu’s picture

Status: Needs work » Needs review

This setting is currently synced with the subscriptions permissions and does not determine the ability to post content to the group.

That's wrong, the selection handler does check for this field, so settings back to needs review.

Also, note that instead of features_revert if og_access() exists, we simply hide the field if it's not in use -- IMO it's a more sane workflow.

ezra-g’s picture

The reason I marked this as "needs work" in #17, is

However, my expectation is that as a non-member of the private group, I should *not* see the create post link when viewing a private group where I am not a member.

amitaibu’s picture

StatusFileSize
new3.25 KB
new41.34 KB

However, my expectation is that as a non-member of the private group, I should *not* see the create post link when viewing a private group where I am not a member.

Overhauled commons_groups_og_user_access_alter() to look for the new changes. btw, we need to find a better term for "private" group. It's not really "Private" (i.e. node-access), it just doesn't allow users to join without approval. Maybe "Moderated groups"?

amitaibu’s picture

StatusFileSize
new885 bytes
new41.47 KB

Patch makes sure to hide the field when not needed.

amitaibu’s picture

@itamar
We actually need to act on Og-access being enabled, and add the relevant fields using og_create_field()
This should be done in 2 places:

  • hook modules enabled() -- When OG-access is enabled
  • hook_field_attach_create_bundle() -- When a new group-content is added, after OG-access is already enabled

@ezra-g, I believe those fields should not be in features, as they have specific settings for OG + we solve the problem of adding a new bundle after OG-access is enabled.

itamar’s picture

StatusFileSize
new2.13 KB
new42.91 KB

Re-rolling 34; Creating the access fields when og_access is enabled and when a new group content type is created.

amitaibu’s picture

StatusFileSize
new1.22 KB
new42.88 KB

Fix access contorl, @itamar please check.

itamar’s picture

+++ b/commons_groups.moduleundefined
@@ -415,26 +415,22 @@ function commons_groups_og_user_access_alter(&$perm, $context) {
+    // Group is public.
+    $access_create = FALSE;

I believe it should be $access_create = TRUE;

itamar’s picture

StatusFileSize
new43.51 KB
new1.78 KB

Re-rolling #37.

I made the following tests (On the patch attached here) and all worked as I expected.

With OG Access off:

Group subscription is not public - "Joining requires approval":
- Group member is able to post content and sees the post button.
- Pending / Blocked group member and non-member are unable to post nor see the post button.

Group subscription is public:
- Group member / Non-member are able to post.

OG Access is on:

Group subscription is public:
- Group member / pending member / non-member is able to post.

Group subscription is "Joining requires approval":
- Non-member is unable to post.

itamar’s picture

StatusFileSize
new1019 bytes
new43.51 KB

Re-rolling; Hiding the content access field.
I verified that the "Hide contributed content from non-members" setting changes the access setting on new group nodes.

amitaibu’s picture

Great!

@ezra-g, when testing make sure you have OG 2.x --dev

itamar’s picture

StatusFileSize
new3.96 KB
new43.25 KB

Re-rolling;
- Creating the access fields with features.
- Hiding the group access field and setting its value according to subscription settings.

ezra-g’s picture

Status: Needs review » Needs work
StatusFileSize
new64.96 KB

Thanks, itamar & amitaibu!

This is getting close. I love the revised og_user_access_alter() implementation!

I did some functional testing and discovered that the Commons_Groups field instance and field base components were not reverting.

I re-rolled the patch to resolve this, which required refactoring in several places. Note that now we define the field bases irrespective of whether og_access module is enabled -- we only define the instances when og_access is enabled.

It would be great if you could verify that this particular bit of code and the comments seem accurate:

      foreach($group_bundles['node'] as $bundle => $name) {
        // These field instances should be added to groups regardless of
        // whether og_access.module is enabled.
        $info['features']['field_instance'][] = "node-$bundle-field_og_access_default_value";
        $info['features']['field_instance'][] = "node-$bundle-field_og_subscribe_settings";
        $info['features']['field_instance'][] = "node-$bundle-og_roles_permissions";
        // These fields are only necessary when og_access.module is enabled.
        if (module_exists('og_access')) {
          $info['features']['field_instance'][] = "node-$bundle-field_og_access_default_value";
          $info['features']['field_instance'][] = "node-$bundle-group_access";
          $info['features']['field_instance'][] = "node-$bundle-group_content_access";
        }
      }

The privacy settings field seems to have the correct options, both with and without og_access enabled.

A) However, it seems that the selected option gets overridden upon node save and set to "Joining requires admin approval" regardless of the setting that is specified when creating the group.

B) When OG_Access module is enabled, I get a validation error when trying to create a group node: "Group visibility is required." This prevented me from doing further functional testing with OG Access enabled.

Screenshot_4_24_13_4_19_PM.png

C) For upgrading sites, existing public groups will need a value set for the privacy settings field. I would accept this as a followup issue.

Marking as "needs work" based on A and B.

ezra-g’s picture

StatusFileSize
new22.27 KB
new51.08 KB

Now with even more patch.

amitaibu’s picture

Sorry about #43.
#44 doesn't install properly, we are working on fixing the issue and submit a patch later on. Stay tuned.

itamar’s picture

Status: Needs work » Needs review
StatusFileSize
new7.78 KB
new52.52 KB

Fixing points A and B from #43.
Notice that when enabling OG access from the UI, the fields do not revert properly, but that was also the case for me with patch #43. When enabling OG access from drush, the fields revert but the instances are shown as overridden in the features overview even though they aren't.

ezra-g’s picture

Status: Needs review » Needs work
StatusFileSize
new42.99 KB
new1.32 KB
new52.23 KB

Thanks!

I re-rolled 46 to address the fields that wouldn't revert.

Two remaining functional problems:

A) The "Privacy settings" field value is still overridden on the first save of a group node.

B) When a non-member attempts to post into a public group, the node title isn't present in the autocompelte widget and there is no form validation error, but the resulting node isn't posted into any group.

I would expect either a validation error, or success posting into the target group. I believe you can reproduce this by following a "create [content]" link from any public group node with the patch applied.

Screenshot_4_25_13_3_49_PM-2.png

itamar’s picture

@ezra-g I couldn't reproduce the privacy settings being overridden (A);
I'm able to create groups with "privacy settings" set to " Anyone can join" and it doesn't get overridden to "Joining requires admin approval". And so is the case when editing existing groups.
I tried both possibilities with and without og_access. Can you give me an advice on how to reproduce it?

itamar’s picture

StatusFileSize
new831 bytes

B) When a non-member attempts to post into a public group, the node title isn't present in the autocompelte widget and there is no form validation error, but the resulting node isn't posted into any group.

I verified that this problem disappears when OG and Entityreference-prepopulate are updated to their latest releases. The attached patch updates them.

I'm leaving status as needs work because of #48.

ezra-g’s picture

I'm able to create groups with "privacy settings" set to " Anyone can join" and it doesn't get overridden to "Joining requires admin approval". And so is the case when editing existing groups.
I tried both possibilities with and without og_access. Can you give me an advice on how to reproduce it?

I'll try again with the Entityreference_Prepopulate 1.3 and OG 7.x-2.x dev on a fresh install of Commons.

ezra-g’s picture

I am still able to reproduce on a fresh install.

For reference, I'm testing with a fresh installation of Commons using the HEAD of the 7.x-3.x branch of Commons Groups, switching to the patch from #47, running drush cc all, drush updatedb and doing node/add/group as user 1.

I create a group with the "Anyone can join" and upon editing the new group node the Privacy settings value is instead set to " Joining requires admin approval".

itamar’s picture

Status: Needs work » Needs review

@ezra-g I created a fresh installation from 7.x-3.x (But with OG and entityreference-prepopulate updated to their latest releases), and then performed exactly what you described on #51, and the group stayed as "Anyone can join".
So I'm assuming also this problem disappears with the latest OG and entityreference-prepopulate.

ezra-g’s picture

Status: Needs review » Fixed

I tested #47 again after building Commons with build-commons-dev.make and replacing OG and Entityreference_Prepopulate to their latest official releases, and this is working as expected now.

I tweaked commons_groups_modules_enabled() to revert the field bases before the instances so that the updated base definition will take effect and committed.

Thanks, itamar and amitaibu!

http://drupalcode.org/project/commons_groups.git/commit/7d0c734

ezra-g’s picture

Followup to remove group privacy module that I missed in the previous commit: http://drupalcode.org/project/commons_groups.git/commit/473eaa3.

ezra-g’s picture

@itamar/@amitaibu: Will it be necessary to update group nodes on existing Commons sites to set values for the fields added in this issue?

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