Skip to content

Commit

Permalink
Merge pull request #426 from DigitalExcellence/hotfix/seeding
Browse files Browse the repository at this point in the history
Hotfix/seeding
  • Loading branch information
niraymak authored Apr 15, 2021
2 parents f335deb + e1caece commit e4bf00d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
3 changes: 2 additions & 1 deletion API/HelperClasses/SeedHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static void InsertUser(User seedUser, ApplicationDbContext context)
/// <param name="context"></param>
public static void SeedDataSourceWizardPages(ApplicationDbContext context)
{
foreach(DataSource dataSource in context.DataSource)
foreach(DataSource dataSource in context.DataSource.Include(wp => wp.DataSourceWizardPages))
{
if(dataSource.DataSourceWizardPages == null || !dataSource.DataSourceWizardPages.Any())
{
Expand Down Expand Up @@ -142,6 +142,7 @@ public static void SeedDataSourceWizardPages(ApplicationDbContext context)
}
}
}
context.SaveChanges();
}

}
Expand Down
26 changes: 13 additions & 13 deletions API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,20 +519,7 @@ private static void UpdateDatabase(IApplicationBuilder app, IWebHostEnvironment
context.Highlight.AddRange(Seed.SeedHighlights(projects));
context.SaveChanges();
}
if(!context.WizardPage.Any())
{
context.WizardPage.AddRange(Seed.SeedWizardPages());
context.SaveChanges();
}
if(!context.DataSource.Any())
{
context.DataSource.AddRange(Seed.SeedDataSources());
context.SaveChanges();
}

SeedHelper.SeedDataSourceWizardPages(context);


// TODO seed embedded projects
}

Expand All @@ -547,6 +534,19 @@ private static void UpdateDatabase(IApplicationBuilder app, IWebHostEnvironment
context.SaveChanges();
}
}

if(!context.WizardPage.Any())
{
context.WizardPage.AddRange(Seed.SeedWizardPages());
context.SaveChanges();
}
if(!context.DataSource.Any())
{
context.DataSource.AddRange(Seed.SeedDataSources());
context.SaveChanges();
}

SeedHelper.SeedDataSourceWizardPages(context);
}

/// <summary>
Expand Down
20 changes: 3 additions & 17 deletions Data/Helpers/Seed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,39 +521,25 @@ public static List<DataSource> SeedDataSources()
Title = "Github",
Guid = "de38e528-1d6d-40e7-83b9-4334c51c19be",
IsVisible = true,
Description = "Seeded description for the Github data source adaptee"
Description = ""
},
new DataSource
{
Title = "Gitlab",
Guid = "66de59d4-5db0-4bf8-a9a5-06abe8d3443a",
IsVisible = true,
Description = "Seeded description for the Gitlab data source adaptee"
Description = ""
},
new DataSource
{
Title = "JsFiddle",
Guid = "96666870-3afe-44e2-8d62-337d49cf972d",
IsVisible = false,
Description = "Seeded description for the JsFiddle data source adaptee"
Description = ""
}
};
}

public static User SeedAdminUser2(List<Role> roles)
{
Role adminRole = roles.Find(i => i.Name == nameof(Defaults.Roles.Administrator));

User user = new User
{
Role = adminRole,
IdentityId = "32423446",
Email = "elastic_admin@dex.software",
Name = "ElasticSearch Admin",
};

return user;
}
}

}
10 changes: 10 additions & 0 deletions IdentityServer/Quickstart/TestUsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public static List<IdentityUser> GetDefaultIdentityUsers()
Firstname = "Admin",
Lastname = "Admin",
Email = "Admin@email.com"
},
new IdentityUser
{
SubjectId = "74489498",
Username = "DeXAdmin",
Password = LoginHelper.GetHashPassword("Admin321!"),
Name = "Admin",
Firstname = "DeX",
Lastname = "Admin",
Email = "DeXAdmin@email.com"
}
};

Expand Down

0 comments on commit e4bf00d

Please sign in to comment.