Add establishment manager role
This commit is contained in:
parent
3271a6fed9
commit
9fd89bf812
|
|
@ -12,7 +12,7 @@ class RoleAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
@admin.register(models.UserRole)
|
@admin.register(models.UserRole)
|
||||||
class UserRoleAdmin(admin.ModelAdmin):
|
class UserRoleAdmin(admin.ModelAdmin):
|
||||||
list_display = ['user', 'role']
|
list_display = ['user', 'role', 'establishment']
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.User)
|
@admin.register(models.User)
|
||||||
|
|
|
||||||
30
apps/account/migrations/0013_auto_20191016_0810.py
Normal file
30
apps/account/migrations/0013_auto_20191016_0810.py
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-16 08:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0033_auto_20191003_0943_squashed_0034_auto_20191003_1036'),
|
||||||
|
('account', '0012_merge_20191015_0708'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='userrole',
|
||||||
|
name='establishment',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='establishment.Establishment', verbose_name='Establishment'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='role',
|
||||||
|
name='country',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='location.Country', verbose_name='Country'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='role',
|
||||||
|
name='role',
|
||||||
|
field=models.PositiveIntegerField(choices=[(1, 'Standard user'), (2, 'Comments moderator'), (3, 'Country admin'), (4, 'Content page manager'), (5, 'Establishment manager')], verbose_name='Role'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -13,6 +13,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
|
|
||||||
from authorization.models import Application
|
from authorization.models import Application
|
||||||
|
from establishment.models import Establishment
|
||||||
from location.models import Country
|
from location.models import Country
|
||||||
from utils.models import GMTokenGenerator
|
from utils.models import GMTokenGenerator
|
||||||
from utils.models import ImageMixin, ProjectBaseMixin, PlatformMixin
|
from utils.models import ImageMixin, ProjectBaseMixin, PlatformMixin
|
||||||
|
|
@ -25,12 +26,14 @@ class Role(ProjectBaseMixin):
|
||||||
COMMENTS_MODERATOR = 2
|
COMMENTS_MODERATOR = 2
|
||||||
COUNTRY_ADMIN = 3
|
COUNTRY_ADMIN = 3
|
||||||
CONTENT_PAGE_MANAGER = 4
|
CONTENT_PAGE_MANAGER = 4
|
||||||
|
ESTABLISHMENT_MANAGER = 5
|
||||||
|
|
||||||
ROLE_CHOICES = (
|
ROLE_CHOICES = (
|
||||||
(STANDARD_USER, 'Standard user'),
|
(STANDARD_USER, 'Standard user'),
|
||||||
(COMMENTS_MODERATOR, 'Comments moderator'),
|
(COMMENTS_MODERATOR, 'Comments moderator'),
|
||||||
(COUNTRY_ADMIN, 'Country admin'),
|
(COUNTRY_ADMIN, 'Country admin'),
|
||||||
(CONTENT_PAGE_MANAGER, 'Content page manager')
|
(CONTENT_PAGE_MANAGER, 'Content page manager'),
|
||||||
|
(ESTABLISHMENT_MANAGER, 'Establishment manager')
|
||||||
)
|
)
|
||||||
role = models.PositiveIntegerField(verbose_name=_('Role'), choices=ROLE_CHOICES,
|
role = models.PositiveIntegerField(verbose_name=_('Role'), choices=ROLE_CHOICES,
|
||||||
null=False, blank=False)
|
null=False, blank=False)
|
||||||
|
|
@ -230,3 +233,5 @@ class UserRole(ProjectBaseMixin):
|
||||||
"""UserRole model."""
|
"""UserRole model."""
|
||||||
user = models.ForeignKey(User, verbose_name=_('User'), on_delete=models.CASCADE)
|
user = models.ForeignKey(User, verbose_name=_('User'), on_delete=models.CASCADE)
|
||||||
role = models.ForeignKey(Role, verbose_name=_('Role'), on_delete=models.SET_NULL, null=True)
|
role = models.ForeignKey(Role, verbose_name=_('Role'), on_delete=models.SET_NULL, null=True)
|
||||||
|
establishment = models.ForeignKey(Establishment, verbose_name=_('Establishment'),
|
||||||
|
on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
|
|
@ -143,4 +143,17 @@ class IsCommentModerator(IsStandardUser):
|
||||||
|
|
||||||
|
|
||||||
class IsEstablishmentManager(IsStandardUser):
|
class IsEstablishmentManager(IsStandardUser):
|
||||||
pass
|
|
||||||
|
def has_object_permission(self, request, view, obj):
|
||||||
|
role = Role.objects.filter(role=Role.ESTABLISHMENT_MANAGER)\
|
||||||
|
.first() # 'Comments moderator'
|
||||||
|
|
||||||
|
is_access = UserRole.objects.filter(user=request.user, role=role,
|
||||||
|
establishment_id=obj.establishment_id).exists()
|
||||||
|
if is_access:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if super().has_object_permission(request, view, obj):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user