Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a custom permission to a User

I'd like to be able to give some existing Users a custom permission which I will require for accessing a view.

I think I need to add the new permission to the Postgres table auth_permission, but I suspect there is a higher-level way to do this. Also there is a column in auth_permission for content_type and I don't know what its value should be.

What is the right way to do this?

like image 462
Mitch Avatar asked Dec 09 '09 19:12

Mitch


People also ask

What are custom permissions?

This document describes how app developers can use the security features provided by Android to define their own permissions. By defining custom permissions, an app can share its resources and capabilities with other apps.

What is the difference between permission set and custom permission?

Custom Permissions in Salesforce are used to give access to users for certain apps or processes that you have configured and which cannot be controlled by profile or permission set directly. A profile and a permission set control the users' access to many entities such as objects, fields, tabs, and Visualforce pages.


1 Answers

Have a look at how to create custom permissions in the docs.

class USCitizen(models.Model):     # ...     class Meta:         permissions = (             ("can_drive", "Can drive"),             ("can_vote", "Can vote in elections"),             ("can_drink", "Can drink alcohol"),         ) 

Then run python manage.py makemigrations && python manage.py migrate.

Use the permission_required decorator to restrict access to your view.

like image 89
sheats Avatar answered Sep 27 '22 23:09

sheats