From 6ab80322805d553335c3f314ffbf0c3bf437782d Mon Sep 17 00:00:00 2001 From: Thomas Svendal Date: Mon, 6 Mar 2023 19:50:12 +0100 Subject: [PATCH] Temp Jubileum Permissions (#681) * Fixed flake8 (#672) * Added Event permissions to Jubkom temporarily (#680) --- app/common/enums.py | 2 +- app/content/models/event.py | 4 ++-- app/tests/conftest.py | 6 ++++++ app/tests/content/test_event_integration.py | 12 +++++++++++- setup.cfg | 4 ++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/common/enums.py b/app/common/enums.py index 83fd165b7..92a3e3581 100644 --- a/app/common/enums.py +++ b/app/common/enums.py @@ -39,8 +39,8 @@ def admin(cls): class Groups(ChoiceEnum): TIHLDE = "TIHLDE" - REDAKSJONEN = "redaksjonen" + JUBKOM = "JubKom" class AppModel(ChoiceEnum): diff --git a/app/content/models/event.py b/app/content/models/event.py index aa6893cf1..f02b3e0e7 100644 --- a/app/content/models/event.py +++ b/app/content/models/event.py @@ -3,7 +3,7 @@ from django.core.exceptions import ValidationError from django.db import models -from app.common.enums import AdminGroup +from app.common.enums import AdminGroup, Groups from app.common.permissions import ( BasePermissionModel, check_has_access, @@ -19,7 +19,7 @@ class Event(BaseModel, OptionalImage, BasePermissionModel): - write_access = (*AdminGroup.admin(), AdminGroup.PROMO) + write_access = (*AdminGroup.admin(), AdminGroup.PROMO, Groups.JUBKOM) title = models.CharField(max_length=200) start_date = models.DateTimeField() diff --git a/app/tests/conftest.py b/app/tests/conftest.py index 7f65c3fbb..651902a24 100644 --- a/app/tests/conftest.py +++ b/app/tests/conftest.py @@ -80,6 +80,12 @@ def member(): return user +@pytest.fixture() +def jubkom_member(member): + add_user_to_group_with_name(member, Groups.JUBKOM) + return member + + @pytest.fixture() def member_client(member): return get_api_client(user=member) diff --git a/app/tests/content/test_event_integration.py b/app/tests/content/test_event_integration.py index c135561e7..991f23460 100644 --- a/app/tests/content/test_event_integration.py +++ b/app/tests/content/test_event_integration.py @@ -5,7 +5,7 @@ import pytest -from app.common.enums import AdminGroup, GroupType, MembershipType +from app.common.enums import AdminGroup, Groups, GroupType, MembershipType from app.content.factories import EventFactory, RegistrationFactory, UserFactory from app.content.models import Event from app.forms.enums import EventFormType @@ -634,3 +634,13 @@ def test_expired_filter_list(api_client, admin_user, expired, expected_count): actual_count = response.json().get("count") assert actual_count == expected_count + + +@pytest.mark.django_db +def test_jubkom_has_create_permission(api_client, jubkom_member): + client = api_client(user=jubkom_member) + organizer = Group.objects.get(name=Groups.JUBKOM).slug + data = get_event_data(organizer=organizer) + response = client.post(API_EVENTS_BASE_URL, data) + + assert response.status_code == status.HTTP_201_CREATED diff --git a/setup.cfg b/setup.cfg index 3c15c1ac1..3b9818bcd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,7 +48,7 @@ omit = [flake8] ignore = # Ignore the flake8-warnings that are incompatible with Black-formatting - E203, E231, W503E203, E266, E501, W503 + E203, E231, E266, E501, W503 max-line-length = 80 max-complexity = 10 inline-quotes = "double" @@ -73,4 +73,4 @@ exclude = */migrations # Settings are temporarily excluded. - settings.py \ No newline at end of file + settings.py