add rules package, create rule for is_job_poster

This commit is contained in:
aatish 2018-10-20 13:33:33 +05:45
parent 58c739c4e6
commit 95d2f9c3d1
3 changed files with 16 additions and 0 deletions

View file

@ -48,6 +48,9 @@ INSTALLED_APPS += [
# before 'django.contrib.admin' app
'dal',
'dal_select2',
# for authorization
'rules',
]
# Our apps
@ -115,6 +118,10 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
AUTHENTICATION_BACKENDS = (
'rules.permissions.ObjectPermissionBackend',
'django.contrib.auth.backends.ModelBackend',
)
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

8
jobs/rules.py Normal file
View file

@ -0,0 +1,8 @@
import rules
@rules.predicate
def is_job_poster(user, job):
return job.posted_by == user
rules.add_perm('jobs.change_job', is_job_poster)

View file

@ -1,3 +1,4 @@
Django==2.1.2
django-crispy-forms==1.7.2
git+https://github.com/yourlabs/django-autocomplete-light.git#egg=django-autocomplete-light
rules==2.0