diff --git a/README.md b/README.md index b340c76..4656695 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,6 @@ Those files are markdown files that are rendered as HTML. You have to supply the The following files are expected: * `imprint.md` with your imprint information. -* `privacy_policy.md` with your privacy policy. ## Settings @@ -177,13 +176,3 @@ BORG_SERVER_PUBKEYS = [ ), ] ``` - -## Webserver Config / Content-Security-Policy - -This page by itself does not load external sources and does not use inline javascript/styling. -It only loads javascript, CSS and images. -Therefore the following Content-Security-Policy should work fine in the standard cases: - -``` -Content-Security-Policy "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self';" -``` diff --git a/community_backup/community_backup/settings.py b/community_backup/community_backup/settings.py index b733ca7..fc103fc 100644 --- a/community_backup/community_backup/settings.py +++ b/community_backup/community_backup/settings.py @@ -120,7 +120,7 @@ STATICFILES_DIRS = [ BASE_DIR / "static", ] -RELEASE_VERSION = "0.15" +RELEASE_VERSION = "0.13" # Import settings from configuration.py try: diff --git a/community_backup/static/webui/css/webui.css b/community_backup/static/webui/css/webui.css index 514ae45..40cedd4 100644 --- a/community_backup/static/webui/css/webui.css +++ b/community_backup/static/webui/css/webui.css @@ -1,7 +1,5 @@ -body { - display: flex; - flex-direction: column; - height: 100vh; +h1 { + font-size: 2rem } .pixelart { @@ -12,7 +10,3 @@ body { min-width: 32px; min-height: 32px; } - -.word-break-break-all { - word-break: break-all; -} diff --git a/community_backup/static/webui/js/webui.js b/community_backup/static/webui/js/webui.js deleted file mode 100644 index 03da0f8..0000000 --- a/community_backup/static/webui/js/webui.js +++ /dev/null @@ -1,24 +0,0 @@ -// -// Activation script for the bulma burger menu. -// Copied from https://bulma.io/documentation/components/navbar/ -// -document.addEventListener('DOMContentLoaded', () => { - - // Get all "navbar-burger" elements - const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0); - - // Add a click event on each of them - $navbarBurgers.forEach( el => { - el.addEventListener('click', () => { - - // Get the target from the "data-target" attribute - const target = el.dataset.target; - const $target = document.getElementById(target); - - // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu" - el.classList.toggle('is-active'); - $target.classList.toggle('is-active'); - - }); - }); -}); diff --git a/community_backup/webui/admin.py b/community_backup/webui/admin.py index 8f5f29c..7d0a18b 100644 --- a/community_backup/webui/admin.py +++ b/community_backup/webui/admin.py @@ -1,50 +1,7 @@ from django.contrib import admin -from django.urls import path, reverse_lazy -from django.views.generic import FormView -from django import forms from .models import BorgRepository, Voucher - -class VoucherBulkCreateForm(forms.Form): - prefix = forms.CharField(label="Voucher prefix") - amount = forms.IntegerField(label="Amount") - - -class VoucherBulkCreateView(FormView): - form_class = VoucherBulkCreateForm - template_name = "admin/bulk_generate.html" - admin_site_context = None - success_url = reverse_lazy("admin:webui_voucher_changelist") - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - # inject the admin site context so that the navbar and other things work as intended - context.update(self.admin_site_context.each_context(self.request)) - return context - - def form_valid(self, form): - Voucher.bulk_generate(form.cleaned_data["prefix"], form.cleaned_data["amount"]) - return super().form_valid(form) - - -@admin.register(Voucher) -class VoucherAdmin(admin.ModelAdmin): - change_list_template = "admin/voucher_change_list.html" - - def get_urls(self): - urls = super().get_urls() - my_urls = [ - path( - "bulk_generate/", - self.admin_site.admin_view( - VoucherBulkCreateView.as_view(admin_site_context=self.admin_site) - ), - name="voucher_bulk_generate", - ) - ] - return my_urls + urls - - # Register your models here. admin.site.register(BorgRepository) +admin.site.register(Voucher) diff --git a/community_backup/webui/management/commands/add_vouchers.py b/community_backup/webui/management/commands/add_vouchers.py index f8d0e6b..f983d92 100644 --- a/community_backup/webui/management/commands/add_vouchers.py +++ b/community_backup/webui/management/commands/add_vouchers.py @@ -11,7 +11,14 @@ class Command(BaseCommand): parser.add_argument("amount", type=int) def handle(self, *args, **options): - vouchers = Voucher.bulk_generate(options["prefix"], options["amount"]) + unabmigous_characters = "abcdefghijkmnopqrstuvwxyzACDEFHJKLMNPQRTUVWXY1234679" + + vouchers = set() + while len(vouchers) < options["amount"]: + random_part = "".join(choices(unabmigous_characters, k=5)) + vouchers.add(f"{options['prefix']}-{random_part}") + + Voucher.objects.bulk_create(Voucher(code=v) for v in vouchers) header = r"""\begin{document} \begin{center} diff --git a/community_backup/webui/models.py b/community_backup/webui/models.py index f5686d8..36e338f 100644 --- a/community_backup/webui/models.py +++ b/community_backup/webui/models.py @@ -1,12 +1,11 @@ -from random import choices -from pathlib import Path - from django.db import models from django.contrib.auth.models import User from django.core.validators import RegexValidator from django.conf import settings +from pathlib import Path import msgpack + from .tasks import update_user @@ -122,20 +121,3 @@ class Voucher(models.Model): def __str__(self): return f"Voucher '{self.code}'" - - @classmethod - def bulk_generate(cls, prefix: str, amount: int) -> set[str]: - """ - Create `amount` vouchers starting with `prefix`. - - Returns a set of the voucher codes as strings. - """ - unabmigous_characters = "abcdefghijkmnopqrstuvwxyzACDEFHJKLMNPQRTUVWXY1234679" - - vouchers = set() - while len(vouchers) < amount: - random_part = "".join(choices(unabmigous_characters, k=5)) - vouchers.add(f"{prefix}-{random_part}") - - Voucher.objects.bulk_create(Voucher(code=v) for v in vouchers) - return vouchers diff --git a/community_backup/webui/templates/admin/bulk_generate.html b/community_backup/webui/templates/admin/bulk_generate.html deleted file mode 100644 index b44f745..0000000 --- a/community_backup/webui/templates/admin/bulk_generate.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "admin/base_site.html" %} -{% block content %} -
-{% endblock %} diff --git a/community_backup/webui/templates/admin/voucher_change_list.html b/community_backup/webui/templates/admin/voucher_change_list.html deleted file mode 100644 index 6283e9c..0000000 --- a/community_backup/webui/templates/admin/voucher_change_list.html +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "admin/change_list.html" %} - -{% block object-tools-items %} - {{ block.super }} -