feat: add backfill for new permissions in super admin role during catalog seeding
This commit is contained in:
@@ -209,6 +209,25 @@ public sealed class BuiltinBackofficeCatalogSeeder(TikuDbContext dbContext)
|
||||
IsActive = true
|
||||
}));
|
||||
|
||||
var superAdminRoleId = await dbContext.PlatformBackendRoles.AsNoTracking()
|
||||
.Where(role => role.Code == PlatformAdminBootstrapper.SuperAdminRoleCode && role.IsSystem)
|
||||
.Select(role => (Guid?)role.Id)
|
||||
.SingleOrDefaultAsync(cancellationToken);
|
||||
if (superAdminRoleId.HasValue)
|
||||
{
|
||||
var boundPermissionCodes = await dbContext.PlatformBackendRolePermissions.AsNoTracking()
|
||||
.Where(binding => binding.RoleId == superAdminRoleId.Value)
|
||||
.Select(binding => binding.PermissionCode)
|
||||
.ToHashSetAsync(StringComparer.Ordinal, cancellationToken);
|
||||
dbContext.PlatformBackendRolePermissions.AddRange(BackendPermissions.Platform
|
||||
.Where(code => !boundPermissionCodes.Contains(code))
|
||||
.Select(code => new PlatformBackendRolePermission
|
||||
{
|
||||
RoleId = superAdminRoleId.Value,
|
||||
PermissionCode = code
|
||||
}));
|
||||
}
|
||||
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user