Add can_resolve_censorship permission and uncensor feature
- Add custom permission to Photo model - Add PhotoUncensorView POST endpoint to restore private photos - Show private photos to users with can_resolve_censorship - Add restore button in lightgallery toolbar for censored photos
This commit is contained in:
parent
40352cffee
commit
f5ccb40e16
6 changed files with 71 additions and 2 deletions
|
|
@ -12,6 +12,7 @@ class lgAdmin {
|
|||
this.$LG = $LG;
|
||||
this.isStaff = document.querySelector('[name=is_staff]').value === "true";
|
||||
this.userId = document.querySelector('[name=user_id]').value;
|
||||
this.canResolveCensorship = document.querySelector('[name=can_resolve_censorship]').value === "true";
|
||||
this.csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
||||
this.photoId = 0;
|
||||
return this;
|
||||
|
|
@ -35,6 +36,12 @@ class lgAdmin {
|
|||
this.core.$toolbar.append(`<a href="#" id="lg-report" title="Notify abuse" class="lg-icon lg-bi-icon">${reportIcon}</a>`);
|
||||
document.getElementById("lg-report").addEventListener('click', this.onReport.bind(this));
|
||||
|
||||
// Add button to restore a censored photo
|
||||
const restoreIcon = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" fill=\"currentColor\" class=\"bi\" viewBox=\"0 0 16 16\"><path d=\"M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z\"/><path d=\"M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z\"/></svg>";
|
||||
this.core.$toolbar.append(`<a href="#" id="lg-restore" title="Restore photo (remove censorship)" class="lg-icon lg-bi-icon">${restoreIcon}</a>`);
|
||||
document.getElementById("lg-restore").style.display = 'none';
|
||||
document.getElementById("lg-restore").addEventListener('click', this.onRestore.bind(this));
|
||||
|
||||
this.core.LGel.on("lgAfterSlide.admin", this.onAfterSlide.bind(this));
|
||||
}
|
||||
|
||||
|
|
@ -46,6 +53,31 @@ class lgAdmin {
|
|||
const ownerId = el ? el.dataset.ownerId : null;
|
||||
const canDelete = this.isStaff || (ownerId && ownerId === this.userId);
|
||||
document.getElementById("lg-delete").style.display = canDelete ? 'block' : 'none';
|
||||
const isCensored = el ? el.dataset.isPublic === 'false' : false;
|
||||
document.getElementById("lg-restore").style.display = (this.canResolveCensorship && isCensored) ? 'block' : 'none';
|
||||
}
|
||||
|
||||
// Event called when user clicks the restore (uncensor) button
|
||||
onRestore(event) {
|
||||
event.preventDefault();
|
||||
if(confirm("Restore this photo and make it public again?")) {
|
||||
const photoId = this.photoId;
|
||||
let data = new FormData();
|
||||
data.append('csrfmiddlewaretoken', this.csrfToken);
|
||||
fetch(`/photo/${photoId}/uncensor/`, {
|
||||
method: "POST",
|
||||
body: data,
|
||||
credentials: 'same-origin',
|
||||
}).then(() => {
|
||||
const el = document.querySelector(`[data-slide-name='${photoId}']`);
|
||||
if (el) {
|
||||
el.dataset.isPublic = 'true';
|
||||
const img = el.querySelector('img');
|
||||
if (img) img.classList.remove('border-danger', 'border-5');
|
||||
}
|
||||
document.getElementById("lg-restore").style.display = 'none';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Navigate away from a photo that was just deleted/hidden.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue