2

I have two Profile2 profile types, and each one automatically applies a specific user role to the user account:

  1. Man
  2. Woman

All users have the ability to add a specific type of node... let's call it "Event".

Man users should never see other Man-user-created events. They should only see Woman-user-created events

Woman users should never see other Woman-user-created events. They should only see Man-user-created events.

I already have the permissions set up where Man users cannot view other Man user profile pages, and likewise for Woman users. How can I apply that same logic/permission restriction to the content those user types create?

3

Just tried this in my sandbox. You can do this by using Content Access together with Rules. The configuration would go like this:

  • Activate the following modules: Rules, Content Access and Content Access Rules Integrations (a submodule of Content Access)
  • On your content type - Event - under Access Control, activate "Enable per content node access control settings"
  • Create two new Rules:
    1. For content created by a member of the Men role:
      • Event: After saving new content of type Event
      • Condition: User has role(s), Parameter: User: [node:author], Roles: men
      • Action: Revokes Access to the newly created node for the role men. To do that check all but "women" in the "Role-based access control settings" > "View any content" acl group
    2. For content created by a member of the Women role:
      • Event: After saving new content of type Event
      • Condition: User has role(s), Parameter: User: [node:author], Roles: women
      • Action: Revokes Access to the newly created node for the role women. To do that check all but "men" in the "Role-based access control settings" > "View any content" acl group

Once these Rules are in place, any new content of type Event will have an ACL configuration (per node) that will block members of the same role and allow members of the opposite role to view it. You would probably need to tweak this more to match your goals but this should get you going.

Hope it helps!

  • Awesome solution. It worked great! The only two things I changed were the following: (1) I edited the access control settings for the node type (admin/structure/types/manage/event/access) so that Admin was the only role with any remaining permissions. (2) I used the "Grant Access By Role" action in the rule to add the "View: Men" permission for nodes created by Women, and vice versa. Thanks! – hockey2112 Feb 29 '16 at 19:17
  • Great to hear it worked! Btw, your configuration sounds even simpler than my original suggestion! – Stefanos Petrakis Feb 29 '16 at 19:20
1

Have a look at my answer to the (= your ...) question about "How to control content access based on value of a List (text) field in user profile?".

Replace the roles in that answer like so:

  • Change Woman to NoWomanAllowed.
  • Change Man to NoManAllowed.

With that you should be close to an answer for your question here.

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.