Fix site_id for comment
This commit is contained in:
parent
29782fe876
commit
86500b6b88
20
apps/comment/migrations/0007_comment_site.py
Normal file
20
apps/comment/migrations/0007_comment_site.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 2.2.7 on 2019-11-25 08:10
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0037_sitesettings_old_id'),
|
||||
('comment', '0006_comment_is_publish'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='comment',
|
||||
name='site',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.SiteSettings', verbose_name='site'),
|
||||
),
|
||||
]
|
||||
|
|
@ -35,7 +35,8 @@ class Comment(ProjectBaseMixin):
|
|||
user = models.ForeignKey('account.User', related_name='comments', on_delete=models.CASCADE, verbose_name=_('User'))
|
||||
old_id = models.IntegerField(null=True, blank=True, default=None)
|
||||
is_publish = models.BooleanField(default=False, verbose_name=_('Publish status'))
|
||||
|
||||
site = models.ForeignKey('main.SiteSettings', blank=True, null=True,
|
||||
on_delete=models.SET_NULL, verbose_name=_('site'))
|
||||
content_type = models.ForeignKey(generic.ContentType, on_delete=models.CASCADE)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from account.models import Role, User, UserRole
|
|||
from authorization.tests.tests_authorization import get_tokens_for_user
|
||||
from comment.models import Comment
|
||||
from utils.tests.tests_permissions import BasePermissionTests
|
||||
from main.models import SiteSettings
|
||||
|
||||
|
||||
class CommentModeratorPermissionTests(BasePermissionTests):
|
||||
|
|
@ -33,11 +34,16 @@ class CommentModeratorPermissionTests(BasePermissionTests):
|
|||
self.content_type = ContentType.objects.get(app_label='location', model='country')
|
||||
|
||||
self.user_test = get_tokens_for_user()
|
||||
|
||||
self.site_ru, created = SiteSettings.objects.get_or_create(
|
||||
subdomain='ru'
|
||||
)
|
||||
|
||||
self.comment = Comment.objects.create(text='Test comment', mark=1,
|
||||
user=self.user_test["user"],
|
||||
object_id=self.country_ru.pk,
|
||||
content_type_id=self.content_type.id,
|
||||
country=self.country_ru
|
||||
site=self.site_ru
|
||||
)
|
||||
self.comment.save()
|
||||
self.url = reverse('back:comment:comment-crud', kwargs={"id": self.comment.id})
|
||||
|
|
@ -50,7 +56,7 @@ class CommentModeratorPermissionTests(BasePermissionTests):
|
|||
"user": self.user_test["user"].id,
|
||||
"object_id": self.country_ru.pk,
|
||||
"content_type": self.content_type.id,
|
||||
"country_id": self.country_ru.id
|
||||
"site_id": self.site_ru.id
|
||||
}
|
||||
|
||||
response = self.client.post(self.url, format='json', data=comment)
|
||||
|
|
@ -61,7 +67,7 @@ class CommentModeratorPermissionTests(BasePermissionTests):
|
|||
"user": self.moderator.id,
|
||||
"object_id": self.country_ru.id,
|
||||
"content_type": self.content_type.id,
|
||||
"country_id": self.country_ru.id
|
||||
"site_id": self.site_ru.id
|
||||
}
|
||||
|
||||
tokens = User.create_jwt_tokens(self.moderator)
|
||||
|
|
|
|||
|
|
@ -321,13 +321,13 @@ class IsReviewerManager(IsStandardUser):
|
|||
]
|
||||
|
||||
# and request.user.email_confirmed,
|
||||
if hasattr(request.data, 'user') and hasattr(request.data, 'country_id'):
|
||||
if hasattr(request.data, 'user') and hasattr(request.data, 'site_id'):
|
||||
role = Role.objects.filter(role=Role.REVIEWER_MANGER) \
|
||||
.first() # 'Comments moderator'
|
||||
.first()
|
||||
|
||||
rules = [
|
||||
UserRole.objects.filter(user=request.user, role=role,
|
||||
establishment_id=request.data.country_id
|
||||
establishment_id=request.data.site_id
|
||||
).exists(),
|
||||
super().has_permission(request, view)
|
||||
]
|
||||
|
|
@ -335,7 +335,7 @@ class IsReviewerManager(IsStandardUser):
|
|||
|
||||
def has_object_permission(self, request, view, obj):
|
||||
role = Role.objects.filter(role=Role.REVIEWER_MANGER,
|
||||
country_id=obj.country_id) \
|
||||
country_id=obj.site_id) \
|
||||
.first()
|
||||
|
||||
rules = [
|
||||
|
|
|
|||
|
|
@ -5,15 +5,13 @@ from translation.models import Language
|
|||
|
||||
class BasePermissionTests(APITestCase):
|
||||
def setUp(self):
|
||||
self.lang = Language.objects.get(
|
||||
self.lang, created = Language.objects.get_or_create(
|
||||
title='Russia',
|
||||
locale='ru-RU'
|
||||
)
|
||||
self.lang.save()
|
||||
|
||||
self.country_ru = Country.objects.get(
|
||||
self.country_ru, created = Country.objects.get_or_create(
|
||||
name={"en-GB": "Russian"}
|
||||
)
|
||||
self.country_ru.save()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user