Open Closed

Determination of Permissions to Role On Data Seeding #8451


User avatar
0
omer_yel created
  • ABP Framework version: v8.2.0
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

Hi. I try to add custom role and set permission for that role. I have researched related creating seed data for customer role and permission. There are some solutions for creating role as seed data and adding all permission into that role. But I want to create several roles other than admin role like standard and basic. Furthermore i want to set specific permissions to them.

Can i define role on this class in order to separate permissions? Shortly I want to - create multiple role as seed data - specify permission for each role while seeding them

<br>


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

    hi

    You can add a IDataSeedContributor class and get all permissions, then seeder for a specific role(Line 37).

    https://github.com/abpframework/abp/blob/dev/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDataSeedContributor.cs#L10-L41

  • User Avatar
    0
    omer_yel created

    I have seen this. At line 38, it assigns all permission into custom given role. I also want to choose permission from all permission list. Then assign only chosen ones. Is there a practical way to choose permission?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can add your logic to filter the permission definitions(permissionNames).

    var permissionNames = (await PermissionDefinitionManager.GetPermissionsAsync())
        .Where(p => p.MultiTenancySide.HasFlag(multiTenancySide))
        .Where(p => !p.Providers.Any() || p.Providers.Contains(RolePermissionValueProvider.ProviderName))
        .Select(p => p.Name)
        .ToArray();
    
  • User Avatar
    0
    omer_yel created

    Thank you We solved the problem in a different way.

  • 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