How to limit access to content to only users with the same role as the content author? I'm having trouble in my Drupal the Views and I don't really know how to solve it.

Let's suppose that we have two roles named Org1 and Org2. We can have more than one user per role so for example:


A and B belong to Org1.
C belongs to Org2.


The trouble I'm having is that I want that the content posted by A is seen by all the users in Org1 (in this case A,B) but not the users that are in Org2 (C).

How could be this made? I'm new to Drupal but not to programming in general. I've tried several modules but maybe due to my ignorance I have not been able to make it work (so any suggestion would be great). Any programatically suggestion also would be great (but it will be first time programming in Drupal 7).

What I have currently in mind and would probably solve my problem I think that is to filter by the user is logged in (if I'm user A for example filter by Org1). How could this be done?
Option 1 - Group module

You could, for sure, use the Group module for this. Group allows for creating arbitrary collections of your content and users on your site, and grant access control permissions on those collections. It is available as of D7, and has a D8 version also. The Group module creates groups as entities, making them fully fieldable, extensible and exportable.

For more details about the various roles and permissions, refer to my answer to "What are the various roles supported by the Group module?".

Resources


Community documentation for the Group module.
Video tutorial "How to use the Group module in Drupal 8 to manage editorial access control to different areas of a web site".


Option 2 - Possible alternatives

Refer to my answer to "Recommended modules for managing Content access?" for some other modules that you might want to consider as a possible alternative. Even though it's not part of your question (today), I don't think any of them have a D8 version already.