2

I use the modules "Group" and "Views" to display to the administrators of the groups, the lists of their members.

My problem :

  • user1 is the administrator of group1.
  • user2 is the administrator of group2.

When user1 goes to group2, it has access to the list of members.How limit access to the group administrator?

With the module "Organic Group" there are parameters in "Access" of the view. The "Group" module does not provide any parameters.

$view = new view();
$view->name = 'group_members';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'group_membership';
$view->human_name = 'Membres';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Liste des membres';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['use_more_text'] = 'plus';
$handler->display->display_options['access']['type'] = 'role';
$handler->display->display_options['access']['role'] = array(
  3 => '3',
  9 => '9',
);
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['submit_button'] = 'Appliquer';
$handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Réinitialiser';
$handler->display->display_options['exposed_form']['options']['exposed_sorts_label'] = 'Trier par';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['style_plugin'] = 'table';
/* Entête: Global : Texte non filtré */
$handler->display->display_options['header']['area_text_custom']['id'] = 'area_text_custom';
$handler->display->display_options['header']['area_text_custom']['table'] = 'views';
$handler->display->display_options['header']['area_text_custom']['field'] = 'area_text_custom';
$handler->display->display_options['header']['area_text_custom']['empty'] = TRUE;
$handler->display->display_options['header']['area_text_custom']['content'] = '<strong>Légende :</strong></br>
Actif = fait partie du groupe et a accès aux offres groupés.</br>
Bloqué = fait partie du groupe mais n\'a plus accès aux offres groupés.</br>
Invité = a était invité dans le groupe mais n\'a pas encore accepté l\'invitation.';
/* Pied de page: Global : Texte non filtré */
$handler->display->display_options['footer']['area_text_custom']['id'] = 'area_text_custom';
$handler->display->display_options['footer']['area_text_custom']['table'] = 'views';
$handler->display->display_options['footer']['area_text_custom']['field'] = 'area_text_custom';
$handler->display->display_options['footer']['area_text_custom']['empty'] = TRUE;
$handler->display->display_options['footer']['area_text_custom']['content'] = '<strong>Instructions :</strong></br>
<u>Pour démarrer une commande groupée :</u></br>
Étape 1 : mettre à jour la liste des membres.</br>
Étape 2 : aller sur la page du groupe et cliquer sur "Démarrer la vente".</br>
Étape 3 : compléter les dates et confirmer "Démarrer la vente".</br>
<u>Pour arrêter une commande groupée :</u></br>
Étape 1 : aller sur la page du groupe et cliquer sur "Arrêter la vente".</br>
Étape 2 : confirmer "Arrêter la vente".</br>
</br>
<i>Pour plus de détails, veuillez consulter la question suivante :</br>
lien</i>';
/* Comportement en l'absence de résultats: Global : Zone de texte */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['empty'] = TRUE;
$handler->display->display_options['empty']['area']['content'] = 'Vous n\'avez aucun membre dans votre groupe.';
$handler->display->display_options['empty']['area']['format'] = 'plain_text';
/* Relation: Adhésion au groupe : Groupe gid */
$handler->display->display_options['relationships']['group']['id'] = 'group';
$handler->display->display_options['relationships']['group']['table'] = 'group_membership';
$handler->display->display_options['relationships']['group']['field'] = 'group';
/* Relation: Adhésion au groupe : Utilisateur uid */
$handler->display->display_options['relationships']['user']['id'] = 'user';
$handler->display->display_options['relationships']['user']['table'] = 'group_membership';
$handler->display->display_options['relationships']['user']['field'] = 'user';
/* Champ: Opérations en masse : Adhésion au groupe */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'views_entity_group_membership';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '0';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['row_clickable'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
  'rules_component::rules_block_a_group_membership' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 1,
    'override_label' => 1,
    'label' => 'Bloquer les membres sélectionnés',
  ),
  'rules_component::rules_unblock_a_group_membership' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 1,
    'override_label' => 1,
    'label' => 'Débloquer les membres sélectionnés',
  ),
);
/* Champ: Groupe : ID du groupe */
$handler->display->display_options['fields']['gid']['id'] = 'gid';
$handler->display->display_options['fields']['gid']['table'] = 'groups';
$handler->display->display_options['fields']['gid']['field'] = 'gid';
$handler->display->display_options['fields']['gid']['relationship'] = 'group';
$handler->display->display_options['fields']['gid']['exclude'] = TRUE;
/* Champ: Utilisateur : Uid */
$handler->display->display_options['fields']['uid']['id'] = 'uid';
$handler->display->display_options['fields']['uid']['table'] = 'users';
$handler->display->display_options['fields']['uid']['field'] = 'uid';
$handler->display->display_options['fields']['uid']['relationship'] = 'user';
$handler->display->display_options['fields']['uid']['exclude'] = TRUE;
/* Champ: Groupe : Titre */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'groups';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['relationship'] = 'group';
/* Champ: Utilisateur : Nom */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
$handler->display->display_options['fields']['name']['label'] = 'Nom d\'utilisateur';
$handler->display->display_options['fields']['name']['exclude'] = TRUE;
/* Champ: Global : Texte personnalisé */
$handler->display->display_options['fields']['nothing_3']['id'] = 'nothing_3';
$handler->display->display_options['fields']['nothing_3']['table'] = 'views';
$handler->display->display_options['fields']['nothing_3']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing_3']['label'] = 'Nom d\'utilisateur';
$handler->display->display_options['fields']['nothing_3']['alter']['text'] = '[name]';
$handler->display->display_options['fields']['nothing_3']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['nothing_3']['alter']['path'] = 'group/[gid]/member/[uid]';
/* Champ: Utilisateur : Courriel */
$handler->display->display_options['fields']['mail']['id'] = 'mail';
$handler->display->display_options['fields']['mail']['table'] = 'users';
$handler->display->display_options['fields']['mail']['field'] = 'mail';
$handler->display->display_options['fields']['mail']['relationship'] = 'user';
$handler->display->display_options['fields']['mail']['link_to_user'] = '0';
/* Champ: Adhésion au groupe : Statut de membre */
$handler->display->display_options['fields']['status']['id'] = 'status';
$handler->display->display_options['fields']['status']['table'] = 'group_membership';
$handler->display->display_options['fields']['status']['field'] = 'status';
$handler->display->display_options['fields']['status']['label'] = 'Statut';
/* Champ: Adhésion au groupe : Group role */
$handler->display->display_options['fields']['role']['id'] = 'role';
$handler->display->display_options['fields']['role']['table'] = 'group_membership';
$handler->display->display_options['fields']['role']['field'] = 'role';
$handler->display->display_options['fields']['role']['label'] = 'Rôles';
$handler->display->display_options['fields']['role']['separator'] = '';
/* Champ: Global : Texte personnalisé */
$handler->display->display_options['fields']['nothing_2']['id'] = 'nothing_2';
$handler->display->display_options['fields']['nothing_2']['table'] = 'views';
$handler->display->display_options['fields']['nothing_2']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing_2']['label'] = 'Metadata';
$handler->display->display_options['fields']['nothing_2']['exclude'] = TRUE;
$handler->display->display_options['fields']['nothing_2']['alter']['text'] = 'metadata';
$handler->display->display_options['fields']['nothing_2']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['nothing_2']['alter']['path'] = 'group/[gid]/member/[uid]/metadata';
/* Champ: Global : Texte personnalisé */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['label'] = 'Modifier';
$handler->display->display_options['fields']['nothing']['exclude'] = TRUE;
$handler->display->display_options['fields']['nothing']['alter']['text'] = 'modifier';
$handler->display->display_options['fields']['nothing']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['nothing']['alter']['path'] = 'group/[gid]/member/[uid]/edit?destination=group/[gid]/member';
/* Champ: Global : Texte personnalisé */
$handler->display->display_options['fields']['nothing_1']['id'] = 'nothing_1';
$handler->display->display_options['fields']['nothing_1']['table'] = 'views';
$handler->display->display_options['fields']['nothing_1']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing_1']['label'] = 'Supprimer';
$handler->display->display_options['fields']['nothing_1']['exclude'] = TRUE;
$handler->display->display_options['fields']['nothing_1']['alter']['text'] = 'supprimer';
$handler->display->display_options['fields']['nothing_1']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['nothing_1']['alter']['path'] = 'group/[gid]/member/[uid]/cancel?destination=group/[gid]/member';
/* Champ: Global : Texte personnalisé */
$handler->display->display_options['fields']['nothing_4']['id'] = 'nothing_4';
$handler->display->display_options['fields']['nothing_4']['table'] = 'views';
$handler->display->display_options['fields']['nothing_4']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing_4']['label'] = 'Actions';
$handler->display->display_options['fields']['nothing_4']['alter']['text'] = '[nothing_2]   [nothing]   [nothing_1]';
/* Filtre contextuel: Adhésion au groupe : Groupe gid */
$handler->display->display_options['arguments']['group']['id'] = 'group';
$handler->display->display_options['arguments']['group']['table'] = 'group_membership';
$handler->display->display_options['arguments']['group']['field'] = 'group';
$handler->display->display_options['arguments']['group']['default_action'] = 'default';
$handler->display->display_options['arguments']['group']['exception']['title'] = 'Tout';
$handler->display->display_options['arguments']['group']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['group']['default_argument_options']['index'] = '1';
$handler->display->display_options['arguments']['group']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['group']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['group']['summary_options']['items_per_page'] = '25';
/* Critère de filtrage: Adhésion au groupe : Statut de membre */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'group_membership';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = array(
  'active' => 'active',
  'blocked' => 'blocked',
  'invited' => 'invited',
);
$handler->display->display_options['filters']['status']['exposed'] = TRUE;
$handler->display->display_options['filters']['status']['expose']['operator_id'] = 'status_op';
$handler->display->display_options['filters']['status']['expose']['label'] = 'Filtrer les membres';
$handler->display->display_options['filters']['status']['expose']['operator'] = 'status_op';
$handler->display->display_options['filters']['status']['expose']['identifier'] = 'status';
$handler->display->display_options['filters']['status']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  5 => 0,
  8 => 0,
  4 => 0,
  9 => 0,
  7 => 0,
  3 => 0,
);
$handler->display->display_options['filters']['status']['expose']['reduce'] = TRUE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'group/%/member';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Membres';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;
$handler->display->display_options['tab_options']['weight'] = '0';
$translatables['group_members'] = array(
  t('Master'),
  t('Liste des membres'),
  t('plus'),
  t('Appliquer'),
  t('Réinitialiser'),
  t('Trier par'),
  t('Asc'),
  t('Desc'),
  t('<strong>Légende :</strong></br>
Actif = fait partie du groupe et a accès aux offres groupés.</br>
Bloqué = fait partie du groupe mais n\'a plus accès aux offres groupés.</br>
Invité = a était invité dans le groupe mais n\'a pas encore accepté l\'invitation.'),
  t('<strong>Instructions :</strong></br>
<u>Pour démarrer une commande groupée :</u></br>
Étape 1 : mettre à jour la liste des membres.</br>
Étape 2 : aller sur la page du groupe et cliquer sur "Démarrer la vente".</br>
Étape 3 : compléter les dates et confirmer "Démarrer la vente".</br>
<u>Pour arrêter une commande groupée :</u></br>
Étape 1 : aller sur la page du groupe et cliquer sur "Arrêter la vente".</br>
Étape 2 : confirmer "Arrêter la vente".</br>
</br>
<i>Pour plus de détails, veuillez consulter la question suivante :</br>
lien</i>'),
  t('Vous n\'avez aucun membre dans votre groupe.'),
  t('Groupe'),
  t('Utilisateur'),
  t('Adhésion au groupe'),
  t('- Choisir une opération -'),
  t('Ajouter le rôle administrateur aux membres sélectionnés'),
  t('Bloquer les membres sélectionnés'),
  t('Supprimer les membres sélectionnés'),
  t('Supprimer le rôle administrateur des membres sélectionnés'),
  t('Débloquer les membres sélectionnés'),
  t('ID du groupe'),
  t('.'),
  t(','),
  t('Uid'),
  t('Titre'),
  t('Nom d\'utilisateur'),
  t('[name]'),
  t('Courriel'),
  t('Statut'),
  t('Rôles'),
  t('Metadata'),
  t('metadata'),
  t('Modifier'),
  t('modifier'),
  t('Supprimer'),
  t('supprimer'),
  t('Actions'),
  t('[nothing_2]   [nothing]   [nothing_1]'),
  t('Tout'),
  t('Filtrer les membres'),
  t('Page'),
);
  • I might have an idea, but need to do some "experiments" first ... patience? – Pierre.Vriens Nov 25 '16 at 18:35
  • @Pierre.Vriens OK thanks. Do you see the difference with the "Organic Group" module? It is an important functionality that maque to "Group". – user54067 Nov 25 '16 at 18:47
  • I somehow understand your last comment. I think Group is great (amazing), but still needs time to grow and become more mature. While waiting for that, the Rules module is your friend to make it do more or less what you want (which is also what my idea is about that I'm working on ...) – Pierre.Vriens Nov 25 '16 at 19:06
  • Hey Mathieu, looks like you brought up a very interesting question here, for which I found at least 1 answer (which will require custom code ...). But I think (need to do some experiments to be sure) I can aso think of a custom rule (again, sorry!) to achieve a similar result without custom code. Give me some time to "document" both approaches soon ... – Pierre.Vriens Nov 26 '16 at 10:18
  • Voilà @Mathieu ... your turn again ... have fun digesting "plan B" ... As always: feedback welcome. – Pierre.Vriens Jan 17 '17 at 18:29
0

As an alternative to the solution in my prior answer, below is a "Plan B" solution ... with no custom code at all, based on using the Rules module (and a related one).

Step 1: Add the Group ID as a required filter

Adapt your view, to add a filter, which is "(Group) Group: Group ID". Expose this filter, and make it required (if a user want to access a memberlist of a group, they must be willing to enter the group id they are asking for).

Assume you give your view a path like so: /group/memberlist. In doing so, to display the list of a members of a group (say with gid=6), the relative path of the views results for that group will become something like this: /group/memberlist?gid=6&status=active (which assumes you might want to use some other filter also, like in my example with status=active).

With that, we have everything in place to introduce some Rules logic to verify access to the views result for the requested group id (see where I'm going?)

Step 2: Enable the Rules URL Argument module

Enable the Rules URL Argument module, which will be used to create a rule (in the next step). If you wonder what this module is about, have a look at the answer to "Redirect page to existing field value".

With that, all that's left is to "capture" the value of the Group ID (following gid= in the URL of the view from Step 1), and use that to perform a validation (using Rules) to check if the user trying to access these views results does have the required Group role for the required Group id (easy, no?).

Step 3: Create a Rules Component to validate Group access

Create a Rules Component which looks like so (in Rules export format, which you should be able to import in your own site, using the Rules UI):

{ "rules_validate_access_to_a_group_role" : {
    "LABEL" : "Validate access to a Group role",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "group_id" : { "label" : "ID of group to validate", "type" : "integer" },
      "role_to_validate" : { "label" : "Role to validate", "type" : "group_role" },
      "granted_roles" : { "label" : "Granted group roles", "type" : "list\u003Cgroup_role\u003E" },
      "no_access_url" : { "label" : "No access URL", "type" : "uri" }
    },
    "IF" : [
      { "NOT list_contains" : { "list" : [ "granted-roles" ], "item" : [ "role-to-validate" ] } }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "You are not allowed to view this list of members for the group with \u003Cstrong\u003Egid=[group-id:value]\u003C\/strong\u003E (because you do not have the role \u003Cstrong\u003E[role-to-validate:label]\u003C\/strong\u003E for this group).\r\n\u003Cbr \/\u003E\r\nBelow are the roles you have been granted for the group indicated in the URL as argument value after \u0022gid=[group-id:value]\u0022" } },
      { "LOOP" : {
          "USING" : { "list" : [ "granted-roles" ] },
          "ITEM" : { "role_item" : "Current role item" },
          "DO" : [ { "drupal_message" : { "message" : "---\u003E [role-item:label]." } } ]
        }
      },
      { "redirect" : { "url" : "[no-access-url:value]" } }
    ]
  }
}

