Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/crud-laboratories' into crud-cds…
Browse files Browse the repository at this point in the history
…-websites
  • Loading branch information
revelis-vincenzo committed Oct 20, 2023
2 parents 51ce921 + 18dd3a4 commit c10b08b
Show file tree
Hide file tree
Showing 28 changed files with 3,979 additions and 510 deletions.
6 changes: 4 additions & 2 deletions crud/companies/templates/company_unical_referent.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ <h3 style="font-weight: lighter;" class="mb-4">
<div class="card-body">
{% include "blocks/includes/choose_teacher.html" with required=1 %}
<hr />
{% include "form_template.html" with form=form %}
{% include "includes/form_submit.html" %}
<form method="post" novalidate>
{% include "form_template.html" with form=form %}
{% include "includes/form_submit.html" %}
</form>
</div>
</div>
</div>
Expand Down
75 changes: 71 additions & 4 deletions crud/laboratories/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from .. utils.settings import *
from .. utils.utils import custom_message


def can_manage_laboratories(func_to_decorate):
"""
List
"""
def new_func(*original_args, **original_kwargs):
request = original_args[0]
Expand All @@ -21,15 +21,82 @@ def new_func(*original_args, **original_kwargs):
LaboratorioDatiBase, pk=original_kwargs['code'])
original_kwargs['laboratory'] = laboratory


if request.user.is_superuser:
return func_to_decorate(*original_args, **original_kwargs)

my_offices = OrganizationalStructureOfficeEmployee.objects.filter(employee=request.user,
office__name=OFFICE_LABORATORIES,
offices = OrganizationalStructureOfficeEmployee.objects.filter(employee=request.user,
office__is_active=True,
office__organizational_structure__is_active=True)
if not my_offices:

my_offices = offices.filter(office__name=OFFICE_LABORATORIES)
is_validator = offices.filter(office__name=OFFICE_LABORATORY_VALIDATORS).exists()


original_kwargs['my_offices'] = my_offices
original_kwargs['is_validator'] = is_validator

if not (my_offices.exists() or is_validator):
return custom_message(request, _("Permission denied"))
return func_to_decorate(*original_args, **original_kwargs)

return new_func

#Does not prevent POST from validator users
def can_view_laboratories(func_to_decorate):
"""
Detail
"""
def new_func(*original_args, **original_kwargs):
request = original_args[0]
laboratory = original_kwargs['laboratory']

if request.user.is_superuser:
return func_to_decorate(*original_args, **original_kwargs)

my_offices = original_kwargs['my_offices']
department_id = laboratory.id_dipartimento_riferimento

my_offices = my_offices.filter(office__organizational_structure__unique_code = department_id.dip_cod)
original_kwargs['my_offices'] = my_offices

if original_kwargs['is_validator'] or my_offices.exists():
return func_to_decorate(*original_args, **original_kwargs)


return custom_message(request, _("Permission denied"))

return new_func

def check_if_superuser(func_to_decorate):
"""
"""
def new_func(*original_args, **original_kwargs):
request = original_args[0]

if request.user.is_superuser:
return func_to_decorate(*original_args, **original_kwargs)

return custom_message(request, _("Permission denied"))

return new_func

def can_edit_laboratories(func_to_decorate):
"""
Detail
"""
def new_func(*original_args, **original_kwargs):
request = original_args[0]

if request.user.is_superuser:
return func_to_decorate(*original_args, **original_kwargs)

laboratory = original_kwargs['laboratory']
my_offices = original_kwargs['my_offices']

if not my_offices.exists():
return custom_message(request, _("Permission denied"))

return func_to_decorate(*original_args, **original_kwargs)

return new_func
Loading

0 comments on commit c10b08b

Please sign in to comment.