My first Python web development Framework (35)--The structure design of permission database

Source: Internet
Author: User

The next thing to do is the database structure of the Authority system design, in the previous chapter we understand the authority system is through what to manage the permissions, we choose the more commonly used permission system to achieve the current project management requirements.

Here is the permission system relationship model we selected:

 

From the above relationship can be seen, after the user login successfully, by reading the Administrator account information to obtain the current Administrator's department and position, read the position of the permissions information. After entering the system, through the position permission information to filter out the displayed menu items, access each function page and make the operation, through the permission information to determine whether the current administrator has the operation rights, thus realize the system administrator operation permission control. The purpose of each data table is explained below separately.

Menu tables are used to register (BIND) menus, manage pages, and interfaces, and without adding interfaces and menu items to the menus, the program is unclear about what the menu items and interfaces are, and what the relationship is between them and the interface.

Therefore, it is necessary to manually add them to the menu table when developing, in order to manage the respective functions.

Before we start designing the menu table, let's think about what information we need to store, what is the correlation between them, what each field does, and why do you want to add this field or reduce the field?

For menu table fields, it is easy to set up a number of fields, such as the menu name, menu URL (bound HTML page name or path), small menu icon (increasing the aesthetics of the menu), the previous menu ID (for creating a tree-level menu directory), sorting, whether it is displayed (for some pages or key functions, Not shown in the menu list), disabled (some features can be disabled temporarily when not in use). In addition to this, we also need to add the menu routing Address field, to store the current menu bound page to use the routing address items, such as the Edit menu page, we need to read this record in development, and then edit, and then submit, here will be related to two routes, One is the menu record reads the route, and the menu record modifies the route, when does the permission judgment, may the permission current operation page and the binding routing address, with the permission information to compare, determines whether has the operation permission, in the later corresponding section detailed explanation. Since our front-end uses the Jqgrid component's Tree list feature, the component requires that the server side return the list, the tree list depth, whether the current node is the final node, whether the current node expands three fields, so you need to add them to the menu table.

According to these requirements, the data structure of our menu table is as follows

  

The Finished menu Management page works as follows:

  


Department table it is equivalent to the permission group, can be based on the department structure of the Enterprise to create a corresponding structure record, it is also convenient for enterprises to understand the relationship between system permissions more easily. Of course, you can also set up the virtual department to manage.

For a departmental table, it is also a tree-like relationship, so it is basically similar to the menu table structure.

In order to expand the need later, you need to add the Department coding field, the encoding from 01 to 99, of course, if the Department of more than 99, either increase to 3 digits, or the current framework can not support the development of the business need to think about the new architecture.

Each additional level of encoding is automatically added "0x" after 01, and the length of the encoding is related to the department grading depth.

The following is the structure of the departmental table, which seems to have been deleted from a number of fields on the basis of the menu table.

  

A job table is a permission role that is bound to a department, which is directly associated with a menu item, and different positions can be set with different permissions (set menu items that can be viewed and manipulated)

So the job table needs to store the associated items with the Department table: Department table ID, department code, and department name (this redundant field is stored directly, so you don't need to associate a query from the Department table when you need to display the Department of a position, because the department name is almost set and no longer changed)

In addition, it needs to have a job name, menu permissions two fields

  

Page:

  

  

  

and administrator account management, the main management is the background administrator login account and password, the basic information of the Administrator, as well as operational rights.

The management of the authority only needs to bind the corresponding department and the position, when the user logs on, it can get the corresponding operation permission through this binding.

In general, the administrator account needs to record: login account, login password, login key (if you need to login through the app side, need to encrypt the access link or enable cookies to verify the login, this field is required to store the user's own corresponding key), the last logon time, the last login ID, number of logins, Registration time and other information

and the basic information of the administrator is different from the management needs of different enterprises, and some will be added to the system of personnel management, you need to record all the basic information of each employee, of course, the commonly used information is: The user's Chinese name, gender, date of birth, mobile phone number, mailbox, notes, we add or subtract as necessary.

And the user's permissions related fields, mainly binding departments and positions, and working status and account status it some fields.

Specific data structures:

  

Page:

  

  

Do to manage the system, of course, also need to record all the records of the administrator's operations, such as login, exit, browse what page, the operation of what, so also add an Administrator operation log table, easy to view analysis problems, distinguish responsibility

  

Rights Management data table Create SQL Download (PS: For ease of operation, SQL will delete the manager table created earlier and then add the admin admin account back in)

Copyright NOTICE: This article was originally published in the Blog Park , the author for allempty This article welcomes, but without the author's consent must retain this paragraph, and in the article page obvious location to the original link, otherwise considered infringement.

Python Development QQ Group: 669058475 Author Blog:/http

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.