Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tapir/log/templates/log/log_entry_list_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ <h5 class="card-header d-flex justify-content-between align-items-center flex-wr
<span class="material-icons">manage_search</span>
{% translate 'See all log entries' %}
</a>
{% if perms.accounts.manage %}
<a class="{% tapir_button_link %}"
href="{% url 'log:delete_logs' share_owner_id %}">
<span class="material-icons">delete_sweep</span>
{% translate 'Delete' %}
</a>
{% endif %}
</span>
</h5>
<div class="card-body">
Expand Down
55 changes: 55 additions & 0 deletions tapir/log/templates/log/logentry_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% extends "core/base.html" %}
{% load django_bootstrap5 %}
{% load i18n %}
{% load coop %}
{% load static %}
{% load core %}
{% block head %}
{{ block.super }}
<link rel="stylesheet" href="{% static "coop/css/coop.css" %}">
<style>
.select2 {
width: 100%!important;
}
</style>
{{ filter.form.media }}
{% endblock head %}
{% block content %}
<div class="card m-2">
<div class="card-header">
<div class="d-flex flex-row justify-content-between">
<div class="col-6 d-flex flex-column justify-content-center">
<h5 style="margin-bottom: 0">
<span class="material-icons align-middle">warning</span>
{% translate "Delete all log entries?" %}
</h5>
</div>
</div>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<p>
{% blocktranslate with name=share_owner.get_display_name|default:share_owner count=log_count %}
You are about to permanently delete <strong>{{ count }} log entries</strong> for <strong>{{ name }}</strong>.
{% endblocktranslate %}
</p>
<div class="alert alert-danger" role="alert">
<strong>{% translate "Warning:" %}</strong>
{% translate "This action cannot be undone!" %}
{% translate "This action may skew statistics based on the logs!" %}
</div>
</li>
<li class="list-group-item d-flex justify-content-end gap-2">
<a class="{% tapir_button_link %}"
href="{% url 'coop:shareowner_detail' share_owner.pk %}">{% translate "Cancel" %}</a>
<form method="post" style="display: inline;">
{% csrf_token %}
<button type="submit" class="btn tapir-btn btn-danger">
<span class="material-icons">delete_sweep</span>
{% translate "Delete all logs" %}
</button>
</form>
</li>
</ul>
</div>
{% endblock content %}
2 changes: 2 additions & 0 deletions tapir/log/templatetags/tapir_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def log_entry_list(context, **kwargs):
share_owner_id = tapir_user.share_owner.id
elif share_owner:
share_owner_id = share_owner.id
else:
share_owner_id = tapir_user.id
context["share_owner_id"] = share_owner_id

