Skip to content

Commit

Permalink
fix: preselect decision maker if it was selected before (hl-1530) (#3522
Browse files Browse the repository at this point in the history
)

* fix: decision maker validation for decision proposal

* refactor: deprecate handler_role from proposals in favor of decision_maker

* refactor: remove unused api view

* fix: rather than trusting frontend on input, fetch the decision maker from backend using id

* chore: update translations

* fix: deprecate handlerRole from frontend

* fix: select decision maker if previously chosen and display it in review box

* fix: crashing bug when hitting cancel when cancelling application in modal prompt

* chore: migration for handler_role

* test: add ahjo settings to test
  • Loading branch information
sirtawast authored Nov 11, 2024
1 parent 34e6201 commit 45095c5
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 171 deletions.
26 changes: 22 additions & 4 deletions backend/benefit/applications/api/v1/ahjo_decision_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from applications.models import (
AhjoDecisionProposalDraft,
AhjoDecisionText,
AhjoSetting,
Application,
ApplicationLogEntry,
DecisionProposalTemplateSection,
Expand Down Expand Up @@ -182,6 +183,23 @@ def patch(self, request):
decision_text = f'<section id="paatos"><h1>{_("Päätös")}</h1>{decision_part}</section>\
<section id="paatoksenperustelut"><h1>{_("Päätöksen perustelut")}</h1>{justification_part}</section>'

available_decision_makers = AhjoSetting.objects.get(
name="ahjo_decision_maker"
).data

decision_maker_id = request.data.get("decision_maker_id")
decision_maker = next(
(
item
for item in available_decision_makers
if item["ID"] == decision_maker_id
),
None,
)

if decision_maker is None:
decision_maker = {"ID": None, "Name": None}

if ahjo_text:
ahjo_text.update(
language=application.applicant_language,
Expand All @@ -191,8 +209,8 @@ def patch(self, request):
else DecisionType.DENIED
),
decision_text=decision_text,
decision_maker_id=data.get("decision_maker_id"),
decision_maker_name=data.get("decision_maker_name"),
decision_maker_id=decision_maker["ID"],
decision_maker_name=decision_maker["Name"],
)
else:
AhjoDecisionText.objects.create(
Expand All @@ -204,8 +222,8 @@ def patch(self, request):
else DecisionType.DENIED
),
decision_text=decision_text,
decision_maker_id=data.get("decision_maker_id"),
decision_maker_name=data.get("decision_maker_name"),
decision_maker_id=decision_maker["ID"],
decision_maker_name=decision_maker["Name"],
)

if data["review_step"] >= 4:
Expand Down
129 changes: 0 additions & 129 deletions backend/benefit/applications/api/v1/decision_proposal_draft_views.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.core.exceptions import ValidationError
from rest_framework import serializers

from applications.enums import ApplicationStatus, HandlerRole
from applications.enums import ApplicationStatus
from applications.models import AhjoDecisionProposalDraft


class AhjoDecisionProposalReadOnlySerializer(serializers.ModelSerializer):
"""Used to get the draft listed in Application serializer"""

class Meta:
model = AhjoDecisionProposalDraft
fields = [
Expand All @@ -14,18 +16,14 @@ class Meta:
"decision_text",
"justification_text",
"review_step",
"handler_role",
"log_entry_comment",
"decision_maker_id",
"decision_maker_name",
]


class AhjoDecisionProposalSerializer(serializers.ModelSerializer):
"""
# TODO: Add description
"""
"""Used for manipulating the decision proposal draft on PATCH requests"""

class Meta:
model = AhjoDecisionProposalDraft
Expand All @@ -35,7 +33,6 @@ class Meta:
"decision_text",
"justification_text",
"review_step",
"handler_role",
"log_entry_comment",
"decision_maker_id",
"decision_maker_name",
Expand Down Expand Up @@ -78,11 +75,8 @@ def validate(self, data):
errors.append(
ValidationError("Decision or justification texts cannot be empty")
)
if (data.get("handler_role", None)) not in [
HandlerRole.HANDLER,
HandlerRole.MANAGER,
]:
errors.append(ValidationError("Handler role must be specified"))
if len(data.get("decision_maker_id", "None")) <= 0:
errors.append(ValidationError("Decision maker id must be specified"))
if len(errors) > 0:
raise ValidationError(errors)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-11-07 07:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('applications', '0085_alter_ahjostatus_status'),
]

