mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
Small improvements to try and mitigate #2750
This commit is contained in:
parent
da9c481bb4
commit
d834b96b4b
3 changed files with 1244 additions and 47 deletions
|
@ -87,53 +87,6 @@ namespace Ombi.Store.Context
|
|||
|
||||
public void Seed()
|
||||
{
|
||||
// VACUUM;
|
||||
Database.ExecuteSqlCommand("VACUUM;");
|
||||
|
||||
// Make sure we have the roles
|
||||
var newsletterRole = Roles.Where(x => x.Name == OmbiRoles.ReceivesNewsletter);
|
||||
if (!newsletterRole.Any())
|
||||
{
|
||||
Roles.Add(new IdentityRole(OmbiRoles.ReceivesNewsletter)
|
||||
{
|
||||
NormalizedName = OmbiRoles.ReceivesNewsletter.ToUpper()
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
var requestMusicRole = Roles.Where(x => x.Name == OmbiRoles.RequestMusic);
|
||||
if (!requestMusicRole.Any())
|
||||
{
|
||||
Roles.Add(new IdentityRole(OmbiRoles.RequestMusic)
|
||||
{
|
||||
NormalizedName = OmbiRoles.RequestMusic.ToUpper()
|
||||
});
|
||||
Roles.Add(new IdentityRole(OmbiRoles.AutoApproveMusic)
|
||||
{
|
||||
NormalizedName = OmbiRoles.AutoApproveMusic.ToUpper()
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
var manageOwnRequestsRole = Roles.Where(x => x.Name == OmbiRoles.ManageOwnRequests);
|
||||
if (!manageOwnRequestsRole.Any())
|
||||
{
|
||||
Roles.Add(new IdentityRole(OmbiRoles.ManageOwnRequests)
|
||||
{
|
||||
NormalizedName = OmbiRoles.ManageOwnRequests.ToUpper()
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
var editCustomPage = Roles.Where(x => x.Name == OmbiRoles.EditCustomPage);
|
||||
if (!editCustomPage.Any())
|
||||
{
|
||||
Roles.Add(new IdentityRole(OmbiRoles.EditCustomPage)
|
||||
{
|
||||
NormalizedName = OmbiRoles.EditCustomPage.ToUpper()
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
// Make sure we have the API User
|
||||
var apiUserExists = Users.Any(x => x.UserName.Equals("Api", StringComparison.CurrentCultureIgnoreCase));
|
||||
if (!apiUserExists)
|
||||
|
|
1212
src/Ombi.Store/Migrations/20190216224539_Roles.Designer.cs
generated
Normal file
1212
src/Ombi.Store/Migrations/20190216224539_Roles.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
32
src/Ombi.Store/Migrations/20190216224539_Roles.cs
Normal file
32
src/Ombi.Store/Migrations/20190216224539_Roles.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Ombi.Helpers;
|
||||
|
||||
namespace Ombi.Store.Migrations
|
||||
{
|
||||
public partial class Roles : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder mb)
|
||||
{
|
||||
// Make sure we have the roles
|
||||
InsertRole(mb, OmbiRoles.ReceivesNewsletter);
|
||||
InsertRole(mb, OmbiRoles.RequestMusic);
|
||||
InsertRole(mb, OmbiRoles.AutoApproveMusic);
|
||||
InsertRole(mb, OmbiRoles.ManageOwnRequests);
|
||||
InsertRole(mb, OmbiRoles.EditCustomPage);
|
||||
}
|
||||
|
||||
private void InsertRole(MigrationBuilder mb, string role)
|
||||
{
|
||||
mb.Sql($@"
|
||||
INSERT INTO AspnetRoles(Id, ConcurrencyStamp, Name, NormalizedName)
|
||||
SELECT '{Guid.NewGuid().ToString()}','{Guid.NewGuid().ToString()}','{role}', '{role.ToUpper()}'
|
||||
WHERE NOT EXISTS(SELECT 1 FROM AspnetRoles WHERE Name = '{role}');");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue