Open Closed

Unable to save the permission after creating it in an App Service #8410


User avatar
0
jordanchen98 created
  • ABP Framework version: v9.0.0
  • UI Type: Angular
  • Database System: EF Core (PostgreSQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

I tried to create a permission using Static Permission Definition Store and without restarting the API (Swagger) I am unable to save the permission.

When I debug it, it goes to SetAsync() in PermissionManager class the PermissionDefinitionManager cant seem to find the permission.

Here is how I insert the permission:

// Add Branch
if (branch is not null && state is not null && input.FilterFieldID.Equals(branch.Id))
{
    var branch_state = input.FilterValueParts.FirstOrDefault(x => x.ID.Equals(state.Id))?.Value.Replace(" ", "");
    var statePermission = await _permissionDefinitionManager.GetAsync(KMSv4Permissions.States.Default + "." + branch_state);

    if(statePermission is not null)
    {
        statePermission.AddChild("KMSv4.Branches." + f.Value.Replace(" ", ""), L(f.Value));
        await _staticPermissionDefinitionStore.AddPermissionDefinitionAsync(statePermission.Name, statePermission);
    }
}

// Add State
if (state is not null && input.FilterFieldID.Equals(state.Id))
{
    var statePermission = await _permissionDefinitionManager.GetAsync(KMSv4Permissions.States.Default);
    string state_permission_name = KMSv4Permissions.States.Default + "." + f.Value.Replace(" ", "");

    if (statePermission is not null)
    {
        statePermission.AddChild(state_permission_name, L(f.Value));
        await _staticPermissionDefinitionStore.AddPermissionDefinitionAsync(statePermission.Name, statePermission);
    }
}

and here is a function I created by following https://abp.io/support/questions/5490/Need-to-refresh-the-list-of-static-permission-definitions-without-site-reload?CurrentPage=1.

public class ExtendedStaticPermissionDefinitionStore : StaticPermissionDefinitionStore, IExtendedStaticPermissionDefinitionStore
 {
     public ExtendedStaticPermissionDefinitionStore(IServiceProvider serviceProvider, IOptions options) : base(serviceProvider, options)
     {
     }

     public Task AddPermissionDefinitionAsync(string key, PermissionDefinition permissionDefinition)
     {
         if (!PermissionDefinitions.ContainsKey(key))
         {
             PermissionDefinitions.Add(key, permissionDefinition);
         }
         return Task.CompletedTask;
     }
 }

 public interface IExtendedStaticPermissionDefinitionStore : IStaticPermissionDefinitionStore
 {
     Task AddPermissionDefinitionAsync(string key, PermissionDefinition permissionDefinition);
 }

Thanks!


27 Answer(s)
  • User Avatar
    0
    jordanchen98 created

    Hi,

    I tested this on my own project and its working as expected!

    Thank you so much.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great!

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09