I have an issue with creating my User Roles in a custom authorisation implementation.
Unfutunately I’m dealing with a really badly designed legacy database which is used by other applications, and I don’t really want to have to re-code the database and the other applications.
Below I have listed how I would like my User and UserPermissionGroup classes to look.
public class User
{
public virtual int Id { get; set; }
public virtual int Name { get; set; }
public virtual int Email { get; set; }
public virtual int Password { get; set; }
protected virtual IEnumerable<UserPermissionGroup> PermissionGroups { get; set; }
public virtual book IsInRole(string role)
{
// code to check with PermissionGroups if user is in one of the required roles
}
}
public class UserPermissionGroup
{
public virtual string Role { get; set; }
public virtual bool CanAccess { get; set; }
public virtual string SiteCode { get; set; } // optional field - depends on perm type in DB
}
And unfortunately my (abbreviated) database structure looks like:
People
{
ID (PK, int)
Name (varchar)
Email (varchar)
Password (varchar)
PeopleTypeId (FK, int)
IsSuperAdmin (bit)
IsSiteAdmin (bit)
IsUserAdmin (bit)
}
PeopleTypes
{
PeopleTypeId (PK, int)
TypeName (varchar)
}
Perm2People
{
PeopleId (PK, FK, int)
GroupID (PK, FK, int)
}
PermGroups
{
GroupID (PK, int)
GroupName (varchar)
}
Perms4Sites
{
PeopleID (PK, FK, int)
SiteCode (PK, FK, char(3))
Section (PK, char(1))
AccessLevel (int)
}
In Perms4Sites:
- SiteCode relates to one of the sites that the Admin area is managing.
- Section is a 1 character code for different parts of the admin (which relates to the Roles)
- AccessLevel 0-3 depending on how much permissions a person has to that section (ie read, write, publish). At the moment we don’t need to know what level of access soemone has – just if they have anything other than 0.
I would like to add mappings for all the permission type tables (and rows from the People table) into the one UserPermissionGroup class. I only need to read these tables – no writing to the DB required.
Does anyone know how to write a mapping for this DB structure into something more useful like my ideal class schema above?
Thanks for any help
Saan
A colleague of mine pointed out that I was making this way too complicated, and I should just write a sql view for all the mappings.