You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.
Hello!
I've read the docs, read #26 and #28 examples, tried to find out where I've mistaken using Kawaz sources, but still can't understand where I've made a mistake.
I'm using Djnago 1.11 with Python 3.6.1 and django-permission 1.4.0 (also tried under django 1.10.7, python 3.6.0)
I have 'console_test' project with 'console' app inside it. It has 1 model called Deal, so my models.py looks like this:
#models.py
from django.db import models
# Create your models here.
from django.contrib.auth.models import User
class Deal(models.Model):
title = models.CharField(max_length=200)
desc = models.CharField(max_length=200, blank=True)
user = models.ForeignKey(User)
In settings.py of the project I've:
1)Added permission to INSTALLED_APPS:
4)Then in project's urls.py (not app's) I've added Autodiscover
#urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views as auth_views
import permission; permission.autodiscover()
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^console/', include('console.urls', namespace="console")),
url(r'^accounts/login/$', auth_views.login, {'template_name': 'login.html'}, name='login'),
url(r'^accounts/logout/$', auth_views.logout_then_login, name='logout'),
]
5)Then I've created perms.py file inside 'console' app dir (Is it right? Not in 'console_test' project root?) with AuthorPermissionLogic, StaffPermissionLogic and CustomPermissionLogic (for test purposes it always returns True):
I've tried a lot to make this module working for me but unfortunately unsuccessfully.
If I try to use, for example, 'deal.read' for permission name with @permission_required decorator I'm always getting error "Permission matching query does not exist.
If I try to use for example, 'read' for permission name @permission_required decorator I've always being redirected to login screen (no matter what CustomPermissionLogic has_perm function returns). Could you tell me where I've made a mistake?
So views under this decorator are unreachable for users. Super-user can reach these views (as I understand no permission checking is made for him) but {% if user has ... %} template tags inside view template also doesn't work.
So I have some questions:
If I want to use @permission_required decorator to limit access to some views (for ex. With list of models and Detail page), how can I do that? What permission name I must use to limit access with that built-in Logic?
If I want to use AuthorPermissionLogic, StaffPermissionLogic, GroupInPermissionLogic what permission name must be? Must I use 'app_name.permission_name' or 'model_name.permission_name' or 'app_name.model_name.permission_name' or just 'permission_name'? Is it connected somehow with Logic?
Example
@permission_required('staff? or console.staff? or deal.staff?')
How to combine them (for ex. Author and Custom), with a list (['staff','author']?
The same situation, if I want to use {% if user has ... %} template tags?
I've created CustomPermissionLogic and want to create permissions for viewing, deleting, and modifying Deal model objects. How can I bind by permissions to be processed by CustomPermissionLogic. I've tried to check whether has_perm function is used during permission-checking process but it seems that it is unreachable, return True or return False or raise Exception inside it has no effect at alaa. I can't understand how to bind permissions to model or to CustomPermissionLogic. How does django-permission module bind them?
Example:
I want Deal model to have permissions: read, modify and delete
CustomPermissionLogic has has_perm function, that can process that permissions and return True or False.
CustomPermissionLogic binded to Deal model via perms.py file inside console app dir ('console.Deal', CustomPermissionLogic()),
How to bind my "new permissions" to Deal or to CustomPermissionLogic to use them with @permission_required() or {% if user has ... %}
The text was updated successfully, but these errors were encountered:
Hello!
I've read the docs, read #26 and #28 examples, tried to find out where I've mistaken using Kawaz sources, but still can't understand where I've made a mistake.
I'm using Djnago 1.11 with Python 3.6.1 and django-permission 1.4.0 (also tried under django 1.10.7, python 3.6.0)
I have 'console_test' project with 'console' app inside it. It has 1 model called Deal, so my models.py looks like this:
In settings.py of the project I've:
1)Added permission to INSTALLED_APPS:
2)Added 'builtins': ['permission.templatetags.permissionif'], for using {% if user has ... %} in TEMPLATES:
3)Added to the bottom of the settings.py AUTHENTICATION_BACKENDS:
4)Then in project's urls.py (not app's) I've added Autodiscover
5)Then I've created perms.py file inside 'console' app dir (Is it right? Not in 'console_test' project root?) with AuthorPermissionLogic, StaffPermissionLogic and CustomPermissionLogic (for test purposes it always returns True):
In views I have 4 views (Index, Result, Detail and Change).
console app's urls.py are simple
I've tried a lot to make this module working for me but unfortunately unsuccessfully.
If I try to use, for example, 'deal.read' for permission name with @permission_required decorator I'm always getting error "Permission matching query does not exist.
If I try to use for example, 'read' for permission name @permission_required decorator I've always being redirected to login screen (no matter what CustomPermissionLogic has_perm function returns). Could you tell me where I've made a mistake?
So views under this decorator are unreachable for users. Super-user can reach these views (as I understand no permission checking is made for him) but {% if user has ... %} template tags inside view template also doesn't work.
So I have some questions:
If I want to use AuthorPermissionLogic, StaffPermissionLogic, GroupInPermissionLogic what permission name must be? Must I use 'app_name.permission_name' or 'model_name.permission_name' or 'app_name.model_name.permission_name' or just 'permission_name'? Is it connected somehow with Logic?
Example
The same situation, if I want to use {% if user has ... %} template tags?
I've created CustomPermissionLogic and want to create permissions for viewing, deleting, and modifying Deal model objects. How can I bind by permissions to be processed by CustomPermissionLogic. I've tried to check whether has_perm function is used during permission-checking process but it seems that it is unreachable, return True or return False or raise Exception inside it has no effect at alaa. I can't understand how to bind permissions to model or to CustomPermissionLogic. How does django-permission module bind them?
Example:
The text was updated successfully, but these errors were encountered: