Allow photo owners to delete their own photos

This commit is contained in:
krek0 2026-04-20 22:56:05 +02:00
parent a875c2707b
commit 71937f5c4d
3 changed files with 16 additions and 4 deletions

View file

@ -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(`<a href="#" id="lg-delete" title="Remove this photo" class="lg-icon lg-bi-icon">${deleteIcon}</a>`);
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