Git Product home page Git Product logo

acl.net.core's Issues

Refactor `IsPermitted` and `IsPermittedAsync` in `ResourceManager`

Add one new override of IsPermitted and IsPermittedAsync functions.
In these methods need to call GetResourceByName or GetResourceByNameAsync

public virtual bool IsPermitted(TUser user, string resource);
public virtual async Task<bool> IsPermittedAsync(TUser user, string resource)

It's need for prevent call two methods in AclManager

var resource = resourceManager.GetResourceByName(resourceName);
return resourceManager.IsPermitted(user, resource);

Update model `User`

Add new property Name for model User and implement new override of method IsPermitted in AclManager

Change relationship `User <-> Role`

Right now: Roles contain UserId
Need to be: User contain RoleId

I think it's better because right now in table Roles be many duplicate roles, and because of this many duplicates in Resources table

Complex refactor exist code

  • Remove exist Acl.cs. Instead of this, we write AclManager who will contain only needed methods.
  • Remove Backend.cs. Instead of this, we write DataProvider who will contain only needed methods.
  • Remove Interfaces folder.
  • Remove Utils.cs.
  • Remove table/entity Permission.
  • Remove fields from tables/entities who don't need. Example: User = string[] RoleNames.
  • Remove RoleParentNotFoundException.cs

Add logic for processing array of resources (two ways)

Make new PK (Name + RoleId). (This PK can make user in his context)
It's allow situation when DB contain two resources with the same name, but with different role.

Example:

Roles:

  1. AdminRole
  2. SuperAdminRole

Resources:

  1. Name=OnlyAdminResource, RoleId = AdminRole
  2. Name=OnlyAdminResource, RoleId = SuperAdminRole

In this example, we allow only AdminRole and SuperAdminRole, to call OnlyAdminResource

Also, need to update ResourceManager in overrides which receive IEnumerable<TResource> resources need to check if these resources has the same name. This move need to prevent this situation:

Roles:

  1. UserRole
  2. AdminRole

Resources:

  1. Name=PublicResource, RoleId = UserRole
  2. Name=AdminResource, RoleId = AdminRole

User call PublicResource and AdminResource with override which receive IEnumerable<TResource> resources and receive true because least one resource allow (in this situation allowed PublicResource)

More flexibility for `AclManager`

  • Add interface IUserManager for possible override default UserManager
  • Add interface IResourceManager for possible override default ResourceManager

Add new overrides for `AclManager`

public virtual bool IsPermitted(TUser user, string resourceName)

public virtual bool IsPermitted(string userName, TResource resource)

public virtual bool IsPermitted(TUser user, TResource resource)

Add the same overrides, but for IsPermittedAsync

Update `GetResourceByName` logic

Let's use Where() function instead of FirstOrDefault here:

public TResource GetResourceByName(string resourceName)
{
return context.Resources.FirstOrDefault(r => r.Name == resourceName)
?? throw new ResourceNotFoundException(resourceName);
}
public async Task<TResource> GetResourceByNameAsync(string resourceName)
{
return await context.Resources.FirstOrDefaultAsync(r => r.Name == resourceName)
?? throw new ResourceNotFoundException(resourceName);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.