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
|
|
@ -121,6 +121,17 @@ class PhotoReportView(DetailView):
|
|||
return redirect(url)
|
||||
|
||||
|
||||
class PhotoUncensorView(LoginRequiredMixin, View):
|
||||
def post(self, request, pk):
|
||||
if not request.user.has_perm("photologue.can_resolve_censorship"):
|
||||
from django.core.exceptions import PermissionDenied
|
||||
raise PermissionDenied
|
||||
photo = get_object_or_404(Photo, pk=pk)
|
||||
photo.is_public = True
|
||||
photo.save()
|
||||
return JsonResponse({"ok": True})
|
||||
|
||||
|
||||
class TagDetail(LoginRequiredMixin, DetailView):
|
||||
model = Tag
|
||||
|
||||
|
|
@ -146,8 +157,11 @@ class GalleryDetailView(LoginRequiredMixin, DetailView):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
can_resolve = self.request.user.has_perm("photologue.can_resolve_censorship")
|
||||
context["can_resolve_censorship"] = can_resolve
|
||||
|
||||
# Non-staff members only see public photos + prefetch all owners informations (Optimisation)
|
||||
if self.request.user.is_staff:
|
||||
if self.request.user.is_staff or can_resolve:
|
||||
context["photos"] = self.object.photos.all().select_related("owner")
|
||||
else:
|
||||
context["photos"] = self.object.photos.filter(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue