diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-10-16 17:57:13 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-02-19 14:43:48 +0100 | 
| commit | c93dd3812c53d21ab8517dc7af72e1d4b70a1b04 (patch) | |
| tree | 2153d8fd121f7ecd08a31e4867d58a2eb3c9aab7 /archaeological_operations/views.py | |
| parent | b8eef9b6aaed7ee097f8ea86174067f9ca42abd8 (diff) | |
| download | Ishtar-c93dd3812c53d21ab8517dc7af72e1d4b70a1b04.tar.bz2 Ishtar-c93dd3812c53d21ab8517dc7af72e1d4b70a1b04.zip  | |
♻ permissions refactoring: refactor has_permission methods
Diffstat (limited to 'archaeological_operations/views.py')
| -rw-r--r-- | archaeological_operations/views.py | 72 | 
1 files changed, 40 insertions, 32 deletions
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index 20193e197..7b6a56597 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -23,14 +23,14 @@ from jinja2 import TemplateSyntaxError  from django.conf import settings  from django.core.exceptions import PermissionDenied  from django.db.models import Q -from django.forms.utils import ErrorDict, ErrorList +from django.forms.utils import ErrorList  from django.http import HttpResponse, HttpResponseRedirect, Http404  from django.shortcuts import render, redirect  from django.urls import reverse  from django.views.generic import RedirectView  from ishtar_common.utils import ugettext_lazy as _, pgettext_lazy  from archaeological_operations.utils import parse_parcels -from django.forms import formset_factory, ValidationError +from django.forms import ValidationError  from archaeological_operations import models  from archaeological_operations import forms @@ -43,7 +43,7 @@ from ishtar_common.models import (      DocumentTemplate,  )  from archaeological_context_records.models import ContextRecord -from ishtar_common.utils import put_session_message, check_rights_condition +from ishtar_common.utils import check_permissions_condition  from ishtar_common.views import (      gen_generate_doc,      QAItemEditForm, @@ -58,14 +58,12 @@ from ishtar_common.wizards import SearchWizard  def autocomplete_patriarche(request): +    ishtaruser = getattr(request.user, "ishtaruser", None) +    if not ishtaruser: +        return HttpResponse(content_type="text/plain")      if ( -        not request.user.has_perm("ishtar_common.view_operation", models.Operation) -        and not request.user.has_perm( -            "ishtar_common.view_own_operation", models.Operation -        ) -        and not request.user.ishtaruser.has_right( -            "operation_search", session=request.session -        ) +        not ishtaruser.has_permission("archaeological_operations.view_operation") +        and not ishtaruser.has_permission("archaeological_operations.view_own_operation")      ):          return HttpResponse(content_type="text/plain")      if not request.GET.get("term"): @@ -88,11 +86,13 @@ def autocomplete_patriarche(request):  def autocomplete_archaeologicalsite(request): -    if not request.user.has_perm( -        "archaeological_operations.view_archaeologicalsite", models.ArchaeologicalSite -    ) and not request.user.has_perm( +    ishtaruser = getattr(request.user, "ishtaruser", None) +    if not ishtaruser: +        return HttpResponse(content_type="text/plain") +    if not ishtaruser.has_permission( +        "archaeological_operations.view_archaeologicalsite" +    ) and not ishtaruser.has_permission(          "archaeological_operations.view_own_archaeologicalsite", -        models.ArchaeologicalSite,      ):          return HttpResponse(content_type="text/plain")      if not request.GET.get("term"): @@ -121,14 +121,14 @@ new_archaeologicalsite = new_qa_item(  def autocomplete_operation(request): +    ishtaruser = getattr(request.user, "ishtaruser", None) +    if not ishtaruser: +        return HttpResponse(content_type="text/plain")      # person_types = request.user.ishtaruser.person.person_type      if ( -        not request.user.has_perm("ishtar_common.view_operation", models.Operation) -        and not request.user.has_perm( -            "ishtar_common.view_own_operation", models.Operation -        ) -        and not request.user.ishtaruser.has_right( -            "operation_search", session=request.session +        not ishtaruser.has_permission("archaeological_operations.view_operation") +        and not ishtaruser.has_permission( +            "archaeological_operations.view_own_operation"          )      ):          return HttpResponse(content_type="text/plain") @@ -161,10 +161,13 @@ def autocomplete_operation(request):  def get_available_operation_code(request, year=None): -    if not request.user.has_perm( -        "ishtar_common.view_operation", models.Operation -    ) and not request.user.has_perm( -        "ishtar_common.view_own_operation", models.Operation +    ishtaruser = getattr(request.user, "ishtaruser", None) +    if not ishtaruser: +        return HttpResponse(content_type="text/plain") +    if not ishtaruser.has_permission( +            "archaeological_operations.view_operation" +    ) and not ishtaruser.has_permission( +        "archaeological_operations.view_own_operation"      ):          return HttpResponse(content_type="text/plain")      data = json.dumps({"id": models.Operation.get_available_operation_code(year)}) @@ -211,9 +214,8 @@ wizard_steps = [  def get_check_files_for_operation(other_check=None):      def func(self): -        if not get_current_profile().files or not check_rights_condition(["view_file"])( -            self -        ): +        if not get_current_profile().files or \ +                not check_permissions_condition(["archaeological_files.view_file"])(self):              return False          if not other_check:              return True @@ -975,7 +977,10 @@ def administrativeactfile_document(          search_form = AdministrativeActTreatmentFileFormSelection          document_type = "TF" -    if not request.user.has_perm("view_administrativeact", models.AdministrativeAct): +    ishtaruser = getattr(request.user, "ishtaruser", None) +    if not ishtaruser: +        return HttpResponse(content_type="text/plain") +    if not ishtaruser.has_permission("archaeological_operations.view_administrativeact"):          return HttpResponse(content_type="text/plain")      dct = {}      DocumentGenerationAdminActForm = forms.DocumentGenerationAdminActForm @@ -1032,10 +1037,13 @@ def administrativeactfile_document(  def autocomplete_administrativeact(request): -    if not request.user.has_perm( -        "archaeological_operations.view_administrativeact", models.AdministrativeAct -    ) and not request.user.has_perm( -        "archaeological_operations.view_own_administrativeact", models.AdministrativeAct +    ishtaruser = getattr(request.user, "ishtaruser", None) +    if not ishtaruser: +        return HttpResponse(content_type="text/plain") +    if not ishtaruser.has_permission( +        "archaeological_operations.view_administrativeact" +    ) and not ishtaruser.has_permission( +        "archaeological_operations.view_own_administrativeact"      ):          return HttpResponse(content_type="text/plain")      if not request.GET.get("term"):  | 
