Best Practice for Designing User Roles and Permission System?

后端 未结 5 1061
逝去的感伤
逝去的感伤 2020-12-04 05:20

I need to add user roles and permission system into my web application built using PHP/MySQL. I want to have this functionality:

  1. One root user can create sub-
5条回答
  •  我在风中等你
    2020-12-04 05:50

    I have groups and users (like active directory LDAP solution). So if I give access to group I need that users in this group have herited accesses.

    So, based on the @suresh-kamrushi answer below, I made this :

    INSERT INTO `permission` (`bit`, `name`) VALUES
    (1,   'add-yes'),
    (2,   'add-no'),
    (4,   'edit-yes'),
    (8,   'edit-no'),
    (16,  'del-yes'),
    (32,  'del-no'),
    (64,  'view-yes'),
    (128, 'view-no');
    

    If user have bit 00000000, I take first two digits 00 that means add-yes and add-no are herited from group permissions.

    If user have bit 01010110, I take first two digits 01 that means add-no will prime on group permissions, so this user have no add permission. This bitwise says that user can only view.

    It's also working with parent groups.

    What do you think about this solution ? Does anyone have got better way for that ?

提交回复
热议问题