Autorizace v1 (nechápu, proč to funguje (= neháže chyby), ale funguje)
This commit is contained in:
parent
0f7e6e0d6b
commit
f047328758
4 changed files with 21 additions and 13 deletions
|
@ -14,7 +14,7 @@ from galerie.forms import KomentarForm, NewGalerieForm
|
|||
def zobrazit(galerie, request):
|
||||
preview = False
|
||||
if galerie.zobrazit >= 1:
|
||||
if request.user.is_staff:
|
||||
if request.user.je_org:
|
||||
preview = True;
|
||||
else:
|
||||
raise Http404
|
||||
|
@ -35,7 +35,7 @@ def nahled(request, pk, soustredeni):
|
|||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
|
||||
podgalerie = Galerie.objects.filter(galerie_up = galerie).order_by('poradi')
|
||||
if not request.user.is_staff:
|
||||
if not request.user.je_org:
|
||||
podgalerie = podgalerie.filter(zobrazit__lt=1)
|
||||
|
||||
obrazky = Obrazek.objects.filter(galerie = galerie).order_by('poradi', 'nazev')
|
||||
|
@ -44,7 +44,7 @@ def nahled(request, pk, soustredeni):
|
|||
sourozenci = []
|
||||
if galerie.galerie_up:
|
||||
sourozenci = galerie.galerie_up.galerie_set.all().order_by('poradi')
|
||||
if not request.user.is_staff:
|
||||
if not request.user.je_org:
|
||||
sourozenci = sourozenci.filter(zobrazit__lt=1)
|
||||
|
||||
predchozi = None
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
{# Projdi vsechna soustredeni #}
|
||||
{% for soustredeni in object_list %}
|
||||
{# Kdyz je verejne -> zobraz #}
|
||||
{% if soustredeni.verejne_db or user.is_staff %}
|
||||
{% if not soustredeni.verejne_db and user.is_staff %}
|
||||
{% if soustredeni.verejne_db or user.je_org %}
|
||||
{% if not soustredeni.verejne_db and user.je_org %}
|
||||
<div class="mam-org-only">
|
||||
<!--Groups of user: {{user.groups.all}} <br>-->
|
||||
{% endif %}
|
||||
|
@ -34,8 +34,8 @@
|
|||
{# Zobrazeni odkazu na galerie #}
|
||||
{% if soustredeni.galerie_set.all %}
|
||||
{% for galerie in soustredeni.galerie_set.all %}
|
||||
{% if galerie.zobrazit == 0 or user.is_staff %}
|
||||
<li {% if galerie.zobrazit > 0 and user.is_staff %}class="mam-org-only"{% endif %}>
|
||||
{% if galerie.zobrazit == 0 or user.je_org %}
|
||||
<li {% if galerie.zobrazit > 0 and user.je_org %}class="mam-org-only"{% endif %}>
|
||||
<a href="../{{soustredeni.pk}}/fotogalerie/{{galerie.pk}}">Fotogalerie</a>
|
||||
{# TODO kdyz je titulni obrazek, tak asi i titulni obrazek #}
|
||||
</li>
|
||||
|
@ -43,7 +43,7 @@
|
|||
{% endfor %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% if user.is_staff %}
|
||||
{% if user.je_org %}
|
||||
<div class="mam-org-only">
|
||||
<a href="../{{soustredeni.pk}}/fotogalerie/0/new/">Vytvořit novou fotogalerii</a><br>
|
||||
<a href="../{{soustredeni.pk}}/obalky.pdf">Vygenerovat obálky pro účastníky</a><br>
|
||||
|
@ -60,7 +60,7 @@
|
|||
{% if soustredeni.text %}
|
||||
{% autoescape off %}{{soustredeni.text}}{% endautoescape %}
|
||||
{% endif %}
|
||||
{% if user.is_staff %}
|
||||
{% if user.je_org %}
|
||||
<div class="mam-org-only">
|
||||
{# Účastníci #}
|
||||
<h2>Soustředění se zúčastnili tito účastníci:</h2>
|
||||
|
@ -82,7 +82,7 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if not soustredeni.verejne_db and user.is_staff %}
|
||||
{% if not soustredeni.verejne_db and user.je_org %}
|
||||
</div> {# class="mam-org-only" #}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
from html.parser import HTMLParser
|
||||
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
|
@ -11,6 +15,11 @@ import seminar.treelib as t
|
|||
|
||||
org_required = permission_required('auth.org', raise_exception=True)
|
||||
resitel_required = permission_required('auth.resitel', raise_exception=True)
|
||||
User = get_user_model()
|
||||
User.je_org = lambda self: self.has_perm('auth.org')
|
||||
User.je_resitel = lambda self: self.has_perm('auth.resitel')
|
||||
AnonymousUser.je_org = lambda self: False
|
||||
AnonymousUser.je_resitel = lambda self: False
|
||||
|
||||
|
||||
class FirstTagParser(HTMLParser):
|
||||
|
|
|
@ -238,8 +238,7 @@ def spravne_novinky(request):
|
|||
user = request.user
|
||||
# Využíváme líné vyhodnocování QuerySetů
|
||||
qs = Novinky.objects.all()
|
||||
# TODO: Tohle by mělo spíš kontrolovat, že je/není někdo org, než že může do Adminu.
|
||||
if not user.is_staff:
|
||||
if not user.je_org:
|
||||
qs = qs.filter(zverejneno=True)
|
||||
return qs.order_by('-datum')
|
||||
|
||||
|
@ -623,7 +622,7 @@ class ProblemView(generic.DetailView):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
# Musí se používat context['object'], protože nevíme, jestli dostaneme úložku, téma, článek, .... a tyhle věci vyrábějí různé klíče.
|
||||
if not context['object'].verejne() and not self.request.user.is_staff:
|
||||
if not context['object'].verejne() and not self.request.user.je_org:
|
||||
raise PermissionDenied()
|
||||
if isinstance(context['object'], Clanek):
|
||||
context['reseni'] = Reseni.objects.filter(problem=context['object']).select_related('resitel').order_by('resitel__prijmeni')
|
||||
|
|
Loading…
Reference in a new issue