Skip to content

Commit

Permalink
fix: add basic auth check
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Nov 14, 2023
1 parent 9e960fc commit c1279fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
<ul class="list-group list-group-flush">
{% for reference in object_list %}
<li class="list-group-item justify-content-between align-items-center d-flex">
{% if request.user.is_authenticated %}
<a href="{{ reference.get_absolute_url }}">{{ reference }} ({{ reference.id }})</a>
<a href="{% url "apis_bibsonomy:referencedelete" reference.id %}?redirect={{ request.path }}"
hx-delete="{% url "apis_bibsonomy:referencedelete" reference.id %}"
hx-confirm="Are your sure you want to delete reference {{ reference }} for {{ reference.referenced_object }}"
hx-target="closest li"
hx-swap="outerHTML swap:1s">Delete</a>
{% else %}
{{ reference }}
{% endif %}
</li>
{% empty %}
<li>No references yet.</li>
Expand Down
7 changes: 6 additions & 1 deletion apis_bibsonomy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.views.generic.edit import DeleteView, FormMixin, ProcessFormView
from django.urls import reverse_lazy, reverse
from django.http import Http404
from django.contrib.auth.mixins import LoginRequiredMixin

from .models import Reference
from .forms import ReferenceNewForm
Expand All @@ -18,7 +19,7 @@ def get_context_data(self, **kwargs):
return context


class ReferenceDeleteView(DeleteView):
class ReferenceDeleteView(LoginRequiredMixin, DeleteView):
model = Reference

def get_success_url(self):
Expand Down Expand Up @@ -50,12 +51,16 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["contenttype"] = self.contenttype
context["object"] = self.contenttype.get_object_for_this_type(id=self.pk)
if not self.request.user.is_authenticated:
del context["form"]
return context

def get_success_url(self):
return reverse('apis_bibsonomy:referenceonlist', kwargs=self.request.resolver_match.kwargs)

def form_valid(self, form):
if not self.request.user.is_authenticated:
return super().form_invalid(form)
args = form.cleaned_data
# we store the data about the last entered entry in the session
# so we can automatically fill the form with the last reference
Expand Down

0 comments on commit c1279fa

Please sign in to comment.