Skip to content

Commit

Permalink
Finalize permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyStk committed Feb 18, 2025
1 parent a6e3a8f commit 2eda342
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
6 changes: 4 additions & 2 deletions integreat_cms/cms/constants/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
*EVENT_MANAGER_PERMISSIONS,
"change_page",
"view_page",
"view_contact",
"change_contact",
]


Expand Down Expand Up @@ -144,6 +146,7 @@
"view_translation_report",
"view_broken_links",
"view_statistics",
"view_contact",
]

#: The permissions of the app team
Expand All @@ -165,6 +168,7 @@
"replace_mediafile",
"send_push_notification",
"upload_mediafile",
"change_contact",
]

#: The permissions of the service team
Expand Down Expand Up @@ -194,9 +198,7 @@
"delete_user",
"grant_page_permissions",
"manage_translations",
"change_contact",
"delete_contact",
"view_contact",
"view_externalcalendar",
]

Expand Down
2 changes: 2 additions & 0 deletions integreat_cms/release_notes/current/unreleased/2955.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en: Add contact management
de: Füge Kontaktverwaltung hinzu
17 changes: 12 additions & 5 deletions tests/cms/views/contacts/test_contact_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
from django.urls import reverse

from integreat_cms.cms.models import Contact
from tests.conftest import ANONYMOUS, HIGH_PRIV_STAFF_ROLES
from tests.conftest import (
ANONYMOUS,
AUTHOR,
EDITOR,
HIGH_PRIV_STAFF_ROLES,
MANAGEMENT,
PRIV_STAFF_ROLES,
)
from tests.utils import assert_message_in_log

# Use the region Augsburg, as it has some contacts in the test data
Expand Down Expand Up @@ -55,7 +62,7 @@ def test_archive_contact(
)
response = client.post(archive_contact)

if role in HIGH_PRIV_STAFF_ROLES:
if role in (*PRIV_STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert response.status_code == 302
redirect_url = response.headers.get("location")
if should_be_archived:
Expand Down Expand Up @@ -181,7 +188,7 @@ def test_restore_contact(
)
response = client.post(restore_contact)

if role in HIGH_PRIV_STAFF_ROLES:
if role in (*PRIV_STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert response.status_code == 302
redirect_url = response.headers.get("location")
assert_message_in_log(
Expand Down Expand Up @@ -237,7 +244,7 @@ def test_bulk_archive_contacts(
data={"selected_ids[]": BULK_ARCHIVE_SELECTED_IDS},
)

if role in HIGH_PRIV_STAFF_ROLES:
if role in (*PRIV_STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert response.status_code == 302
redirect_url = response.headers.get("location")
redirect_page = client.get(redirect_url).content.decode("utf-8")
Expand Down Expand Up @@ -366,7 +373,7 @@ def test_bulk_restore_contacts(
data={"selected_ids[]": BULK_RESTORE_SELECTED_IDS},
)

if role in HIGH_PRIV_STAFF_ROLES:
if role in (*PRIV_STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert response.status_code == 302
redirect_url = response.headers.get("location")
redirect_page = client.get(redirect_url).content.decode("utf-8")
Expand Down
12 changes: 6 additions & 6 deletions tests/cms/views/contacts/test_contact_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from integreat_cms.cms.forms import ContactForm
from integreat_cms.cms.models import Contact, Region
from tests.conftest import ANONYMOUS, HIGH_PRIV_STAFF_ROLES
from tests.conftest import ANONYMOUS, AUTHOR, EDITOR, MANAGEMENT, PRIV_STAFF_ROLES
from tests.utils import assert_message_in_log

# Use the region Augsburg, as it has some contacts in the test data
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_create_a_new_contact(
},
)

if role in HIGH_PRIV_STAFF_ROLES:
if role in (*PRIV_STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert_message_in_log(
'SUCCESS Contact for "Draft location with area of responsibility: Title" was successfully created',
caplog,
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_edit_a_contact(
},
)

if role in HIGH_PRIV_STAFF_ROLES:
if role in (*PRIV_STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert_message_in_log(
'SUCCESS Contact for "Draft location with area of responsibility: Title Updated" was successfully saved',
caplog,
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_no_contact_without_poi(
},
)

if role in HIGH_PRIV_STAFF_ROLES:
if role in (*PRIV_STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert_message_in_log(
"ERROR Location: This field is required.",
caplog,
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_at_least_one_field_filled(
},
)

if role in HIGH_PRIV_STAFF_ROLES:
if role in (*PRIV_STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert_message_in_log(
"ERROR One of the following fields must be filled: area of responsibility, name, e-mail, phone number, website.",
caplog,
Expand Down Expand Up @@ -270,7 +270,7 @@ def test_one_primary_contact_per_poi(
},
)

if role in HIGH_PRIV_STAFF_ROLES:
if role in (*PRIV_STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert_message_in_log(
"ERROR Only one contact per location can have an empty area of responsibility.",
caplog,
Expand Down
7 changes: 5 additions & 2 deletions tests/cms/views/poi/test_poi_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
)
from tests.conftest import (
ANONYMOUS,
AUTHOR,
EDITOR,
HIGH_PRIV_STAFF_ROLES,
MANAGEMENT,
PRIV_STAFF_ROLES,
STAFF_ROLES,
WRITE_ROLES,
)
from tests.utils import assert_message_in_log
Expand Down Expand Up @@ -311,8 +315,7 @@ def test_poi_form_shows_no_associated_contacts(
assert (
response.headers.get("location") == f"{settings.LOGIN_URL}?next={edit_poi}"
)
# probably needs adjustment after #2958
elif role in HIGH_PRIV_STAFF_ROLES:
if role in (*STAFF_ROLES, MANAGEMENT, EDITOR, AUTHOR):
assert (
"This location is not currently referred to in any contact."
in response.content.decode("utf-8")
Expand Down

0 comments on commit 2eda342

Please sign in to comment.