context["create_text_log_entry_action_url"] = reverse(
Expand Down
5 changes: 5 additions & 0 deletions tapir/log/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
views.LogTableView.as_view(),
name="log_overview",
),
path(
"delete/<int:share_owner_id>/",
views.DeleteLogsView.as_view(),
name="delete_logs",
),
]
39 changes: 36 additions & 3 deletions tapir/log/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import django_filters
import django_tables2
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q, QuerySet
from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import get_object_or_404
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.translation import gettext_lazy as _
from django.views import View
from django.views.decorators.http import require_GET, require_POST
from django_filters import DateRangeFilter
from django_filters.views import FilterView
Expand All @@ -20,7 +21,10 @@
from tapir.log.forms import CreateTextLogEntryForm
from tapir.log.models import EmailLogEntry, LogEntry, TextLogEntry
from tapir.log.util import freeze_for_log
from tapir.settings import PERMISSION_COOP_MANAGE, PERMISSION_COOP_VIEW
from tapir.settings import (
PERMISSION_COOP_MANAGE,
PERMISSION_COOP_VIEW,
)
from tapir.utils.filters import ShareOwnerModelChoiceFilter, TapirUserModelChoiceFilter
from tapir.utils.shortcuts import (
safe_redirect,
Expand Down Expand Up @@ -182,3 +186,32 @@ def get_queryset(self):
if not self.request.user.has_perm(PERMISSION_COOP_VIEW):
return queryset.filter(user=self.request.user)
return queryset


class DeleteLogsView(LoginRequiredMixin, PermissionRequiredMixin, View):

permission_required = "accounts.manage"
raise_exception = True
template_name = "log/logentry_confirm_delete.html"

def get(self, request, share_owner_id):
share_owner = get_object_or_404(ShareOwner, pk=share_owner_id)
log_count = LogEntry.objects.filter(share_owner=share_owner).count()

if log_count == 0:
log_count = LogEntry.objects.filter(user=share_owner.user).count()

context = {
"share_owner": share_owner,
"log_count": log_count,
}
return render(request, self.template_name, context)

def post(self, request, share_owner_id):
share_owner = get_object_or_404(ShareOwner, pk=share_owner_id)

deleted_count, _ = LogEntry.objects.filter(share_owner=share_owner).delete()
if deleted_count == 0:
deleted_count, _ = LogEntry.objects.filter(user=share_owner.user).delete()

return redirect(share_owner.user.get_absolute_url())
56 changes: 45 additions & 11 deletions tapir/translations/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ msgstr "Du kannst nur deinen eigenen Strichcode sehen, es sei denn du hast Admin

#: accounts/templates/accounts/user_detail.html:20 coop/models.py:724
#: coop/templates/coop/draftuser_detail.html:86
#: coop/templates/coop/shareowner_detail.html:10 log/views.py:94
#: log/views.py:152 shifts/templates/shifts/shift_detail_printable.html:50
#: coop/templates/coop/shareowner_detail.html:10 log/views.py:98
#: log/views.py:156 shifts/templates/shifts/shift_detail_printable.html:50
msgid "Member"
msgstr "Mitglied"

Expand Down Expand Up @@ -960,6 +960,7 @@ msgstr "Löschen bestätigen"
#: coop/templates/coop/confirm_delete_share_ownership.html:24
#: coop/templates/coop/tags/user_coop_share_ownership_list_tag.html:135
#: financingcampaign/templates/financingcampaign/confirm_delete.html:24
#: log/templates/log/log_entry_list_tag.html:19
#: shifts/templates/shifts/shift_confirm_delete.html:30
msgid "Delete"
msgstr "Löschen"
Expand Down Expand Up @@ -2089,6 +2090,7 @@ msgid "Submit"
msgstr "Abschicken"

#: coop/templates/coop/extra_share_request.html:92
#: log/templates/log/logentry_confirm_delete.html:44
#: shifts/templates/shifts/user_shifts_overview_tag.html:177
msgid "Cancel"
msgstr "Abmelden"
Expand Down Expand Up @@ -2946,7 +2948,7 @@ msgid "The list of all datapoints"
msgstr ""

#: financingcampaign/templates/financingcampaign/general.html:111
#: log/templates/log/log_entry_list_tag.html:23
#: log/templates/log/log_entry_list_tag.html:30
#: shifts/templates/shifts/user_shift_account_log.html:26
#: statistics/templates/statistics/tags/credit_account_card.html:17
#: statistics/templates/statistics/tags/purchase_statistics_card.html:18
Expand Down Expand Up @@ -3013,29 +3015,61 @@ msgstr "Letzte 5 Log-Einträge"
msgid "See all log entries"
msgstr "Alle Log-Einträge einsehen"

#: log/templates/log/log_entry_list_tag.html:20
#: log/templates/log/log_entry_list_tag.html:27
msgid "List of log entries for this member"
msgstr "Liste der Protokoll-Einträge für dieses Mitglied"

#: log/templates/log/log_entry_list_tag.html:24 log/views.py:97
#: log/views.py:151
#: log/templates/log/log_entry_list_tag.html:31 log/views.py:101
#: log/views.py:155
msgid "Actor"
msgstr "Sender*in"

#: log/templates/log/log_entry_list_tag.html:25 log/views.py:90
#: log/templates/log/log_entry_list_tag.html:32 log/views.py:94
msgid "Message"
msgstr "Nachricht"

#: log/templates/log/log_entry_list_tag.html:57
#: log/templates/log/log_entry_list_tag.html:58
#: log/templates/log/log_entry_list_tag.html:64
#: log/templates/log/log_entry_list_tag.html:65
msgid "Notes about this user"
msgstr "Notizen über diese*n Benutzer*in"

#: log/templates/log/log_entry_list_tag.html:63
#: log/templates/log/log_entry_list_tag.html:70
msgid "Add Note"
msgstr "Notiz hinzufügen"

#: log/views.py:153
#: log/templates/log/logentry_confirm_delete.html:24
#, fuzzy
#| msgid "See all log entries"
msgid "Delete all log entries?"
msgstr "Alle Log-Einträge einsehen"

#: log/templates/log/logentry_confirm_delete.html:32
#, python-format
msgid ""
"\n"
" You are about to permanently delete <strong>%(count)s log entries</strong> for <strong>%(name)s</strong>.\n"
" "
msgstr ""

#: log/templates/log/logentry_confirm_delete.html:37
msgid "Warning:"
msgstr ""

#: log/templates/log/logentry_confirm_delete.html:38
msgid "This action cannot be undone!"
msgstr ""

#: log/templates/log/logentry_confirm_delete.html:39
msgid "This action may skew statistics based on the logs!"
msgstr ""

#: log/templates/log/logentry_confirm_delete.html:49
#, fuzzy
#| msgid "See all log entries"
msgid "Delete all logs"
msgstr "Alle Log-Einträge einsehen"

#: log/views.py:157
msgid "Log Type"
msgstr ""

Expand Down
Loading