From e92df933436287ae218e5dd2de4060a1aee1c594 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 13 Dec 2021 20:51:06 +0000 Subject: [PATCH] . --- atlas/decorators.py | 64 +++++++++++++++++++++++++++++-------- atlas/filters.py | 6 ++-- atlas/views.py | 34 ++++++++++---------- templates/cid_selector.html | 2 +- 4 files changed, 71 insertions(+), 35 deletions(-) diff --git a/atlas/decorators.py b/atlas/decorators.py index 58c154f7..ce6c9555 100755 --- a/atlas/decorators.py +++ b/atlas/decorators.py @@ -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 \ No newline at end of file + return wrap diff --git a/atlas/filters.py b/atlas/filters.py index af59f075..92f0ca87 100755 --- a/atlas/filters.py +++ b/atlas/filters.py @@ -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__( diff --git a/atlas/views.py b/atlas/views.py index bb75af04..cf72024e 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -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) diff --git a/templates/cid_selector.html b/templates/cid_selector.html index b1949383..07fc8bfa 100644 --- a/templates/cid_selector.html +++ b/templates/cid_selector.html @@ -2,7 +2,7 @@ {% block content %}
-

Score / Results checker

+

Exam / Results checker

Please enter your CID and passcode

CID:

Passcode: