Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow applicant messages for all but cancelled and archived app (HL-860) #2496

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions backend/benefit/messages/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Meta:
ApplicationStatus.RECEIVED,
ApplicationStatus.HANDLING,
ApplicationStatus.ADDITIONAL_INFORMATION_NEEDED,
ApplicationStatus.ACCEPTED,
ApplicationStatus.REJECTED,
]

def validate(self, data): # noqa: C901
Expand All @@ -45,12 +47,16 @@ def validate(self, data): # noqa: C901
if settings.NEXT_PUBLIC_MOCK_FLAG:
if not (user and user.is_authenticated):
user = get_user_model().objects.all().order_by("username").first()
elif not user.is_handler():

if not user.is_handler():
company = get_company_from_request(request)
if company != application.company:
raise PermissionDenied(_("You are not allowed to do this action"))

if application.status not in self.APPLICANT_MESSAGE_ALLOWED_STATUSES:
if (
application.status not in self.APPLICANT_MESSAGE_ALLOWED_STATUSES
or application.archived
):
raise serializers.ValidationError(
_(
"Cannot do this action because "
Expand Down
20 changes: 12 additions & 8 deletions backend/benefit/messages/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,32 @@ def test_create_handler_message_invalid(handler_api_client, handling_application


@pytest.mark.parametrize(
"status,expected_result",
"status, archived, expected_result",
[
(ApplicationStatus.DRAFT, 400),
(ApplicationStatus.RECEIVED, 201),
(ApplicationStatus.HANDLING, 201),
(ApplicationStatus.ADDITIONAL_INFORMATION_NEEDED, 201),
(ApplicationStatus.ACCEPTED, 400),
(ApplicationStatus.REJECTED, 400),
(ApplicationStatus.CANCELLED, 400),
(ApplicationStatus.DRAFT, False, 400),
(ApplicationStatus.RECEIVED, False, 201),
(ApplicationStatus.HANDLING, False, 201),
(ApplicationStatus.ADDITIONAL_INFORMATION_NEEDED, False, 201),
(ApplicationStatus.ACCEPTED, False, 201),
(ApplicationStatus.REJECTED, False, 201),
(ApplicationStatus.ACCEPTED, True, 400),
(ApplicationStatus.REJECTED, True, 400),
(ApplicationStatus.CANCELLED, False, 400),
],
)
def test_applicant_send_first_message(
api_client,
handling_application,
mock_get_organisation_roles_and_create_company,
status,
archived,
expected_result,
):
msg = deepcopy(SAMPLE_MESSAGE_PAYLOAD)
msg["message_type"] = MessageType.APPLICANT_MESSAGE
handling_application.company = mock_get_organisation_roles_and_create_company
handling_application.status = status
handling_application.archived = archived
handling_application.save()
result = api_client.post(
reverse(
Expand Down
Loading