Book Image

Flask Framework Cookbook

By : Shalabh Aggarwal
Book Image

Flask Framework Cookbook

By: Shalabh Aggarwal

Overview of this book

Table of Contents (19 chapters)
Flask Framework Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating user roles


Until now, we saw how a view that is accessible to a certain set of admin users can be created easily using the is_accessible() method. This can be extended to have different kinds of scenarios where specific users will be able to view specific views. There is another way of implementing user roles at a much more granular level in a model where the roles determine whether a user can perform all, some, or any of the CRUD operations.

Getting ready

In this recipe, we will see a basic way of creating user roles, where an admin user can only perform actions they are entitled to.

Note

Remember that this is just one way of implementing user roles. There are many better ways of doing this, but this one seems to be the best one to demonstrate the concept of creating user roles.

One such method will be to create user groups and assign roles to the groups rather than individual users. Another method can be the complex policy-based user roles, which will include defining the roles according...