Tuesday, March 1, 2011

Winform, authorization on ui

0 vote down check

I'm thinking on creating standard users, roles, permissions table schema, add contorls table and permission would be 'for a role on a control' and then in form loading event fire up a method to set Enabled proprerty of controls due to user's role's permissions. Is this good idea or i should took a hammer and get this out of my head (and if i should, please tell me why ;) )

From stackoverflow
  • I probably would advise against the individual control roles table and just deal with setting the states of the controls in the application based on what Role the user has.

    e.g.

    Button adminButton = new Button();
    Button userButton = new Button();
    ...
    
    public void Form_Load(object sender, EventArgs e)
    {
        User user = // find user
        adminButton.Enabled = (user.Role == UserRoles.Admin)
        userButton.Enabled = (user.Role == UserRoles.Admin || user.Role == UserRoles.Standard)
    }
    

    Other than that, it seems a normal approach.

    Adrian : i can't hardcode this like you suggest, becouse permissions have to be managable (i should be able to change through user firendly interface)
    James : If every control you have MUST be configurable i.e. unable to group them, then using a control table would be perfectly fine.
  • I've created a similar schema, works out reasonably well. Allows for fine-grained control; but it's also a lot of work to get all permissions right.

0 comments:

Post a Comment