From c764bc16ebe8abd31709a51ce655a4168d853b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org> Date: Tue, 2 Nov 2021 12:09:31 +0100 Subject: [PATCH] Tweak permissions, offer menu of proposed new homepages --- .../commands/add_groups_and_permissions.py | 10 ++++++++++ .../scipost/{index_alt.html => index3.html} | 10 +++++++--- .../scipost/templates/scipost/navbar2.html | 20 +++++++++++++++++++ scipost_django/scipost/urls.py | 4 ++-- scipost_django/scipost/views.py | 10 +++++----- 5 files changed, 44 insertions(+), 10 deletions(-) rename scipost_django/scipost/templates/scipost/{index_alt.html => index3.html} (94%) diff --git a/scipost_django/scipost/management/commands/add_groups_and_permissions.py b/scipost_django/scipost/management/commands/add_groups_and_permissions.py index 4311644b5..5259a7690 100644 --- a/scipost_django/scipost/management/commands/add_groups_and_permissions.py +++ b/scipost_django/scipost/management/commands/add_groups_and_permissions.py @@ -26,6 +26,7 @@ class Command(BaseCommand): name='Registered Contributors') Developers, created = Group.objects.get_or_create(name='Developers') Testers, created = Group.objects.get_or_create(name='Testers') + Previewers, created = Group.objects.get_or_create(name='Previewers') NewsAdmin, created = Group.objects.get_or_create(name='News Administrators') Ambassadors, created = Group.objects.get_or_create(name='Ambassadors') JuniorAmbassadors, created = Group.objects.get_or_create(name='Junior Ambassadors') @@ -311,6 +312,11 @@ class Command(BaseCommand): name='Can manage ontology', content_type=content_type) + # Previewing new features + can_preview_new_features, created = Permission.objects.get_or_create( + codename='can_preview_new_features', + name='Can preview new features', + content_type=content_type) # Assign permissions to groups SciPostAdmin.permissions.set([ @@ -428,6 +434,10 @@ class Command(BaseCommand): can_view_docs_scipost, ]) + Previewers.permissions.set([ + can_preview_new_features, + ]) + Ambassadors.permissions.set([ can_create_registration_invitations, can_manage_registration_invitations, diff --git a/scipost_django/scipost/templates/scipost/index_alt.html b/scipost_django/scipost/templates/scipost/index3.html similarity index 94% rename from scipost_django/scipost/templates/scipost/index_alt.html rename to scipost_django/scipost/templates/scipost/index3.html index 2ccc70bf0..8a2120a20 100644 --- a/scipost_django/scipost/templates/scipost/index_alt.html +++ b/scipost_django/scipost/templates/scipost/index3.html @@ -1,9 +1,9 @@ {% extends 'scipost/base.html' %} {% block headsup %} -<link rel="preconnect" href="https://fonts.googleapis.com"> -<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> -<link href="https://fonts.googleapis.com/css2?family=Merriweather+Sans:wght@300;400;500;600&display=swap" rel="stylesheet"> + <link rel="preconnect" href="https://fonts.googleapis.com"> + <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> + <link href="https://fonts.googleapis.com/css2?family=Merriweather+Sans:wght@300;400;500;600&display=swap" rel="stylesheet"> {% endblock headsup %} {% load render_bundle from webpack_loader %} @@ -14,6 +14,10 @@ {% block meta_description %}{{ block.super }} homepage{% endblock meta_description %} {% block pagetitle %}Homepage{% endblock pagetitle %} +{% block navbar %} + {% include 'scipost/navbar2.html' %} +{% endblock %} + {% block content %} <div class="row"> <div class="col-12"> diff --git a/scipost_django/scipost/templates/scipost/navbar2.html b/scipost_django/scipost/templates/scipost/navbar2.html index 924d734d8..1e5bbbd07 100644 --- a/scipost_django/scipost/templates/scipost/navbar2.html +++ b/scipost_django/scipost/templates/scipost/navbar2.html @@ -17,6 +17,26 @@ <div class="collapse navbar-collapse mt-lg-0 mt-3" id="main-navbar"> <ul class="navbar-nav me-auto"> + {% if perms.scipost.can_preview_new_features %} + <li class="nav-item dropdown border border-warning"> + <a class="nav-link dropdown-toggle" href="#" id="HomepagesDropdown" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-trigger="hover"> + <span class="d-none d-lg-inline-block text-warning" aria-hidden="true" style="min-width: 16px;">{% include 'bi/house-fill.html' %}</span> + <span class="d-lg-none d-inline-block text-warning">Homepages</span> + </a> + <div class="dropdown-menu" aria-labelledby="HomepagesDropdown"> + <div class="dropdown-item"> + <a href="{% url 'scipost:index' %}">Current homepage</a> + </div> + <div class="dropdown-item"> + <a href="{% url 'scipost:index2' %}">2: home + portal</a> + </div> + <div class="dropdown-item"> + <a href="{% url 'scipost:index3' %}">3: homepage, restyled</a> + </div> + </div> + </li> + {% endif %} + <li class="nav-item{% if request.path == '/home2' %} active{% endif %}"> <a href="{% url 'scipost:index2' %}" class="nav-link" aria-label="SciPost Home"> <span class="d-none d-lg-inline-block" aria-hidden="true" style="min-width: 16px;">{% include 'bi/house-fill.html' %}</span> diff --git a/scipost_django/scipost/urls.py b/scipost_django/scipost/urls.py index e8765a3ec..6f1ad700b 100644 --- a/scipost_django/scipost/urls.py +++ b/scipost_django/scipost/urls.py @@ -80,8 +80,8 @@ urlpatterns = [ name='index2' ), path( - 'home_alt', - views.index_alt, name='index-alt' + 'home3', + views.index3, name='index3' ), # Portal diff --git a/scipost_django/scipost/views.py b/scipost_django/scipost/views.py index 15878d774..8778397a7 100644 --- a/scipost_django/scipost/views.py +++ b/scipost_django/scipost/views.py @@ -177,7 +177,7 @@ def index(request): return render(request, 'scipost/index.html', context) -@login_required +@permission_required('scipost.can_preview_new_features', return_403=True) def index2(request): """Homepage view of SciPost.""" if NewsItem.objects.homepage().exists(): @@ -190,7 +190,7 @@ def index2(request): return render(request, 'scipost/index2.html', context) -@login_required +@permission_required('scipost.can_preview_new_features', return_403=True) def portal(request): """ Academic portal entryway. @@ -377,8 +377,8 @@ def _hx_sponsors(request): return render(request, 'scipost/_hx_sponsors.html', context) -@login_required -def index_alt(request): +@permission_required('scipost.can_preview_new_features', return_403=True) +def index3(request): """Homepage view of SciPost.""" context = { 'news_items': NewsItem.objects.homepage().order_by('-date')[:4], @@ -386,7 +386,7 @@ def index_alt(request): '-paper_nr')[:10], 'current_sponsors': Organization.objects.current_sponsors().order_by('?')[:2] } - return render(request, 'scipost/index_alt.html', context) + return render(request, 'scipost/index3.html', context) def protected_serve(request, path, show_indexes=False): -- GitLab