Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Dynamic Permission #12245


User avatar
0
[email protected] created

Hi @oguzhanagir ,

We are using Asp.net Zero V 13.3.0 with.NET Core and Angular.

We have created a dynamic permission and assigned it to a role. However, we are facing an issue where we need to retrieve data from the AbpPermissions SQL table. We attempted to implement the repository pattern, but we are unable to create a repository for the AbpPermissions table. How can we retrieve records from the AbpPermissions table?

here We have created dynamic company permissions that are not defined in the AppPermissions.cs file but have been assigned to the Admin role. These permissions have been inserted as records into the AbpPermissions table, and we want to retrieve those records.


10 Answer(s)
  • User Avatar
    0
    [email protected] created

    Hi @oguzhanagir,

    Could You please any update?

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @[email protected],

    Could you check PermissionManager?

    https://aspnetboilerplate.com/Pages/Documents/Zero/Permission-Management#role-permissions

  • User Avatar
    0
    [email protected] created

    Hi @[email protected],

    Could you check PermissionManager?

    https://aspnetboilerplate.com/Pages/Documents/Zero/Permission-Management#role-permissions

    we want to get Role wise Permission AbpPermission Table record .but here not getting records.

    User role we have assigned company Permisison.AbpPermission table records is there but not got here .

  • User Avatar
    0
    [email protected] created

    Hi , this is my code i have created dynamic Permission

    public static class PermissionManagerExtensions
    {
        /// <summary>
        /// Gets all permissions by names.
        /// Throws <see cref="AbpValidationException"/> if can not find any of the permission names.
        /// </summary>
        ///        
        public static IEnumerable<Permission> GetPermissionsFromNamesByValidating(this IPermissionManager permissionManager, IEnumerable<string> permissionNames, IRepository<ModulePermission, long> modulePermissionRepository)
        {
            var permissions = new List<Permission>();
            var undefinedPermissionNames = new List<string>();
    
          var staticPermissionNames = modulePermissionRepository.GetAll()
          .Select(mp => mp.Name)
          .ToList();
    
            foreach (var permissionName in permissionNames) 
            {
                Permission permission = null;
                if (staticPermissionNames.Contains(permissionName))
                {
                    // Optionally, create a Permission object for static permissions
                    permission = new Permission(permissionName); // Adjust based on your Permission class
                }
                else
                {
                    // Check with permissionManager
                    permission = permissionManager.GetPermissionOrNull(permissionName);
                }
                if (permission != null)
                {
                    permissions.Add(permission);
                }
                else
                {
                    undefinedPermissionNames.Add(permissionName);
                }
            }
    
            if (undefinedPermissionNames.Count > 0)
            {
                throw new AbpValidationException($"There are {undefinedPermissionNames.Count} undefined permission names.")
                      {
                          ValidationErrors = undefinedPermissionNames.Select(permissionName => new ValidationResult("Undefined permission: " + permissionName)).ToList()
                      };
            }
    
            return permissions;
        }
    }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Do you get these records when you restart your app ?

  • User Avatar
    0
    [email protected] created

    Hi,

    Do you get these records when you restart your app ?

    Yes.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks. Could you share where do you use PermissionManagerExtensions ? I assume it is used inside a code block which uses caching.

  • User Avatar
    0
    [email protected] created

    Thanks. Could you share where do you use PermissionManagerExtensions ? I assume it is used inside a code block which uses caching.

  • User Avatar
    0
    [email protected] created

    Hi ismcagdas,

    my issue is i want to get records for role Admin,user etc form Abppermisison table. how to get all records from abpPermission table.

  • User Avatar
    0
    [email protected] created

    Thanks. Could you share where do you use PermissionManagerExtensions ? I assume it is used inside a code block which uses caching.

    any update ?