3

When my users sign up, they must choose whether they are a Man or a Woman, via a List (text) field. If a user chooses "Man", they should only be able to see Woman users on the site. Likewise, if a user chooses "Woman", they should only be able to see Man users on the site. The users cannot edit the value of this field once it is set. The user is assigned a custom user role (man or woman) when they sign up, based on what they choose from that field.

I am also open to using Profile2 with two Profile types (man and woman), but I would still need a method to restrict one profile type from viewing other users of that same profile type.

How can I set up a permission that will allow this type of access restriction? I have not been able to find a solution to solve this scenario.

  • Any feedback about my answer? – Pierre.Vriens Oct 28 '16 at 9:43
0

Check taxonomy_permissions (I think will do in combination with role assignment and has a stable release too), term_access module, Access by Term

0

I finally found a module that does the job: drupal.org/project/view_profiles_perms.

This module provides permissions to view user profiles depending on what roles the profile requested to be viewed has.

0

As an "alternative" to the View profiles permissions module you've found yourself, you could also use the Rules module for this, as explained below.

Part 1: Create a 1st rule to assign role "Woman"

  1. Rules Event: after a new user account is created

  2. Rules Conditions:

    Check the value specified for your selection list (=Man or Woman), using these conditions:

    (a) Entity has field (related to that selection list field), to make that field available to test its value. (b) Perform a data comparison, to check if the value selected was Woman.

    Refer to my answer to "How to specify a Rules condition related to select list values?" which includes a similar set of Rules conditions (though for entity "node" instead of "user" as you would need here).

  3. Rules Action: grant the role "Woman".

Part 2: Create a 2nd rule to assign role "Man"

This is similar to what's detailed in Part 1 (use "Man" instead of "Woman").

Part 3: Optionally combine both rules in a single rule

The reason why you'd need 2 rules as detailed above, is that Rules does not allow to add "Rules Conditions" within the "Rules Actions". To get around that, you may want to use the Conditional Rules module using either Conditional (if/else) or Switch logic. For more details on that, refer to my answer to "How to access rules condition values in the rule event?".

Be aware: this module only has a beta release for D7, though it's used in over 8K sites (which makes it seem like a pretty robust module though).

Video tutorials

If you're not familiar (enough/yet) with Rules, checkout the 32 (!!!) great, and free, video tutorials Learn the Rules framework.

PS: One of the advantages of using the Rules module, is that you can probably (actually: pretty sure) use it for lots of other features to implement in your site (which helps to avoid your site suffering "modulitis", aka "way too much contributed modules that slows down a site").

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.