From ffc4d00da55eb8022f6cf4273b22f2207084e7ff Mon Sep 17 00:00:00 2001 From: Vasily Zubarev Date: Fri, 27 Dec 2024 15:28:05 +0100 Subject: [PATCH] feat: generate invite handler for godmode --- club/urls.py | 3 ++- frontend/html/invites/edit.html | 2 +- frontend/html/invites/list_invites.html | 7 ++++++ frontend/html/invites/show.html | 8 +++---- frontend/static/css/components/invites.css | 2 ++ landing/views.py | 25 ++++++++++++++++++++++ 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/club/urls.py b/club/urls.py index 4bd3a55db..ef475f38a 100644 --- a/club/urls.py +++ b/club/urls.py @@ -20,7 +20,7 @@ from common.feature_flags import feature_switch from invites.views import show_invite, list_invites, activate_invite from landing.views import landing, docs, godmode_network_settings, godmode_digest_settings, godmode_settings, \ - godmode_invite + godmode_invite, godmode_generate_invite_code from misc.fun import badge_generator, mass_note from misc.views import stats, network, robots, generate_ical_invite, generate_google_invite, show_achievement from rooms.views import redirect_to_room_chat, list_rooms, toggle_room_subscription, toggle_room_mute @@ -202,6 +202,7 @@ path("godmode/network/", godmode_network_settings, name="godmode_network_settings"), path("godmode/digest/", godmode_digest_settings, name="godmode_digest_settings"), path("godmode/invite/", godmode_invite, name="godmode_invite"), + path("godmode/generate_invite_code/", godmode_generate_invite_code, name="godmode_generate_invite_code"), path("godmode/dev_login/", debug_dev_login, name="debug_dev_login"), path("godmode/random_login/", debug_random_login, name="debug_random_login"), path("godmode/login//", debug_login, name="debug_login"), diff --git a/frontend/html/invites/edit.html b/frontend/html/invites/edit.html index 4a70370a7..d8ddda613 100644 --- a/frontend/html/invites/edit.html +++ b/frontend/html/invites/edit.html @@ -38,7 +38,7 @@

- Секретная ссылка, чтобы подарить её другу 👇 + Секретная ссылка, чтобы скопировать и подарить её другу 👇

diff --git a/frontend/html/invites/list_invites.html b/frontend/html/invites/list_invites.html index 1f28a68d6..8de6f08ec 100644 --- a/frontend/html/invites/list_invites.html +++ b/frontend/html/invites/list_invites.html @@ -24,6 +24,13 @@ + {% if request.me.is_god %} +
+

+ +
+ {% endif %} +
{% for invite in invites %} diff --git a/frontend/html/invites/show.html b/frontend/html/invites/show.html index ff1b331d9..6cbdc5132 100644 --- a/frontend/html/invites/show.html +++ b/frontend/html/invites/show.html @@ -6,12 +6,12 @@ {% block content %} {% endblock %} diff --git a/frontend/static/css/components/invites.css b/frontend/static/css/components/invites.css index 319634f60..cdcaf0ba0 100644 --- a/frontend/static/css/components/invites.css +++ b/frontend/static/css/components/invites.css @@ -15,6 +15,7 @@ display: flex; flex-wrap: wrap; flex-direction: row; + align-items: center; gap: 20px; justify-content: space-between; } @@ -29,5 +30,6 @@ } .badge-invite-used, .badge-invite-expired { + color: var(--opposite-text-color); background-color: var(--opposite-block-bg-color); } diff --git a/landing/views.py b/landing/views.py index 140c3db39..724d1bb9c 100644 --- a/landing/views.py +++ b/landing/views.py @@ -9,11 +9,15 @@ from authn.decorators.auth import require_auth from club.exceptions import AccessDenied +from invites.models import Invite from landing.forms import GodmodeNetworkSettingsEditForm, GodmodeDigestEditForm, GodmodeInviteForm from landing.models import GodSettings from notifications.email.invites import send_invited_email, send_account_renewed_email from notifications.telegram.common import send_telegram_message, ADMIN_CHAT +from payments.models import Payment +from payments.products import PRODUCTS from users.models.user import User +from utils.strings import random_string EXISTING_DOCS = [ os.path.splitext(f)[0] # get only filenames @@ -147,3 +151,24 @@ def godmode_invite(request): form = GodmodeInviteForm() return render(request, "admin/simple_form.html", {"form": form}) + + +@require_auth +def godmode_generate_invite_code(request): + if request.method != "POST": + raise Http404() + + if not request.me.is_god: + raise AccessDenied() + + Invite.objects.create( + user=request.me, + payment=Payment.create( + reference="god-" + random_string(length=16), + user=request.me, + product=PRODUCTS["club1_invite"], + status=Payment.STATUS_SUCCESS, + ) + ) + + return redirect("invites")