You can do it like has implemented in Active Directory, instead of creating a new table(entity) for each Access level group you can create only one where you will store Accees level groups Admin , Doctor , Patient
, and so on. And include IdenetityUser
to any group ...
Of course, each group should have some roles.
For example - model:
public class BaseGuidIdTable
{
[Key]
public Guid Id { get; set; }
}
public class SecurityGroupRole: BaseGuidIdTable
{
public string Role { get; set; }
public string Description { get; set; }
}
public class SecurityRight: BaseGuidIdTable
{
public string Right { get; set; }
public string Description { get; set; }
}
public class SecurityGroupAccess: BaseGuidIdTable
{
public Guid GroupId { get; set; }
[ForeignKey(nameof(GroupId))]
public SecurityGroupRole GroupRole { get; set; }
public Guid RightId { get; set; }
[ForeignKey(nameof(RightId))]
public SecurityRight Right { get; set; }
}
Add some data :
builder.Entity<SecurityGroupRole>().HasData(
new SecurityGroupRole
{
Id = new Guid(OwnerGuidTxt),
Role = "Doctor",
Description = "Doctor"
},
new SecurityGroupRole
{
Id = new Guid(AdminGuidTxt),
Role = "Admin",
Description = "Admin"
},
new SecurityGroupRole
{
Id = new Guid(UserGuidTxt),
Role = "Patient",
Description = "Patient"
}
);
builder.Entity<SecurityRight>().HasData(
new SecurityRight
{
Id = new Guid(AddDeleteNewUsers),
Right = "AddDeleteNewUsers",
Description = "Add or delete Users"
},
new SecurityRight
{
Id = new Guid(PasswordChangeYourself),
Right = "PasswordChangeYourself",
Description = "Can password change by yourself"
},
new SecurityRight
{
Id = new Guid(ViewAll),
Right = "ViewAll",
Description = "Can view all objects"
},
new SecurityRight
{
Id = new Guid(CanChangeTags),
Right = "CanChangeTags",
Description = "Can change tags"
}
);
new SecurityGroupAccess {Id = new Guid("DD4C2CC3-65E2-4DD1-A620-723B5ADB8758"), GroupId = ownerGroupGuid, RightId = new Guid(AddDeleteNewUsers) },
new SecurityGroupAccess { Id = new Guid("23CD8B4E-A572-4335-B1EF-2EF115E14947"), GroupId = ownerGroupGuid, RightId = new Guid(PasswordChangeYourself) },
new SecurityGroupAccess { Id = new Guid("6A6A3A41-1103-46BD-B482-AB59903172D9"), GroupId = ownerGroupGuid, RightId = new Guid(ViewAll) },
new SecurityGroupAccess { Id = new Guid("EB133F40-AB3B-4094-9AE7-EF6FD853F36B"), GroupId = ownerGroupGuid, RightId = new Guid(CanChangeTags) },
new SecurityGroupAccess { Id = new Guid("29EE3EDA-08ED-46F1-9EF7-79A2D4021E86"), GroupId = adminGroupGuid, RightId = new Guid(PasswordChangeYourself) },
new SecurityGroupAccess { Id = new Guid("59309220-F49B-4E30-B265-CB2ED71867B0"), GroupId = adminGroupGuid, RightId = new Guid(ViewAll) },
new SecurityGroupAccess { Id = new Guid("F2F3FDF3-1ABC-46FF-BB62-E19B3F48E0AC"), GroupId = adminGroupGuid, RightId = new Guid(CanChangeTags) },
new SecurityGroupAccess { Id = new Guid("7AC0F6A1-A585-40D6-B09B-DD6B86772935"), GroupId = userGroupGuid, RightId = new Guid(PasswordChangeYourself) }
So - in example we add 3 SecurityGroupRole Admin , Doctor , Patient
, and give each some right's, Patient
can change password for himself for example ( excuse me - this is from other project - so naming can looking wrong)