fix: hide delete button for editors in dashboard

fix #1739
This commit is contained in:
Yohan Boniface 2024-04-16 11:32:00 +02:00
parent 05fd33deb7
commit d3bf9fcdf0
3 changed files with 17 additions and 0 deletions

View file

@ -68,6 +68,7 @@
<span class="sr-only">{% translate "Clone" %}</span> <span class="sr-only">{% translate "Clone" %}</span>
</button> </button>
</form> </form>
{% if map_inst|can_delete_map:request %}
<form action="{% url 'map_delete' map_inst.pk %}" <form action="{% url 'map_delete' map_inst.pk %}"
method="post" method="post"
class="map-delete"> class="map-delete">
@ -78,6 +79,7 @@
<span class="sr-only">{% translate "Delete" %}</span> <span class="sr-only">{% translate "Delete" %}</span>
</button> </button>
</form> </form>
{% endif %}
</td> </td>
</tr> </tr>
{% endwith %} {% endwith %}

View file

@ -43,6 +43,11 @@ def tilelayer_preview(tilelayer):
return output return output
@register.filter
def can_delete_map(map, request):
return map.can_delete(request.user, request)
@register.filter @register.filter
def notag(s): def notag(s):
return s.replace("<", "&lt;") return s.replace("<", "&lt;")

View file

@ -36,3 +36,13 @@ def test_dashboard_map_preview(map, live_server, datalayer, login):
expect(dialog).to_be_visible() expect(dialog).to_be_visible()
# Let's check we have a marker on it, so we can guess the map loaded correctly # Let's check we have a marker on it, so we can guess the map loaded correctly
expect(dialog.locator(".leaflet-marker-icon")).to_be_visible() expect(dialog.locator(".leaflet-marker-icon")).to_be_visible()
def test_no_delete_button_for_editors(map, live_server, datalayer, login, user):
map.name = "Map I cannot delete"
map.editors.add(user)
map.save()
page = login(user)
page.goto(f"{live_server.url}/en/me")
expect(page.get_by_text("Map I cannot delete")).to_be_visible()
expect(page.get_by_title("Delete")).to_be_hidden()