refactor: Use new trust level class
This commit is contained in:
parent
d46ab8da6b
commit
8ccdf50bc5
@ -7,7 +7,7 @@ from fellchensammlung import baker_recipes
|
|||||||
from model_bakery import baker
|
from model_bakery import baker
|
||||||
|
|
||||||
from fellchensammlung.models import AdoptionNotice, Species, Animal, Image, ModerationAction, User, Rule, \
|
from fellchensammlung.models import AdoptionNotice, Species, Animal, Image, ModerationAction, User, Rule, \
|
||||||
Report, Comment, ReportAdoptionNotice
|
Report, Comment, ReportAdoptionNotice, TrustLevel
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@ -101,10 +101,10 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
User.objects.create_user('test', password='foobar')
|
User.objects.create_user('test', password='foobar')
|
||||||
admin1 = User.objects.create_superuser(username="admin", password="admin", email="admin1@example.org",
|
admin1 = User.objects.create_superuser(username="admin", password="admin", email="admin1@example.org",
|
||||||
trust_level=User.TRUST_LEVEL[User.ADMIN])
|
trust_level=TrustLevel.ADMIN)
|
||||||
|
|
||||||
mod1 = User.objects.create_user(username="mod1", password="mod", email="mod1@example.org",
|
mod1 = User.objects.create_user(username="mod1", password="mod", email="mod1@example.org",
|
||||||
trust_level=User.TRUST_LEVEL[User.MODERATOR])
|
trust_level=TrustLevel.MODERATOR)
|
||||||
|
|
||||||
comment1 = baker.make(Comment, user=admin1, text="This is a comment", adoption_notice=adoption1)
|
comment1 = baker.make(Comment, user=admin1, text="This is a comment", adoption_notice=adoption1)
|
||||||
comment2 = baker.make(Comment,
|
comment2 = baker.make(Comment,
|
||||||
|
@ -210,7 +210,7 @@ def add_adoption_notice(request):
|
|||||||
add_adoption_notice_location.delay_on_commit(instance.pk)
|
add_adoption_notice_location.delay_on_commit(instance.pk)
|
||||||
|
|
||||||
# Set correct status
|
# Set correct status
|
||||||
if request.user.trust_level >= User.TRUST_LEVEL[User.COORDINATOR]:
|
if request.user.trust_level >= TrustLevel.MODERATOR:
|
||||||
instance.set_active()
|
instance.set_active()
|
||||||
else:
|
else:
|
||||||
instance.set_unchecked()
|
instance.set_unchecked()
|
||||||
@ -484,7 +484,7 @@ def updatequeue(request):
|
|||||||
if action == "checked_active":
|
if action == "checked_active":
|
||||||
adoption_notice.set_active()
|
adoption_notice.set_active()
|
||||||
|
|
||||||
if user_is_trust_level_or_above(request.user, User.MODERATOR):
|
if user_is_trust_level_or_above(request.user, TrustLevel.MODERATOR):
|
||||||
last_checked_adoption_list = AdoptionNotice.objects.order_by("last_checked")
|
last_checked_adoption_list = AdoptionNotice.objects.order_by("last_checked")
|
||||||
else:
|
else:
|
||||||
last_checked_adoption_list = AdoptionNotice.objects.filter(owner=request.user).order_by("last_checked")
|
last_checked_adoption_list = AdoptionNotice.objects.filter(owner=request.user).order_by("last_checked")
|
||||||
|
@ -4,7 +4,7 @@ from django.utils import timezone
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from model_bakery import baker
|
from model_bakery import baker
|
||||||
|
|
||||||
from fellchensammlung.models import Announcement, Language, User
|
from fellchensammlung.models import Announcement, Language, User, TrustLevel
|
||||||
|
|
||||||
|
|
||||||
class UserTest(TestCase):
|
class UserTest(TestCase):
|
||||||
@ -12,7 +12,7 @@ class UserTest(TestCase):
|
|||||||
test_user_1 = User.objects.create(username="Testuser1", password="SUPERSECRET", email="test@example.org")
|
test_user_1 = User.objects.create(username="Testuser1", password="SUPERSECRET", email="test@example.org")
|
||||||
|
|
||||||
self.assertTrue(test_user_1.trust_level == 1)
|
self.assertTrue(test_user_1.trust_level == 1)
|
||||||
self.assertTrue(test_user_1.trust_level == User.TRUST_LEVEL[User.MEMBER])
|
self.assertTrue(test_user_1.trust_level == TrustLevel.MEMBER)
|
||||||
|
|
||||||
|
|
||||||
class AnnouncementTest(TestCase):
|
class AnnouncementTest(TestCase):
|
||||||
|
@ -4,7 +4,7 @@ from django.urls import reverse
|
|||||||
|
|
||||||
from model_bakery import baker
|
from model_bakery import baker
|
||||||
|
|
||||||
from fellchensammlung.models import Animal, Species, AdoptionNotice, User, Location, AdoptionNoticeStatus
|
from fellchensammlung.models import Animal, Species, AdoptionNotice, User, Location, AdoptionNoticeStatus, TrustLevel
|
||||||
from fellchensammlung.views import add_adoption_notice
|
from fellchensammlung.views import add_adoption_notice
|
||||||
|
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ class AnimalAndAdoptionTest(TestCase):
|
|||||||
first_name="Max",
|
first_name="Max",
|
||||||
last_name="Müller",
|
last_name="Müller",
|
||||||
password='12345')
|
password='12345')
|
||||||
test_user0.trust_level = User.TRUST_LEVEL[User.ADMIN]
|
test_user0.trust_level = TrustLevel.ADMIN
|
||||||
test_user0.save()
|
test_user0.save()
|
||||||
|
|
||||||
adoption1 = baker.make(AdoptionNotice, name="TestAdoption1")
|
adoption1 = baker.make(AdoptionNotice, name="TestAdoption1")
|
||||||
@ -133,7 +133,7 @@ class UpdateQueueTest(TestCase):
|
|||||||
first_name="Admin",
|
first_name="Admin",
|
||||||
last_name="BOFH",
|
last_name="BOFH",
|
||||||
password='12345',
|
password='12345',
|
||||||
trust_level=User.TRUST_LEVEL[User.MODERATOR])
|
trust_level=TrustLevel.MODERATOR)
|
||||||
test_user0.is_superuser = True
|
test_user0.is_superuser = True
|
||||||
test_user0.save()
|
test_user0.save()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user