diff --git a/photologue/static/lightgallery/plugins/admin/lg-admin.js b/photologue/static/lightgallery/plugins/admin/lg-admin.js index 8b83e33..19b8ca4 100644 --- a/photologue/static/lightgallery/plugins/admin/lg-admin.js +++ b/photologue/static/lightgallery/plugins/admin/lg-admin.js @@ -11,6 +11,7 @@ class lgAdmin { this.core = instance; this.$LG = $LG; this.isStaff = document.querySelector('[name=is_staff]').value === "true"; + this.userId = document.querySelector('[name=user_id]').value; this.csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value; this.photoId = 0; return this; @@ -27,7 +28,7 @@ class lgAdmin { // Add button to delete photo this.core.$toolbar.append(`${deleteIcon}`); - document.getElementById("lg-delete").style.display = this.isStaff ? 'block' : 'none'; + document.getElementById("lg-delete").style.display = 'none'; document.getElementById("lg-delete").addEventListener('click', this.onDelete.bind(this)); // Add button to report photo @@ -41,6 +42,10 @@ class lgAdmin { onAfterSlide(event) { this.photoId = this.core.galleryItems[event.detail.index].slideName; document.getElementById("lg-admin").href = `/admin/photologue/photo/${this.photoId}/change/`; + const el = document.querySelector(`[data-slide-name='${this.photoId}']`); + const ownerId = el ? el.dataset.ownerId : null; + const canDelete = this.isStaff || (ownerId && ownerId === this.userId); + document.getElementById("lg-delete").style.display = canDelete ? 'block' : 'none'; } // Event called when user click on delete button diff --git a/photologue/templates/photologue/gallery_detail.html b/photologue/templates/photologue/gallery_detail.html index c317ff2..9771b23 100644 --- a/photologue/templates/photologue/gallery_detail.html +++ b/photologue/templates/photologue/gallery_detail.html @@ -18,6 +18,7 @@ SPDX-License-Identifier: GPL-3.0-or-later {# Javascript code fetches CSRF token from HTML #} {% csrf_token %} + @@ -87,7 +88,7 @@ SPDX-License-Identifier: GPL-3.0-or-later {% endif %}