From 79c726a0fb14123848a084502e9b25cae3e3d58e Mon Sep 17 00:00:00 2001 From: dcz2 <dcz@ipipan.waw.pl> Date: Mon, 11 Jul 2022 22:33:19 +0200 Subject: [PATCH] Restrict all views from the menu to authenticated users --- common/templates/base.html | 2 ++ dictionary_statistics/views.py | 2 ++ entries/views.py | 2 ++ phrase_expansions/views.py | 5 +++-- unifier/views.py | 2 ++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/templates/base.html b/common/templates/base.html index 770ca00..f39de09 100644 --- a/common/templates/base.html +++ b/common/templates/base.html @@ -49,6 +49,7 @@ <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> + {% if request.user.is_authenticated %} <ul class="navbar-nav mr-auto"> <li class="nav-item" id="nav-entries"> <a class="nav-link text-light" href="{% url 'entries:entries' %}"> @@ -74,6 +75,7 @@ </li> {% endif %} </ul> + {% endif %} </div> <span id="import-status" class="navbar-text text-warning mr-3"></span> {% if request.user.is_authenticated %} diff --git a/dictionary_statistics/views.py b/dictionary_statistics/views.py index e91161a..c681d40 100644 --- a/dictionary_statistics/views.py +++ b/dictionary_statistics/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth.decorators import login_required from django.shortcuts import render from django.utils.translation import gettext as _ @@ -7,6 +8,7 @@ from semantics.models import Frame, FrameOpinion from entries.polish_strings import POS as POS_names, STATUS, SCHEMA_OPINION, FRAME_OPINION +@login_required def dictionary_statistics(request): ALL = _('wszystkie') diff --git a/entries/views.py b/entries/views.py index 8eb87d9..2a2d2f5 100644 --- a/entries/views.py +++ b/entries/views.py @@ -51,6 +51,7 @@ MAX_LAST_VISITED = 10 #def test(request): # return render(request, 'test.html', {}) +@login_required def entries(request): # TODO make this automatic by subclassing/configuring session object if 'last_visited' not in request.session: @@ -349,6 +350,7 @@ def get_scroller_params(POST_data): #from django.db.models import Count @ajax_required +@login_required def get_entries(request): if request.method == 'POST': errors_dict = dict() diff --git a/phrase_expansions/views.py b/phrase_expansions/views.py index 58162d3..4821f64 100644 --- a/phrase_expansions/views.py +++ b/phrase_expansions/views.py @@ -1,7 +1,7 @@ from collections import defaultdict +from django.contrib.auth.decorators import login_required from django.shortcuts import render - from django.utils.translation import gettext as _ from phrase_expansions.models import PhraseExpansionType, PhraseExpansion @@ -13,7 +13,8 @@ def EXPANSION_OPINION(): 'unc' : _('wÄ…tpliwe'), 'cer' : _('pewne'), } - + +@login_required def phrase_expansions(request): expansions = defaultdict(list) expansions = [ diff --git a/unifier/views.py b/unifier/views.py index beb6b49..119cac2 100644 --- a/unifier/views.py +++ b/unifier/views.py @@ -1,5 +1,6 @@ import json import requests +from django.contrib.auth.decorators import login_required from django.db import transaction from django.http import JsonResponse, HttpResponse from django.shortcuts import get_object_or_404 @@ -206,6 +207,7 @@ def get_unified_frame_json(unifiedFrame, request): return { 'unified_frame_id': unifiedFrame.id, 'unified_frame': unifiedFrame_dict, 'subentries': subentries, 'frames' : slowal_frames_dict, 'alternations' : alternations, 'realisation_phrases' : realisation_phrases, 'realisation_descriptions' : realisation_descriptions, 'examples' : examples, 'last_visited' : request.session['last_visited'] } @ajax_required +@login_required def get_unified_frame(request): if request.method == 'POST': #TODO (*) -- GitLab