The first part please refer to: http://blog.csdn.net/snomyc520/article/details/38677861
To address this need, Version 1 is powerless (of course you can also add several features: for example, classification A's news drafting and classification B's news drafting, add this function to the corresponding role, but this should not be the solution, but Version 2 is also based on this idea ).
In fact, a better example than news is the moderator of the Forum.
The solution for version 2 is as follows:
Added the resourcetype field to the table in version 2. This field is used to indicate the classification of a resource (for example, News). We can simulate it in the same way (the resourcetype of news classification A is: NTA, Category B: NTB ):
Menu:
Then, add the corresponding roles to the role table and add the corresponding functions to the role table.
The statements for getting functions are also changed accordingly:
Select functionid + ',' + resourcetype from role menu where roleid in (select roleid from user role table where userid = 'u1 ')
Permission deduction becomes:
Functions. contain ('f1, NTA ');
When a new category is added, corresponding records are also added to the menu at the same time (of course, not directly added to the database, but function-related functions ).
Using this solution, you can easily control each category of a classified application (such as a forum system) (such as the VIP section, only VIP users can browse and publish their own VIP roles, while other sections can be used only by paying attention to users ).
In actual application, functionid is not a random string, but encoded. It includes the module ID and can reflect the parent-child relationship. For example: for the forum system, we will give it a module ID of "30". The function of the Forum is divided into two categories: Management class (for example, deleting a post ), one class is to use a class (such as posting, replying, browsing a post, etc.), to give the management class A code: 01, using a class code: 02, we will perform the following encoding for functionid:
300101: delete a post
300201: Post
300202: Reply
300203: browse posts
For resources (for example, the ID of a Part 1 is 01), we can combine the following functions (of course, you can also separate the combinations without commas, you can use other combinations to avoid ambiguity ):
300101,01: function of deleting a post in Section 1
: Board 1 posting Function
......
Roleid is also the encoding method used by the role, which also reflects the parent-child relationship of the role, it can also inherit role functions (of course, the SQL statement used to obtain the role function list is not as simple as it is now ). In my current applications, role inheritance is not implemented (although the role encoding reflects the role's parent-child relationship ).
Role-based permission design (2)