Some more details about this Rules Component:

  • It uses these parameters:
    • group_id : ID of group to validate
    • role_to_validate : Role to validate
    • granted_roles : Granted group roles
    • no_access_url : No access URL
  • The Rules Condition checks if the list of granted_roles contains the role role_to_validate. And as per the NOT part in it, the Rules Actions will be performed if that role is not in the list of roles.
  • The Rules Actions consists of 2 parts:
    • Show some Drupal messages (mostly for demo / debug purpose, feel free to remove those if you don't want them).
    • Perform a redirect to no_access_url (remember the NOT in the Rules Condition!).

Step 4: Create a Rules that invokes the Rules Component from Step 3

Create a Rules which looks like so (in Rules export format, which you should be able to import in your own site, using the Rules UI):

{ "rules_limit_access_to_group_related_views" : {
    "LABEL" : "Limit access to Group related Views",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_url_argument" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "3" : "3" } }
        }
      },
      { "data_is" : { "data" : [ "site:current-page:path" ], "value" : "group\/memberlist" } },
      { "rules_url_argument_argument_exists" : { "argument" : "gid" } }
    ],
    "DO" : [
      { "rules_url_argument_rules_action_get_argument_from_url" : {
          "USING" : { "type" : "integer", "argument_name" : "gid" },
          "PROVIDE" : { "argument_from_url" : { "gid_from_url" : "Group ID from URL" } }
        }
      },
      { "entity_fetch" : {
          "USING" : { "type" : "group_membership", "id" : [ "gid-from-url" ] },
          "PROVIDE" : { "entity_fetched" : { "group_mbmships_fetched" : "Fetched Group Memberships from URL" } }
        }
      },
      { "drupal_message" : {
          "message" : "Access to the view with URL argument \u0022gid\u0022=[gid-from-url:value] as specified in \u0022\u003Cstrong\u003E[site:current-page:path]\u003C\/strong\u003E\u0022  is only allowed if passing the \u003Cstrong\u003EGroup Access Validation\u003C\/strong\u003E implemented in the Rules Component that will now be executed.",
          "type" : "warning"
        }
      },
      { "component_rules_validate_access_to_a_group_role" : {
          "group_id" : [ "gid-from-url" ],
          "role_to_validate" : "group_admin",
          "granted_roles" : [ "group-mbmships-fetched:roles" ],
          "no_access_url" : "admin\/group"
        }
      }
    ]
  }
}