operations = [
migrations.AlterField(
model_name='ahjodecisionproposaldraft',
name='handler_role',
field=models.CharField(blank=True, choices=[('handler', 'Helsinki-benefit handler'), ('manager', 'Team manager')], max_length=64, null=True, verbose_name='Handler role (deprecated, was used before dynamic fetch of decision makers)'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-11-07 11:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('applications', '0086_alter_ahjodecisionproposaldraft_handler_role'),
]

operations = [
migrations.AlterField(
model_name='ahjodecisionproposaldraft',
name='handler_role',
field=models.CharField(blank=True, choices=[('handler', 'Helsinki-benefit handler'), ('manager', 'Team manager')], max_length=64, null=True, verbose_name='Handler role (DEPRECATED, was used before dynamic fetch of decision makers)'),
),
]
4 changes: 3 additions & 1 deletion backend/benefit/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,9 @@ class Meta:

handler_role = models.CharField(
max_length=64,
verbose_name=_("Handler role"),
verbose_name=_(
"Handler role (DEPRECATED, was used before dynamic fetch of decision makers)"
),
blank=True,
null=True,
choices=HandlerRole.choices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.conf import settings

from applications.enums import AhjoDecisionDetails, DecisionType, HandlerRole
from applications.enums import AhjoDecisionDetails, DecisionType
from applications.models import (
AhjoDecisionText,
Application,
Expand All @@ -25,7 +25,7 @@ def replace_decision_template_placeholders(
text_to_replace: str,
decision_type: DecisionType,
application: Application,
decision_maker: HandlerRole = HandlerRole.HANDLER,
decision_maker=None,
) -> str:
"""Replace the placeholders starting with $ in the decision template with real data"""
text_to_replace = Template(text_to_replace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def test_decision_proposal_drafting(
decision_text,
justification_text,
fake_decisionmakers,
decision_maker_settings,
):
if review_step == 4:
_prepare_calculation(application=application)
Expand Down
5 changes: 3 additions & 2 deletions frontend/benefit/handler/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@
"calculation": "Tarkista laskelma",
"status": "Puoltotieto puuttuu",
"logEntry": "Päätöksen perustelu puuttuu",
"handler": "Päättäjän rooli puuttuu",
"decisionMakerId": "Päättäjän rooli puuttuu",
"decisionText": "Päätös ei voi olla tyhjä",
"justificationText": "Päätöksen perustelu ei voi olla tyhjä"
}
Expand All @@ -1216,7 +1216,8 @@
"employerName": "Hakija",
"employeeName": "Työllistettävä",
"totalAmount": "Myönnettävä tuki yhteensä",
"grantedAsDeMinimisAid": "Myönnetään de minimis -tukena"
"grantedAsDeMinimisAid": "Myönnetään de minimis -tukena",
"decisionMaker": "Päättäjän rooli"
},
"calculationReview": {
"tableCaption": "Tukijaksot",
Expand Down
5 changes: 3 additions & 2 deletions frontend/benefit/handler/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@
"calculation": "Tarkista laskelma",
"status": "Puoltotieto puuttuu",
"logEntry": "Päätöksen perustelu puuttuu",
"handler": "Päättäjän rooli puuttuu",
"decisionMakerId": "Päättäjän rooli puuttuu",
"decisionText": "Päätös ei voi olla tyhjä",
"justificationText": "Päätöksen perustelu ei voi olla tyhjä"
}
Expand All @@ -1216,7 +1216,8 @@
"employerName": "Hakija",
"employeeName": "Työllistettävä",
"totalAmount": "Myönnettävä tuki yhteensä",
"grantedAsDeMinimisAid": "Myönnetään de minimis -tukena"
"grantedAsDeMinimisAid": "Myönnetään de minimis -tukena",
"decisionMaker": "Päättäjän rooli"
},
"calculationReview": {
"tableCaption": "Tukijaksot",
Expand Down
5 changes: 3 additions & 2 deletions frontend/benefit/handler/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@
"calculation": "Tarkista laskelma",
"status": "Puoltotieto puuttuu",
"logEntry": "Päätöksen perustelu puuttuu",
"handler": "Päättäjän rooli puuttuu",
"decisionMakerId": "Päättäjän rooli puuttuu",
"decisionText": "Päätös ei voi olla tyhjä",
"justificationText": "Päätöksen perustelu ei voi olla tyhjä"
}
Expand All @@ -1216,7 +1216,8 @@
"employerName": "Hakija",
"employeeName": "Työllistettävä",
"totalAmount": "Myönnettävä tuki yhteensä",
"grantedAsDeMinimisAid": "Myönnetään de minimis -tukena"
"grantedAsDeMinimisAid": "Myönnetään de minimis -tukena",
"decisionMaker": "Päättäjän rooli"
},
"calculationReview": {
"tableCaption": "Tukijaksot",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ const CalculationReview: React.FC<ApplicationReviewStepProps> = ({
</div>
</>
)}
<div style={{ maxWidth: '220px', minWidth: '220px' }}>
<dt>{t('common:review.decisionProposal.list.decisionMaker')}</dt>
<dd>
{handledApplication.decisionMakerName ||
decisionProposalDraft.decisionMakerName}
</dd>
</div>
</$HorizontalList>
</$GridCell>
{handledApplication.status === APPLICATION_STATUSES.ACCEPTED && (
Expand Down
Loading

0 comments on commit 45095c5

Please sign in to comment.