private async Task SeedDefaultPermissionsAsync( NetBooruContext context, CancellationToken cancellationToken) { if (await context.RoleClaims.AnyAsync(cancellationToken)) { return; } _logger.LogDebug( "Seeding initial role claims as none could be found"); var ownerRoleId = await context.Roles.Where( x => x.NormalizedName == PermissionConfiguration.OwnerRole) .Select(x => x.Id) .SingleAsync(cancellationToken); foreach (var permission in PermissionConfiguration.Permissions) { _ = context.RoleClaims.Add(new IdentityRoleClaim <ulong> { ClaimType = permission.Claim, RoleId = ownerRoleId }); } _ = await context.SaveChangesAsync(cancellationToken); _logger.LogDebug("Done seeding initial role claims"); }
public UploadController(ILogger <UploadController> logger, NetBooruContext dbContext, FileUploadService uploadService, UserManager <User> userManager) { _dbContext = dbContext; _logger = logger; _uploadService = uploadService; _userManager = userManager; }
private async Task SeedDefaultRolesAsync( NetBooruContext context, CancellationToken cancellationToken) { if (await context.RoleClaims.AnyAsync(cancellationToken)) { return; } _logger.LogDebug( "Seeding initial roles as none could be found"); // If not logged in, the Anonymous virtual user they occupy will be // in this role. _ = context.Roles.Add(new Role() { Id = 1, Name = PermissionConfiguration.AnonymousRole, NormalizedName = PermissionConfiguration.AnonymousRole, Deletable = false, Locked = false, Color = 0xBBBBBB }); // Has no permissions, no matter what. _ = context.Roles.Add(new Role() { Id = 3, Name = PermissionConfiguration.BannedRole, NormalizedName = PermissionConfiguration.BannedRole, Deletable = false, Locked = true, Color = 0x996666 }); // Has all permissions, no matter what. _ = context.Roles.Add(new Role() { Id = 2, Name = PermissionConfiguration.OwnerRole, NormalizedName = PermissionConfiguration.OwnerRole, Deletable = false, Locked = true, Color = 0xFFFFFF }); _ = await context.SaveChangesAsync(cancellationToken); _logger.LogDebug("Done seeding initial roles"); }
private async Task SeedDefaultUsersAsync( NetBooruContext context, CancellationToken cancellationToken) { if (await context.Users.AnyAsync(cancellationToken)) { return; } _logger.LogDebug( "Seeding initial users as none could be found"); _ = context.Users.Add(new User { Id = 1, UserName = PermissionConfiguration.AnonymousRole, NormalizedUserName = PermissionConfiguration.AnonymousRole.ToUpper(), }); _ = await context.SaveChangesAsync(cancellationToken); _logger.LogDebug("Done seeding initial users"); }
public PostsController(ILogger <PostsController> logger, NetBooruContext dbContext) { _dbContext = dbContext; _logger = logger; }