As I approached this problem when it came, it was to give each action that could be taken, or a piece of information that could be shown to it by Permission . Each User has a set of Permissions . From this, you can add other levels of structure to help manage the huge number of permissions that will exist, such as hierarchies or permission categories.
Once this is in place, you can either ask the various parts of User if they have the necessary permissions (s), or you can use the PermissionManager to take the User and the Permissions set and determine if the given user has the necessary Permissions . In any case, this will work fine, but the one you choose affects the dependencies and architecture of your system.
The PermissionManager approach has the advantage that your parts of the application should not depend on User , so you can use another PermissionManager , which always returns False if permissions do not fit, or True if all permissions fit.
For simple situations, this approach may be excessive, and it often seems to be the first, but I went the way of using basic hierarchical or coarse-grained Roles and was fond of the fact that almost every system I worked on quickly became too complicated for most vanilla, pre-built systems role-based permissions.
source share