Base solution for your next web application
Open Closed

Adding permission dynamically #5083


User avatar
0
julianojs created

We have a scenario where we need to add permission dynamically. To accomplish I tried to add another authorization provider which read from DB. After the application is up, we may need more items be added dynamically. It seems PermissionManager is intiallized once only. It’s a singleton object. Can we make it transient so that every time we fetch or any other approach to solve it ? Kindly guide us with your valuable thought.


3 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    No! You can only use predefined permissions. Trying to implement a dynamic permission scenario usually shows you are in the wrong direction. Tell us your use-case

  • User Avatar
    0
    julianojs created

    We have a usecase, a module contains list of reports. Reports are dynamic , we need to add in permission before accessing this report except admin. This report set varies(not fixed) from tenant to tenant

  • User Avatar
    0
    alper created
    Support Team

    Ok. I see! Create a new entity called "ReportGrantedUsers".
    On each of your report view, put a "multiple selection" users combo. And show that users combo to only admin-role. Admin grants users to whom this report will be displayed.

    • When admin adds a user, save it to ReportedGrantedUsers table.
    • When admin removes, remove it from this table.
    • When a user logins, get the list of granted reports by UserId and show those links to the user.

    This must be implemented such a custom scenario. Dynamic permission will not work for you.

    public class ReportGrantedUsers : Entity
        {
            public string ReportName { get; set; }
    
            public int UserId { get; set; }
        }