Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added celerybeat-schedule-shm
Binary file not shown.
Binary file added celerybeat-schedule-wal
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<input type="checkbox"
id="auto-fill-coordinates"
data-url="{% url "auto_complete_place_address" region_slug=request.region.slug %}"
checked />
checked
{% if place_form.instance.archived or not perms.cms.change_place %}disabled{% endif %} />
<label for="auto-fill-coordinates" class="secondary !inline">
{% translate "Derive coordinates automatically from address" %}
</label>
Expand All @@ -53,12 +54,12 @@
class="aspect-video"
data-url="{% url "get_address_from_coordinates" region_slug=request.region.slug %}"
data-bounding-box="{{ request.region.bounding_box.api_representation }}"
data-change-permission="{{ perms.cms.change_place }}"></div>
data-change-permission="{{ disabled }}"></div>
<div id="set_map_position_text" class="help-text hidden">
{% translate "You can set the position by clicking on the map" %}
</div>
<div id="change_map_position_text" class="help-text hidden">
{% if perms.cms.change_place %}
{% if perms.cms.change_place and not place_form.instance.archived %}
{% translate "You can change the position via drag & drop" %}
{% endif %}
</div>
Expand Down
4 changes: 3 additions & 1 deletion integreat_cms/cms/views/places/place_context_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
opening_hour_config_data = get_open_hour_config_data(
related_class=self.related_class,
can_change_place=self.request.user.has_perm("cms.change_place"),
can_change_place=kwargs.get(
"can_change_place", self.request.user.has_perm("cms.change_place")
),
)
context.update(
{
Expand Down
3 changes: 2 additions & 1 deletion integreat_cms/cms/views/places/place_form_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
request,
self.template_name,
{
**self.get_context_data(**kwargs),
**self.get_context_data(**kwargs, can_change_place=not disabled),
"place_form": place_form,
"place_translation_form": place_translation_form,
"language": language,
Expand All @@ -117,6 +117,7 @@ def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
"contact_form": contact_form,
"show_contact_form_widget": False,
"is_edit": is_edit,
"disabled": disabled,
},
)

Expand Down
20 changes: 13 additions & 7 deletions integreat_cms/static/src/js/places/place-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,26 @@ const renderMap = () => {
// Initialize map and marker
const map = new Map(options);
const marker = new Marker();
marker.setDraggable(container.dataset.changePermission === "True");

const canChangePlace = container.dataset.changePermission === "False";
marker.setDraggable(canChangePlace);

// If initial coordinates are given, set the marker to this position
if (coordinates) {
marker.setLngLat(coordinates).addTo(map);
}

// Support setting the marker both via drag & drop and via clicking on the map
map.on("click", (event: MapMouseEvent) => {
marker.setLngLat(event.lngLat).addTo(map);
updateHelpText(event.lngLat);
fetchAddress(marker);
});
marker.on("dragend", () => fetchAddress(marker));
// Only allow changing the position when editing is permitted
if (canChangePlace) {
map.on("click", (event: MapMouseEvent) => {
marker.setLngLat(event.lngLat).addTo(map);
updateHelpText(event.lngLat);
fetchAddress(marker);
});

marker.on("dragend", () => fetchAddress(marker));
}

// Set the initial zoom
map.on("load", map.resize);
Expand Down
49 changes: 49 additions & 0 deletions tests/cms/views/place/test_place_form.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
import re
from datetime import timedelta
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -742,3 +743,51 @@ def test_case_insensitive_unique_slug(

assert PlaceTranslation.objects.filter(slug="slug").count() == 1
assert PlaceTranslation.objects.filter(slug="slug-2").count() == 1


@pytest.mark.django_db
@pytest.mark.parametrize("archived", [True, False])
def test_place_editing_controls_respect_archived_state(
load_test_data: None,
client: Client,
archived: bool,
) -> None:
# Log in as a user with editing permission
user = get_user_model().objects.get(username="root")
client.force_login(user)

# Get a test place and set its archived status
place = Place.objects.get(id=4)
place.archived = archived
place.save(update_fields=["archived"])

# Open the place editing page
url = reverse(
"edit_place",
kwargs={
"region_slug": "augsburg",
"language_slug": "de",
"place_id": place.id,
},
)
response = client.get(url)

assert response.status_code == 200

# Check opening-hours editing permission
config = response.context["opening_hour_config_data"]
assert config["canChangePlace"] is not archived

html = response.content.decode("utf-8")

# Check map editing permission
expected_permission = "True" if archived else "False"
assert f'data-change-permission="{expected_permission}"' in html

# Check automatic-coordinates checkbox
checkbox = re.search(
r'<input\b[^>]*\bid="auto-fill-coordinates"[^>]*>',
html,
)
assert checkbox is not None
assert ("disabled" in checkbox.group(0)) is archived
Loading