Some more details about this Rules:

  • Rules Conditions (in order specified):
    1. Check if the current user has (Drupal, not Group!) role = Administrator. This assumes your view can only be accessed by such roles. That way we don't waste Rules processing time for users who don't have access to the view at all. Feel free to adapt this condition to another role(s), or just remove it if you don't need this condition.
    2. Check if the current path matches the path of the view, which is assumed to be "group/memberlist" (adapt to fit your own path).
    3. Check if the current path includes an argument like gid= (the ID of the group for which the memberlist is to be shown, remember?). Notice that this the 1st (out of 2) reason why we're using the Rules URL Argument module.
  • Rules Actions (in order specified):
    1. Get the value specified in the current path after the argument like gid= (the ID of the group for which the memberlist is to be shown, remember?). Notice that this is the 2nd reason why we're using the Rules URL Argument module.
    2. Perform "Fetch entity by id", to get the memberships of the current user for the specified Group ID.
    3. Show a Drupal message (mostly for demo / debug purpose, feel free to remove if you don't want this).
    4. Invoke the Rules Component (from the previous step), passing it the relevant values for its parameters. If needed, adapt some of the (hardcoded) values to fit your needs, such as for role_to_validate and/or no_access_url.

Demo

  1. For a user who does have access for the requested group, the above rule will produce a message like so:

    Access to the view with URL argument "gid"=6 as specified in "group/memberlist" is only allowed if passing the Group Access Validation implemented in the Rules Component that will now be executed.

    And the actual memberlist for the requested Group ID will be shown.

  2. For a user who does NOT have access for the requested group, the above rule will produce a message like so:

    Access to the view with URL argument "gid"=6 as specified in "group/memberlist" is only allowed if passing the Group Access Validation implemented in the Rules Component that will now be executed.

    However, on top of that, an additional message like this one will be shown:

    You are not allowed to view this list of members for the group with gid=5 (because you do not have the role Administrator for this group).

    Below are the roles you have been granted for the group indicated in the URL as argument value after "gid=5"

    ---> R&D.

    ---> Sales.

    ---> Support.

    And the actual memberlist for the requested Group ID will NOT be shown. Instead, a redirect to relative path "admin/group" will be performed.

Voilà, happy Rules-ing ... with zero custom code!

| improve this answer | |
  • Thank you very much for your very detailed explanations. Is it possible to use a /group/gid/memberlist path ? – user54067 Jan 18 '17 at 12:17
  • @Mathieu : merci for the feedback. Even though I am "a bit" familiar with Rules, I've never found something similar to the Rules Argument module to use a path like group/gid/memberlist ... The only thing I can think of that may possibly be doable (not sure!), is to get another rule involved, which performs a redirect from /group/x/memberlist to /group/memberlist?gid=x (so that then the rules in my answers take care of the rest). Maybe worth a new question? FYI: I'd love to learn about a way to make such path work too! – Pierre.Vriens Jan 18 '17 at 12:26
  • I do not know, for the new question. – user54067 Jan 18 '17 at 12:39
0

Understanding the actual issue

You probably don't realize, but this question is an illustration of the (active) Group issue (feature request) about "Look into group_access query tag like node_access", for which this is the current issue summary:

Work out a query tag like node_access to prevent private groups from showing in Views, menu links, etc.

I didn't understand that issue at first (cfr my comment nr 2) in it. And even after Kristiaan (Group maintainer) added comment nr 3, it only became partially clear to me what the issue really was.

Implementing your own access validations

However, later on I stumbled on Comment nr 6 in the issue "Setting Access Restriction in Views based on Group Role", which states:

I have finally used the module "views_access_callback" and implement my own access callback function that checks if the current user belongs to a specific group's role.

So with that I understood that if you have any Views about Group entities (such as Group Memberships), then know that it's up to you to add your own access checking in your view. A possible way to do so, is to use the Views Access Callback module, which you can you in a custom module to make your view perform whatever access check you want. Obviously, for this specific case, some type of Group related permission seems appropriate.

Some more details about this Views Access Callback module (from its project page:

Provides callback-based access control for Views.

Available callback functions are defined by modules using hook_views_access_callbacks() function (in the same way as in hook_perm()), then could be set in in view's "Access restrictions" configuration.

The Community documentation for this module provides some extra details to get you goiing with this module.

There has to be an alternative to custom coding

True, with the Views Access Callback module it has to work somehow (if you wonder how, just use this link).

But there has to be another way that doesn't require custom code ... I might soon post a Plan B ...

| improve this answer | |
  • Thanks for the answer, but it sounds complicated. I'll wait for the second solution :-) – user54067 Nov 26 '16 at 20:29
  • There remains only this question – user54067 Jan 16 '17 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy