.
This commit is contained in:
+50
-14
@@ -1,66 +1,102 @@
|
|||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from .models import Case, Series
|
from .models import Case, Series
|
||||||
|
|
||||||
|
|
||||||
def user_is_author_or_atlas_series_checker_or_atlas_marker(function):
|
def user_is_author_or_atlas_series_checker_or_atlas_marker(function):
|
||||||
def wrap(request, *args, **kwargs):
|
def wrap(request, *args, **kwargs):
|
||||||
series = Series.objects.get(pk=kwargs['pk'])
|
series = Series.objects.get(pk=kwargs["pk"])
|
||||||
if request.user in series.get_author_objects() or request.user.groups.filter(name='atlas_checker').exists() or request.user.groups.filter(name='atlas_marker').exists() or request.user.is_superuser:
|
if (
|
||||||
|
request.user in series.get_author_objects()
|
||||||
|
or request.user.groups.filter(name="atlas_editor").exists()
|
||||||
|
or request.user.groups.filter(name="atlas_marker").exists()
|
||||||
|
or request.user.is_superuser
|
||||||
|
):
|
||||||
return function(request, *args, **kwargs)
|
return function(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
wrap.__doc__ = function.__doc__
|
wrap.__doc__ = function.__doc__
|
||||||
wrap.__name__ = function.__name__
|
wrap.__name__ = function.__name__
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
|
|
||||||
def user_is_author_or_atlas_series_checker(function):
|
def user_is_author_or_atlas_series_checker(function):
|
||||||
def wrap(request, *args, **kwargs):
|
def wrap(request, *args, **kwargs):
|
||||||
series = Series.objects.get(pk=kwargs['pk'])
|
series = Series.objects.get(pk=kwargs["pk"])
|
||||||
if request.user in series.get_author_objects() or request.user.groups.filter(name='atlas_checker').exists() or request.user.is_superuser:
|
if (
|
||||||
|
request.user in series.get_author_objects()
|
||||||
|
or request.user.groups.filter(name="atlas_editor").exists()
|
||||||
|
or request.user.is_superuser
|
||||||
|
):
|
||||||
return function(request, *args, **kwargs)
|
return function(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
wrap.__doc__ = function.__doc__
|
wrap.__doc__ = function.__doc__
|
||||||
wrap.__name__ = function.__name__
|
wrap.__name__ = function.__name__
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
def user_is_author_or_atlas_checker_or_atlas_marker(function):
|
|
||||||
|
def user_is_author_or_atlas_editor_or_atlas_marker(function):
|
||||||
def wrap(request, *args, **kwargs):
|
def wrap(request, *args, **kwargs):
|
||||||
atlas = Case.objects.get(pk=kwargs['pk'])
|
atlas = Case.objects.get(pk=kwargs["pk"])
|
||||||
if request.user in atlas.author.all() or request.user.groups.filter(name='atlas_checker').exists() or request.user.groups.filter(name='atlas_marker').exists() or request.user.is_superuser:
|
if (
|
||||||
|
request.user in atlas.author.all()
|
||||||
|
or request.user.groups.filter(name="atlas_editor").exists()
|
||||||
|
or request.user.groups.filter(name="atlas_marker").exists()
|
||||||
|
or request.user.is_superuser
|
||||||
|
):
|
||||||
return function(request, *args, **kwargs)
|
return function(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
wrap.__doc__ = function.__doc__
|
wrap.__doc__ = function.__doc__
|
||||||
wrap.__name__ = function.__name__
|
wrap.__name__ = function.__name__
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
def user_is_author_or_atlas_checker(function):
|
|
||||||
|
def user_is_author_or_atlas_editor(function):
|
||||||
def wrap(request, *args, **kwargs):
|
def wrap(request, *args, **kwargs):
|
||||||
atlas = Case.objects.get(pk=kwargs['pk'])
|
atlas = Case.objects.get(pk=kwargs["pk"])
|
||||||
if request.user in atlas.author.all() or request.user.groups.filter(name='atlas_checker').exists() or request.user.is_superuser:
|
if (
|
||||||
|
request.user in atlas.author.all()
|
||||||
|
or request.user.groups.filter(name="atlas_editor").exists()
|
||||||
|
or request.user.is_superuser
|
||||||
|
):
|
||||||
return function(request, *args, **kwargs)
|
return function(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
wrap.__doc__ = function.__doc__
|
wrap.__doc__ = function.__doc__
|
||||||
wrap.__name__ = function.__name__
|
wrap.__name__ = function.__name__
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
def user_is_atlas_checker(function):
|
|
||||||
|
def user_is_atlas_editor(function):
|
||||||
def wrap(request, *args, **kwargs):
|
def wrap(request, *args, **kwargs):
|
||||||
if request.user.groups.filter(name='atlas_checker').exists() or request.user.is_superuser:
|
if (
|
||||||
|
request.user.groups.filter(name="atlas_editor").exists()
|
||||||
|
or request.user.is_superuser
|
||||||
|
):
|
||||||
return function(request, *args, **kwargs)
|
return function(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
wrap.__doc__ = function.__doc__
|
wrap.__doc__ = function.__doc__
|
||||||
wrap.__name__ = function.__name__
|
wrap.__name__ = function.__name__
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
|
|
||||||
def user_is_atlas_marker(function):
|
def user_is_atlas_marker(function):
|
||||||
def wrap(request, *args, **kwargs):
|
def wrap(request, *args, **kwargs):
|
||||||
if request.user.groups.filter(name='atlas_marker').exists() or request.user.is_superuser:
|
if (
|
||||||
|
request.user.groups.filter(name="atlas_marker").exists()
|
||||||
|
or request.user.is_superuser
|
||||||
|
):
|
||||||
return function(request, *args, **kwargs)
|
return function(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
wrap.__doc__ = function.__doc__
|
wrap.__doc__ = function.__doc__
|
||||||
wrap.__name__ = function.__name__
|
wrap.__name__ = function.__name__
|
||||||
return wrap
|
return wrap
|
||||||
|
|||||||
+3
-3
@@ -17,7 +17,7 @@ def get_authors(request):
|
|||||||
if request is None:
|
if request is None:
|
||||||
return User.objects.none()
|
return User.objects.none()
|
||||||
|
|
||||||
if not request.user.groups.filter(name="atlas_checker").exists():
|
if not request.user.groups.filter(name="atlas_editor").exists():
|
||||||
queryset = User.objects.filter(id=request.user.id)
|
queryset = User.objects.filter(id=request.user.id)
|
||||||
else:
|
else:
|
||||||
queryset = User.objects.all()
|
queryset = User.objects.all()
|
||||||
@@ -54,7 +54,7 @@ class CaseFilter(django_filters.FilterSet):
|
|||||||
user=None,
|
user=None,
|
||||||
request=None,
|
request=None,
|
||||||
):
|
):
|
||||||
if not request.user.groups.filter(name="atlas_checker").exists():
|
if not request.user.groups.filter(name="atlas_editor").exists():
|
||||||
# queryset = queryset.filter(open_access=True) | queryset.filter(author__id=request.user.id)
|
# queryset = queryset.filter(open_access=True) | queryset.filter(author__id=request.user.id)
|
||||||
queryset = queryset.filter(author__id=request.user.id)
|
queryset = queryset.filter(author__id=request.user.id)
|
||||||
super(CaseFilter, self).__init__(
|
super(CaseFilter, self).__init__(
|
||||||
@@ -81,7 +81,7 @@ class SeriesFilter(django_filters.FilterSet):
|
|||||||
user=None,
|
user=None,
|
||||||
request=None,
|
request=None,
|
||||||
):
|
):
|
||||||
if not request.user.groups.filter(name="atlas_checker").exists():
|
if not request.user.groups.filter(name="atlas_editor").exists():
|
||||||
# queryset = queryset.filter(open_access=True) | queryset.filter(author__id=request.user.id)
|
# queryset = queryset.filter(open_access=True) | queryset.filter(author__id=request.user.id)
|
||||||
queryset = queryset.filter(author__id=request.user.id)
|
queryset = queryset.filter(author__id=request.user.id)
|
||||||
super(SeriesFilter, self).__init__(
|
super(SeriesFilter, self).__init__(
|
||||||
|
|||||||
+17
-17
@@ -75,13 +75,13 @@ from django_tables2 import SingleTableView, SingleTableMixin
|
|||||||
from django_filters.views import FilterView
|
from django_filters.views import FilterView
|
||||||
|
|
||||||
from .decorators import (
|
from .decorators import (
|
||||||
user_is_author_or_atlas_checker,
|
user_is_author_or_atlas_editor,
|
||||||
user_is_author_or_atlas_checker_or_atlas_marker,
|
user_is_author_or_atlas_editor_or_atlas_marker,
|
||||||
user_is_author_or_atlas_series_checker_or_atlas_marker,
|
user_is_author_or_atlas_series_checker_or_atlas_marker,
|
||||||
user_is_atlas_checker,
|
user_is_atlas_editor,
|
||||||
user_is_author_or_atlas_series_checker,
|
user_is_author_or_atlas_series_checker,
|
||||||
user_is_atlas_marker,
|
user_is_atlas_marker,
|
||||||
user_is_author_or_atlas_checker_or_atlas_marker,
|
user_is_author_or_atlas_editor_or_atlas_marker,
|
||||||
)
|
)
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
@@ -116,7 +116,7 @@ class AuthorOrCheckerRequiredMixin(object):
|
|||||||
def get_object(self, *args, **kwargs):
|
def get_object(self, *args, **kwargs):
|
||||||
obj = super().get_object(*args, **kwargs)
|
obj = super().get_object(*args, **kwargs)
|
||||||
if (
|
if (
|
||||||
self.request.user.groups.filter(name="atlas_checker").exists()
|
self.request.user.groups.filter(name="atlas_editor").exists()
|
||||||
or self.request.user.is_superuser
|
or self.request.user.is_superuser
|
||||||
):
|
):
|
||||||
return obj
|
return obj
|
||||||
@@ -126,7 +126,7 @@ class AuthorOrCheckerRequiredMixin(object):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_author_or_atlas_checker_or_atlas_marker
|
@user_is_author_or_atlas_editor_or_atlas_marker
|
||||||
def case_detail(request, pk):
|
def case_detail(request, pk):
|
||||||
case = get_object_or_404(Case, pk=pk)
|
case = get_object_or_404(Case, pk=pk)
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ def series_detail(request, pk, finding_pk=None):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_atlas_checker
|
@user_is_atlas_editor
|
||||||
def condition_detail(request, pk):
|
def condition_detail(request, pk):
|
||||||
condition = get_object_or_404(Condition, pk=pk)
|
condition = get_object_or_404(Condition, pk=pk)
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ def condition_detail(request, pk):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_atlas_checker
|
@user_is_atlas_editor
|
||||||
def subspecialty_detail(request, pk):
|
def subspecialty_detail(request, pk):
|
||||||
subspecialty = get_object_or_404(Subspecialty, pk=pk)
|
subspecialty = get_object_or_404(Subspecialty, pk=pk)
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ def subspecialty_detail(request, pk):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_atlas_checker
|
@user_is_atlas_editor
|
||||||
def presentation_detail(request, pk):
|
def presentation_detail(request, pk):
|
||||||
presentation = get_object_or_404(Presentation, pk=pk)
|
presentation = get_object_or_404(Presentation, pk=pk)
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ def presentation_detail(request, pk):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_atlas_checker
|
@user_is_atlas_editor
|
||||||
def pathological_process_detail(request, pk):
|
def pathological_process_detail(request, pk):
|
||||||
pathological_process = get_object_or_404(PathologicalProcess, pk=pk)
|
pathological_process = get_object_or_404(PathologicalProcess, pk=pk)
|
||||||
|
|
||||||
@@ -223,7 +223,7 @@ def pathological_process_detail(request, pk):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_atlas_checker
|
@user_is_atlas_editor
|
||||||
def structure_detail(request, pk):
|
def structure_detail(request, pk):
|
||||||
structure = get_object_or_404(Structure, pk=pk)
|
structure = get_object_or_404(Structure, pk=pk)
|
||||||
|
|
||||||
@@ -238,7 +238,7 @@ def structure_detail(request, pk):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_atlas_checker
|
@user_is_atlas_editor
|
||||||
def finding_detail(request, pk):
|
def finding_detail(request, pk):
|
||||||
finding = get_object_or_404(Finding, pk=pk)
|
finding = get_object_or_404(Finding, pk=pk)
|
||||||
|
|
||||||
@@ -253,7 +253,7 @@ def finding_detail(request, pk):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_author_or_atlas_checker
|
@user_is_author_or_atlas_editor
|
||||||
def author_detail(request, pk):
|
def author_detail(request, pk):
|
||||||
# logging.debug(Author.objects.all())
|
# logging.debug(Author.objects.all())
|
||||||
# author = get_object_or_404(Author, pk=pk)
|
# author = get_object_or_404(Author, pk=pk)
|
||||||
@@ -266,7 +266,7 @@ def author_detail(request, pk):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@user_is_author_or_atlas_checker
|
@user_is_author_or_atlas_editor
|
||||||
def author_list(request):
|
def author_list(request):
|
||||||
authors = User.objects.all()
|
authors = User.objects.all()
|
||||||
|
|
||||||
@@ -316,7 +316,7 @@ class StructureDelete(RevisionMixin, AuthorOrCheckerRequiredMixin, DeleteView):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_author_or_atlas_checker
|
@user_is_author_or_atlas_editor
|
||||||
def case_clone(request, pk):
|
def case_clone(request, pk):
|
||||||
new_item = get_object_or_404(Case, pk=pk)
|
new_item = get_object_or_404(Case, pk=pk)
|
||||||
new_item.pk = None # autogen a new pk (item_id)
|
new_item.pk = None # autogen a new pk (item_id)
|
||||||
@@ -610,7 +610,7 @@ class AtlasClone(AtlasCreateBase, CreateView):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_author_or_atlas_checker
|
@user_is_author_or_atlas_editor
|
||||||
def atlas_scrap(request, pk):
|
def atlas_scrap(request, pk):
|
||||||
try:
|
try:
|
||||||
atlas = Case.objects.get(pk=pk)
|
atlas = Case.objects.get(pk=pk)
|
||||||
@@ -879,7 +879,7 @@ class StructureAutocomplete(autocomplete.Select2QuerySetView):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_is_atlas_checker
|
@user_is_atlas_editor
|
||||||
def categories_list(request):
|
def categories_list(request):
|
||||||
# condition = get_object_or_404(Condition, pk=pk)
|
# condition = get_object_or_404(Condition, pk=pk)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="">
|
<div class="">
|
||||||
<h2>Score / Results checker</h2>
|
<h2>Exam / Results checker</h2>
|
||||||
<p>Please enter your CID and passcode</p>
|
<p>Please enter your CID and passcode</p>
|
||||||
<p>CID: <input type="text" name="cid" id="cid-input"></p>
|
<p>CID: <input type="text" name="cid" id="cid-input"></p>
|
||||||
<p>Passcode: <input id="passcode-box" type="text" value="Passcode"></p>
|
<p>Passcode: <input id="passcode-box" type="text" value="Passcode"></p>
|
||||||
|
|||||||
Reference in New Issue
Block a user