Skip to content

Commit

Permalink
- Rules: Validation Logic Piano Promotion from 'DRAFT' to 'ANAGRAFICA'
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Feb 6, 2019
1 parent 19cb4e5 commit 9221b3a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
72 changes: 48 additions & 24 deletions strt/serapide_core/api/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
from ..modello.models import ProceduraVAS


# ############################################################################ #
# User
# ############################################################################ #
rules.add_rule(
'strt_core.api.can_access_private_area',
is_recognizable
)


# ############################################################################ #
# User <--> Piano
# ############################################################################ #
Expand All @@ -45,12 +36,6 @@ def can_access_piano(user, piano):
)


rules.add_rule(
'strt_core.api.can_edit_piano',
is_RUP & can_access_piano
)


# ############################################################################ #
# Piano
# ############################################################################ #
Expand Down Expand Up @@ -90,17 +75,56 @@ def has_procedura_vas(piano):
return ProceduraVAS.objects.filter(piano=piano).count() == 1


rules.add_rule(
'strt_core.api.fase_anagrafica_completa',
is_draft & has_data_delibera & has_description & \
has_delibera_comunale & has_soggetto_proponente & \
has_procedura_vas
)


# ############################################################################ #
# Procedura VAS
# ############################################################################ #
@rules.predicate
def procedura_vas_is_valid(piano):
def procedura_vas_is_valid(piano, procedura_vas):
if procedura_vas.piano == piano:
if procedura_vas.fase == FASE.draft:
if procedura_vas.tipologia == TIPOLOGIA_VAS.semplificata:
if procedura_vas.risorse.filter(tipo='vas_semplificata').count() == 1 and \
procedura_vas.risorse.get(tipo='vas_semplificata').dimensione > 0 and \
procedura_vas.risorse.get(tipo='vas_semplificata').file and \
os.path.exists(procedura_vas.risorse.get(tipo='vas_semplificata').file.path):
return True
return False
elif procedura_vas.tipologia == TIPOLOGIA_VAS.verifica:
if procedura_vas.risorse.filter(tipo='vas_verifica').count() > 0:
return procedura_vas.risorse.filter(tipo='vas_verifica').count() > 0 and \
all(
r.dimensione > 0 and r.file and os.path.exists(r.file.path)
for r in procedura_vas.risorse.filter(tipo='vas_verifica')
)
return False
elif procedura_vas.tipologia == TIPOLOGIA_VAS.procedimento:
return (
piano.autorita_competente_vas.count() > 0 and \
piano.soggetti_sca.count() > 0
)
elif procedura_vas.tipologia == TIPOLOGIA_VAS.non_necessaria:
return True
else:
return False
return False


# ############################################################################ #
# RULES
# ############################################################################ #
rules.add_rule(
'strt_core.api.can_access_private_area',
is_recognizable
)

rules.add_rule(
'strt_core.api.can_edit_piano',
is_RUP & can_access_piano
)

rules.add_rule(
'strt_core.api.fase_anagrafica_completa',
is_draft & has_data_delibera & has_description & \
has_delibera_comunale & has_soggetto_proponente & \
has_procedura_vas & procedura_vas_is_valid
)
4 changes: 2 additions & 2 deletions strt/serapide_core/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,12 +1042,12 @@ def get_next_phase(cls, fase):
@classmethod
def mutate(cls, root, info, **input):
_piano = Piano.objects.get(codice=input['codice_piano'])
_procedura_vas = ProceduraVAS.objects.get(piano=piano)
if rules.test_rule('strt_core.api.can_edit_piano', info.context.user, _piano):
try:
_next_fase = cls.get_next_phase(_piano.fase)
if rules.test_rule('strt_core.api.fase_{next}_completa'.format(next=_next_fase), _piano):
if rules.test_rule('strt_core.api.fase_{next}_completa'.format(next=_next_fase), _piano, _procedura_vas):
_piano.fase = Fase.objects.get(nome=_next_fase)
_procedura_vas = ProceduraVAS.objects.get(piano=piano)
_procedura_vas.fase = _piano.fase

_piano.save()
Expand Down

0 comments on commit 9221b3a

Please sign in to comment.