Skip to content

Commit

Permalink
Merge pull request #3238 from GeotrekCE/fix_attachments_message
Browse files Browse the repository at this point in the history
Fix error message on attachments from other structures
  • Loading branch information
Chatewgne authored Sep 19, 2022
2 parents c6189de + 1696281 commit 58d7e0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CHANGELOG

- Fix Site creation form is initialized with parent Site
- Fix memory leak and optimize SQL queries on zoning intersections
- Fix error message should not be displayed on attachments from the same structure as user

**Maintenance**

Expand Down
11 changes: 7 additions & 4 deletions geotrek/common/templates/common/attachment_list.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{% extends "paperclip/attachment_list.html" %}
{% load i18n %}


{% block info_list_attachments %}
<div class="alert alert-warning">
{% trans "You are not allowed to modify attachments on this object, this object is not from the same structure." %}
</div>
{% if not user.profile.structure == object.structure and not perms.authent.can_bypass_structure %}
<div class="alert alert-warning">
{% trans "You are not allowed to modify attachments on this object, this object is not from the same structure." %}
</div>
{% endif %}
{% endblock info_list_attachments %}

{% block permissions_add_attachment %}
Expand All @@ -15,4 +18,4 @@

{% block inclusion_attachment_table %}
{% include "common/attachment_table.html" %}
{% endblock inclusion_attachment_table %}
{% endblock inclusion_attachment_table %}
3 changes: 2 additions & 1 deletion geotrek/common/tests/test_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from django.urls import reverse
from geotrek.authent.tests.factories import StructureFactory

from mapentity.tests.factories import SuperUserFactory, UserFactory
from geotrek.common.models import AccessibilityAttachment, Attachment
Expand Down Expand Up @@ -46,7 +47,7 @@ def user_perms(p):
return {'paperclip.add_attachment': False}.get(p, True)
cls.user = UserFactory()
cls.user.has_perm = mock.MagicMock(side_effect=user_perms)
cls.object = TrekFactory.create()
cls.object = TrekFactory.create(structure=StructureFactory(name="Another structure"))
call_command('update_permissions_mapentity', verbosity=0)

def createRequest(self):
Expand Down

0 comments on commit 58d7e0b

Please sign in to comment.