109 Security: All Views of the app - chempkovsky/CS82ANGULAR GitHub Wiki
- Run JavaScript Wizard
- First page of the Wizard
- Second page of the Wizard
- Third page of the Wizard
- Fourth page of the Wizard
- Fifth page of the Wizard
- Sixth page of the Wizard
Security has two aspects: Authentication and Authorization
- in the article 104 we created the
aspnetmodel
-table. This table should be used to persist all Views of the application. - read the following article as reminder.
- populating the
aspnetmodel
table with data can be time-consuming. On the other hand, it's easy to misspell a title or forget a View. -
30000-AllModelViews.sql
-script can be used to generate the names along with Sql-code (and C# code) which inserts data in the database table.-
JavaScript Wizard
must be used to run the script. - The script must be run for each Dbcontext of the application.
-
- There is no script for the Features. Thus, Features must be inserted by hands.
- right click any subfolder of any project of the app.
- for example,
Controllers
-folder of thePhBkControllers.csproj
-project
- for example,
- select
JavaScript Wizard
-menu item
- click
Next
-button on the first page
- select the project and Dbcontext for which to run the script
- for example,
PhBkContext.csproj
-project andPhbkDbContext
-dbcontext
- for example,
- click
Next
-button
- select any View of the Dbcontext
- for example,
PhbkPhoneView
- for example,
- click
Next
-button
- in
Select Action Type
-combo box, select30000-AllModelViews.sql
- click
Next
-button
- select
AllModelViews.sql.t4
-template - inside Edit-window
- modify the values for
int startFromId=...
string insertSql=...
string insertCode=...
- modify the values for
- click
Next
-button
Click to show the picture
- copy fragment of the generated code in the clipboard.
Click to show the picture
-
here is a list of Database Contexts of the app
-
PhbkDbContext
-context of thePhBkContext.csproj
-project -
aspnetchckdbcontext
-context of thePhBkContext.csproj
-project -
AspNetRegistrationDbContex
-context of thePhBkContext.csproj
-project. Do not generate. It repeats the Views ofaspnetchckdbcontext
. -
LpEmpPhBkContext
-context of theLpPhBkContext.csproj
-project. Do not generate. It repeats the Views ofPhbkDbContext
. -
LpPhbkDbContext
-context of theLpPhBkContext.csproj
-project. Do not generate. It repeats the Views ofPhbkDbContext
. -
LpPhnPhBkContext
-context of theLpPhBkContext.csproj
-project. Do not generate. It repeats the Views ofPhbkDbContext
.
-
-
Here is a result. We will insert the generated code in the
OnModelCreating
-method of theaspnetchckdbcontext
-context
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 1, ModelName = "PhbkPhoneTypeView", ModelDescription="Phone Type" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 2, ModelName = "PhbkEnterpriseView", ModelDescription="Enterprise" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 3, ModelName = "PhbkDivisionView", ModelDescription="Division" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 4, ModelName = "LpdDivisionView", ModelDescription="Division Name" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 5, ModelName = "LprDivision01View", ModelDescription="Division Name ref01" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 6, ModelName = "LprDivision02View", ModelDescription="Division Name ref02" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 7, ModelName = "PhbkEmployeeView", ModelDescription="Employee" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 8, ModelName = "LpdEmpLastNameView", ModelDescription="Last Name" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 9, ModelName = "LpdEmpFirstNameView", ModelDescription="First Name" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 10, ModelName = "LpdEmpSecondNameView", ModelDescription="Second Name" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 11, ModelName = "LprEmployee01View", ModelDescription="Employee Dict Ref" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 12, ModelName = "LprEmployee02View", ModelDescription="Employee Dict Ref" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 13, ModelName = "PhbkPhoneView", ModelDescription="Phone" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 14, ModelName = "LpdPhoneView", ModelDescription="Phone" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 15, ModelName = "LprPhone01View", ModelDescription="Phone Dict Ref" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 16, ModelName = "LprPhone02View", ModelDescription="Phone Dict Ref" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 17, ModelName = "LprPhone03View", ModelDescription="Phone Dict Ref" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 18, ModelName = "LprPhone04View", ModelDescription="Phone Dict Ref" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 19, ModelName = "aspnetmodelView", ModelDescription="Model" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 20, ModelName = "aspnetroleView", ModelDescription="Role" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 21, ModelName = "aspnetrolemaskView", ModelDescription="Role Mask" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 22, ModelName = "aspnetuserView", ModelDescription="User" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 23, ModelName = "aspnetusermaskView", ModelDescription="User Mask" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 24, ModelName = "aspnetuserpermsView", ModelDescription="User perm" });
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 25, ModelName = "aspnetuserrolesView", ModelDescription="User Role" });
// features
modelBuilder.Entity<aspnetmodel>().HasData(new { ModelPk = 26, ModelName = "SimpleDictionaryFtrComponent", ModelDescription = "Simple feature" });
////////////////////////////////////////////// Roles //////////////////////////////////////////////
for (int i = 1; i < 26; i++)
{
modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "AdminRole", RoleDescription = "AdminRole", ModelPkRef = i, Mask1 = true, Mask2 = true, Mask3 = true, Mask4 = true, Mask5 = true });
}
// features
modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "AdminRole", RoleDescription = "AdminRole", ModelPkRef = 26, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
// 1 "PhbkPhoneTypeView"
modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 1, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = true });
// 2 "PhbkEnterpriseView"
modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 2, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
// 3 "PhbkDivisionView"
modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 3, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
// 7 "PhbkEmployeeView"
modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 7, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
// 13 "PhbkPhoneView"
modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 13, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });
// features
modelBuilder.Entity<aspnetrolemask>().HasData(new { RoleName = "GuestRole", RoleDescription = "GuestRole", ModelPkRef = 26, Mask1 = true, Mask2 = false, Mask3 = false, Mask4 = false, Mask5 = false });