Ends in:
2 DAYS
4 HRS
23 MIN
24 SEC
Ends in:
2 D
4 H
23 M
24 S
Open Closed

Unable to assign Permission after added in Static Permission #8407


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 have followed this tread https://abp.io/support/questions/5490/Need-to-refresh-the-list-of-static-permission-definitions-without-site-reload?CurrentPage=1 and I've managed to get the permission to show up in my roles.

Here is a quick simple flow of what I want to do. I have module to create either a branch or a state and I would like it directly tied to permissions. So, meaning a role can have several branches/states (permission). When I create a branch/state, it should show up in my permissions for me to assign under roles.

Here is where I create a branch.

and it does show up after I created the branch, without actually needed to restart the API. But it is showing up at the bottom, it should be under 'States' Like the above as its parent is under 'Pulau Pinang'. From what I got is that it is correctly assigned but somehow not showing up properly under its parent state. This is fixed if I restart the API(Swagger), is there anyway where I don't have to restart the API?

The more crucial issue here is when I check that permission and save it. It does not save it. 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 followed in the thread mentioned above.

 public class ExtendedStaticPermissionDefinitionStore : StaticPermissionDefinitionStore, IExtendedStaticPermissionDefinitionStore
 {
     public ExtendedStaticPermissionDefinitionStore(IServiceProvider serviceProvider, IOptions<AbpPermissionOptions> 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!


10 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The permission group and permissions get from

    https://github.com/abpframework/abp/blob/dev/modules/permission-management/src/Volo.Abp.PermissionManagement.Application/Volo/Abp/PermissionManagement/PermissionAppService.cs#L35-L107

    You can debug this app service to see the data.

    The more crucial issue here is when I check that permission and save it. It does not save it.

    Please create a new question for this.

    Thanks.

  • User Avatar
    0
    jordanchen98 created

    Hi,

    I've got this from https://github.com/abpframework/abp/blob/dev/modules/permission-management/src/Volo.Abp.PermissionManagement.Application/Volo/Abp/PermissionManagement/PermissionAppService.cs#L35-L107

    its correct, just that in the UI its not displaying correctly unless I restart the API (swagger)

  • User Avatar
    0
    jordanchen98 created

    Hi,

    I have created a new ticket for the other issue here https://abp.io/support/questions/8410/Unable-to-save-the-permission-after-creating-it-in-an-App-Service

    Thanks!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    its correct, just that in the UI its not displaying correctly unless I restart the API (swagger)

    Can you check the JSON data in the browser(angular)?

    Get api/permission-management/permissions?providerName=x&providerKey=y

  • User Avatar
    0
    jordanchen98 created

    Hi,

    I've created a state called Testing State. It seems to be correct, just that its way below, is this related to how it is arranged?

    I've attached the JSON data: https://drive.google.com/file/d/1akHeDGJqxGQkzHsUUV5UkL-fM-GrzGu9/view?usp=sharing

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Does it mean the angular UI page shows the data in the wrong order?

    If so, I will ask our angular team.

  • User Avatar
    0
    jordanchen98 created

    Yes it is, it is under not under the parent

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    ok. I will ask our angular team.

  • User Avatar
    0
    jordanchen98 created

    Thanks!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35