Best Practice for storing Enumerations and User Roles/Privileges

Posts   
 
    
Posts: 56
Joined: 26-Aug-2009
# Posted on: 13-Apr-2010 06:20:33   

Hello there,

I have plans for the following entities; - User (UserId, etc) - UserRoles (RoleId, UserId)

  • RolePrivilege(RolePrivelegeId,UserRoleId,HasInvoiceFormAccess, HasOtherAccessEtc)
  • UserPrivilege(UserPrivegeId,UserId,HasInvoiceFormAccess, HasOtherAccessEtc)

So I have two questions? I was wondering what people normally consider the best way to store enumerations? Say for example I want certain users to have only access to the Invoicing Form. I want to be able to go;

if (CurrentLoggedInUser.HasInvoiceFormAccess) {openinvoiceform();}

Is it a bad idea to have the UserPrivilege Table store all these as fields? (It seems like an OK thing to do but I wonder about updatability even though it is hard coded application logic)

and

How is the best way to structure these tables? I'm confused about this simple_smile Would I be foolish to make RolePrivelege Entity a subtype of UserPrivilege? The role and user privileges entities will be exactly the same except that there will be 1:m user to roles and 1:1 User to UserPrivilege.....or is the best way just to have one privilege table and create some kind of intermediate joining table?

Thank you so much for reading my post and I would be very happy to hear any thoughts simple_smile

Thank you

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 13-Apr-2010 10:57:44   

This is how I would do it:

  • User (UserId, etc)
  • Role (RoleId, etc)
  • UserRoles (RoleId, UserId)

  • Privilege (PrivilegeId, Description)

  • RolePrivilege(RoleId, PrivilegeId)

  • UserPrivilege(UserId, PrivilegeId)

This allows you to add new privileges without changing the schema. You'll only need to insert new data.

Posts: 56
Joined: 26-Aug-2009
# Posted on: 13-Apr-2010 11:35:12   

Thanks Walaa,

How would one get intellisense/strong type doing it via that method?

Or is it just a trade off you accept to avoid regenerating all the time?

Thank you

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Apr-2010 04:15:22   

There is an enum task generator you can use in your project that generates such strongly typed enum fields. You can download it from Customer Area -> v2.0 downloads -> 3rd. Party

David Elizondo | LLBLGen Support Team
Posts: 56
Joined: 26-Aug-2009
# Posted on: 14-Apr-2010 14:29:43   

Hmm, All I see is "ADO.NET Dataservices templates" under 3rd party. I cannot see any others that might resemble this.

No matter. I guess I will try just plot the best way of doing it and worry about generating that when I am happy...it is good to know that is available.

Thanks Daelmo.

Posts: 56
Joined: 26-Aug-2009
# Posted on: 14-Apr-2010 15:02:27   

k, After my best attempt to think things through...I'm going to go with Walaa's way.

Thanks both of you.