-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
239 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Text; | ||
using AnalysisData.Repository.RoleRepository.Abstraction; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.IdentityModel.Tokens; | ||
|
||
namespace AnalysisData; | ||
|
||
public class Authorization | ||
{ | ||
private readonly IRoleRepository _roleRepository; | ||
|
||
public Authorization(IRoleRepository roleRepository) | ||
{ | ||
_roleRepository = roleRepository; | ||
} | ||
|
||
public async Task ConfigureAuthorizationPolicies(IServiceCollection services) | ||
{ | ||
var goldRoles = await _roleRepository.GetRolesByPolicyAsync("Gold"); | ||
var silverRoles = await _roleRepository.GetRolesByPolicyAsync("Silver"); | ||
var bronzeRoles = await _roleRepository.GetRolesByPolicyAsync("Bronze"); | ||
|
||
services.AddAuthorization(options => | ||
{ | ||
options.AddPolicy("gold", policy => policy.RequireRole(goldRoles.ToArray())); | ||
options.AddPolicy("silver", policy => policy.RequireRole(silverRoles.ToArray())); | ||
options.AddPolicy("bronze", policy => policy.RequireRole(bronzeRoles.ToArray())); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,30 @@ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) | |
public DbSet<FileEntity> FileUploadedDb { get; set; } | ||
public DbSet<UserFile> UserFiles { get; set; } | ||
public DbSet<Category> Categories { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
base.OnModelCreating(modelBuilder); | ||
|
||
modelBuilder.Entity<Role>().HasData( | ||
new Role { Id = 1, RoleName = "admin", RolePolicy = "gold" }, | ||
new Role { Id = 2, RoleName = "Data-Analyst", RolePolicy = "bronze" }, | ||
new Role { Id = 3, RoleName = "Data-Manager", RolePolicy = "silver" } | ||
); | ||
|
||
modelBuilder.Entity<User>().HasData( | ||
new User | ||
{ | ||
Id = Guid.NewGuid(), | ||
Username = "admin", | ||
Password = ("admin"), | ||
PhoneNumber = "09131111111", | ||
FirstName = "admin", | ||
LastName = "admin", | ||
Email = "[email protected]", | ||
RoleId = 1 | ||
} | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 35 additions & 2 deletions
37
.../20240830211432_InitialCreate.Designer.cs → ...tions/20240902084123_initials.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,12 @@ | |
|
||
#nullable disable | ||
|
||
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional | ||
|
||
namespace AnalysisData.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class InitialCreate : Migration | ||
public partial class initials : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
|
@@ -231,6 +233,21 @@ protected override void Up(MigrationBuilder migrationBuilder) | |
onDelete: ReferentialAction.Cascade); | ||
}); | ||
|
||
migrationBuilder.InsertData( | ||
table: "Roles", | ||
columns: new[] { "Id", "RoleName", "RolePolicy" }, | ||
values: new object[,] | ||
{ | ||
{ 1, "admin", "gold" }, | ||
{ 2, "Data-Analyst", "bronze" }, | ||
{ 3, "Data-Manager", "silver" } | ||
}); | ||
|
||
migrationBuilder.InsertData( | ||
table: "Users", | ||
columns: new[] { "Id", "Email", "FirstName", "ImageURL", "LastName", "Password", "PhoneNumber", "RoleId", "Username" }, | ||
values: new object[] { new Guid("85906ba5-c7bb-4708-83db-46734d4adf09"), "[email protected]", "admin", null, "admin", "admin", "09131111111", 1, "admin" }); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_EntityNodes_NodeFileReferenceId", | ||
table: "EntityNodes", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,6 +239,26 @@ protected override void BuildModel(ModelBuilder modelBuilder) | |
b.HasKey("Id"); | ||
b.ToTable("Roles"); | ||
b.HasData( | ||
new | ||
{ | ||
Id = 1, | ||
RoleName = "admin", | ||
RolePolicy = "gold" | ||
}, | ||
new | ||
{ | ||
Id = 2, | ||
RoleName = "Data-Analyst", | ||
RolePolicy = "bronze" | ||
}, | ||
new | ||
{ | ||
Id = 3, | ||
RoleName = "Data-Manager", | ||
RolePolicy = "silver" | ||
}); | ||
}); | ||
|
||
modelBuilder.Entity("AnalysisData.UserManage.Model.User", b => | ||
|
@@ -282,6 +302,19 @@ protected override void BuildModel(ModelBuilder modelBuilder) | |
b.HasIndex("RoleId"); | ||
b.ToTable("Users"); | ||
b.HasData( | ||
new | ||
{ | ||
Id = new Guid("85906ba5-c7bb-4708-83db-46734d4adf09"), | ||
Email = "[email protected]", | ||
FirstName = "admin", | ||
LastName = "admin", | ||
Password = "admin", | ||
PhoneNumber = "09131111111", | ||
RoleId = 1, | ||
Username = "admin" | ||
}); | ||
}); | ||
|
||
modelBuilder.Entity("AnalysisData.EAV.Model.EntityNode", b => | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.