liveBook · Manning

Role

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

An authorization role is a named grouping of permissions that determines which actions a user may perform.

A role groups capabilities so an application can decide what a user may do after logging in. Authentication identifies the user; authorization uses the user’s role to control access to actions and routes. section 9.6 section 9.9

A practical role scheme separates ordinary content work from system-wide administration:

  • Administrator: updates, activates, or deactivates any content and can activate or deactivate users. section 9.6
  • Editor: updates any content, including content created by other users, but cannot deactivate users or their content. section 9.6
  • Registered user: creates content and manages its active state, but cannot change another user’s or another user’s content state. section 9.6

Roles are initialized by the application and maintained as database records. Each user has one role, while many users can share the same role, forming a one-to-many relationship between roles and users. section 9.6.1

Named permissions backed by stored values

A Role model defines a Permissions Flag enum with REGISTERED, EDITOR, and ADMINISTRATOR names. The application stores the underlying integer in raw_permissions, initializes the role table at startup, and exposes the permissions class to templates for upcoming authorization features. section 9.6.1

Figure 9.5 The new Role table and its relationship to the existing User table

The relationship diagram clarifies how the role lookup table connects to users and supports shared roles. section 9.6.1

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Defines three roles, their action boundaries, database relationships, enum values, startup initialization, and template exposure.
Examples
Uses administrator, editor, and registered-user roles with distinct content and user-management capabilities.
What it assumes
Assumes authenticated users and introduces authorization as the separate mechanism governing their capabilities.
What you can do after
Configure roles in a Flask application and use them to protect pages and system-wide actions.
How it connects
Connects authentication, authorization, users, permissions, database relationships, templates, and route protection.

Also explained in

Compare how 11 books explain role →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.