feat: add backfill for new permissions in super admin role during catalog seeding

This commit is contained in:
2026-07-30 12:29:58 +08:00
parent 96c20a3b1d
commit a9b89f72e9
2 changed files with 55 additions and 0 deletions

View File

@@ -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);
}