This commit is contained in:
Ross
2021-12-13 20:51:06 +00:00
parent e8e6f5d9ac
commit e92df93343
4 changed files with 71 additions and 35 deletions
+50 -14
View File
@@ -1,66 +1,102 @@
from django.core.exceptions import PermissionDenied
from .models import Case, Series
def user_is_author_or_atlas_series_checker_or_atlas_marker(function):
def wrap(request, *args, **kwargs):
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:
series = Series.objects.get(pk=kwargs["pk"])
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)
else:
raise PermissionDenied
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap
def user_is_author_or_atlas_series_checker(function):
def wrap(request, *args, **kwargs):
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:
series = Series.objects.get(pk=kwargs["pk"])
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)
else:
raise PermissionDenied
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
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):
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:
atlas = Case.objects.get(pk=kwargs["pk"])
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)
else:
raise PermissionDenied
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap
def user_is_author_or_atlas_checker(function):
def user_is_author_or_atlas_editor(function):
def wrap(request, *args, **kwargs):
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:
atlas = Case.objects.get(pk=kwargs["pk"])
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)
else:
raise PermissionDenied
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap
def user_is_atlas_checker(function):
def user_is_atlas_editor(function):
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)
else:
raise PermissionDenied
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap
def user_is_atlas_marker(function):
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)
else:
raise PermissionDenied
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap
return wrap
+3 -3
View File
@@ -17,7 +17,7 @@ def get_authors(request):
if request is 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)
else:
queryset = User.objects.all()
@@ -54,7 +54,7 @@ class CaseFilter(django_filters.FilterSet):
user=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(author__id=request.user.id)
super(CaseFilter, self).__init__(
@@ -81,7 +81,7 @@ class SeriesFilter(django_filters.FilterSet):
user=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(author__id=request.user.id)
super(SeriesFilter, self).__init__(
+17 -17
View File
@@ -75,13 +75,13 @@ from django_tables2 import SingleTableView, SingleTableMixin
from django_filters.views import FilterView
from .decorators import (
user_is_author_or_atlas_checker,
user_is_author_or_atlas_checker_or_atlas_marker,
user_is_author_or_atlas_editor,
user_is_author_or_atlas_editor_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_atlas_marker,
user_is_author_or_atlas_checker_or_atlas_marker,
user_is_author_or_atlas_editor_or_atlas_marker,
)
from collections import defaultdict
@@ -116,7 +116,7 @@ class AuthorOrCheckerRequiredMixin(object):
def get_object(self, *args, **kwargs):
obj = super().get_object(*args, **kwargs)
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
):
return obj
@@ -126,7 +126,7 @@ class AuthorOrCheckerRequiredMixin(object):
@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):
case = get_object_or_404(Case, pk=pk)
@@ -163,7 +163,7 @@ def series_detail(request, pk, finding_pk=None):
@login_required
@user_is_atlas_checker
@user_is_atlas_editor
def condition_detail(request, pk):
condition = get_object_or_404(Condition, pk=pk)
@@ -178,7 +178,7 @@ def condition_detail(request, pk):
@login_required
@user_is_atlas_checker
@user_is_atlas_editor
def subspecialty_detail(request, pk):
subspecialty = get_object_or_404(Subspecialty, pk=pk)
@@ -193,7 +193,7 @@ def subspecialty_detail(request, pk):
@login_required
@user_is_atlas_checker
@user_is_atlas_editor
def presentation_detail(request, pk):
presentation = get_object_or_404(Presentation, pk=pk)
@@ -208,7 +208,7 @@ def presentation_detail(request, pk):
@login_required
@user_is_atlas_checker
@user_is_atlas_editor
def pathological_process_detail(request, pk):
pathological_process = get_object_or_404(PathologicalProcess, pk=pk)
@@ -223,7 +223,7 @@ def pathological_process_detail(request, pk):
@login_required
@user_is_atlas_checker
@user_is_atlas_editor
def structure_detail(request, pk):
structure = get_object_or_404(Structure, pk=pk)
@@ -238,7 +238,7 @@ def structure_detail(request, pk):
@login_required
@user_is_atlas_checker
@user_is_atlas_editor
def finding_detail(request, pk):
finding = get_object_or_404(Finding, pk=pk)
@@ -253,7 +253,7 @@ def finding_detail(request, pk):
@login_required
@user_is_author_or_atlas_checker
@user_is_author_or_atlas_editor
def author_detail(request, pk):
# logging.debug(Author.objects.all())
# 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):
authors = User.objects.all()
@@ -316,7 +316,7 @@ class StructureDelete(RevisionMixin, AuthorOrCheckerRequiredMixin, DeleteView):
@login_required
@user_is_author_or_atlas_checker
@user_is_author_or_atlas_editor
def case_clone(request, pk):
new_item = get_object_or_404(Case, pk=pk)
new_item.pk = None # autogen a new pk (item_id)
@@ -610,7 +610,7 @@ class AtlasClone(AtlasCreateBase, CreateView):
@login_required
@user_is_author_or_atlas_checker
@user_is_author_or_atlas_editor
def atlas_scrap(request, pk):
try:
atlas = Case.objects.get(pk=pk)
@@ -879,7 +879,7 @@ class StructureAutocomplete(autocomplete.Select2QuerySetView):
@login_required
@user_is_atlas_checker
@user_is_atlas_editor
def categories_list(request):
# condition = get_object_or_404(Condition, pk=pk)
+1 -1
View File
@@ -2,7 +2,7 @@
{% block content %}
<div class="">
<h2>Score / Results checker</h2>
<h2>Exam / Results checker</h2>
<p>Please enter your CID and passcode</p>
<p>CID: <input type="text" name="cid" id="cid-input"></p>
<p>Passcode: <input id="passcode-box" type="text" value="Passcode"></p>