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

Create mention notification for case worker when exporter responds #1805

Merged
merged 12 commits into from
Feb 14, 2024

Conversation

hnryjmes
Copy link
Contributor

@hnryjmes hnryjmes commented Feb 5, 2024

Aim

A query is raised by a specific case worker. When an exporter responds to the query, a system mention is created that notifies the case worker that the exporter has responded to their query.

LTD-4620

@hnryjmes hnryjmes changed the title wip: mention notification for case worker when exporter closes query wip: mention notification for case worker when exporter has replied Feb 5, 2024
@hnryjmes hnryjmes changed the title wip: mention notification for case worker when exporter has replied wip: create mention notification for case worker when exporter has replied Feb 5, 2024
api/cases/views/views.py Outdated Show resolved Hide resolved
@hnryjmes hnryjmes force-pushed the LTD-4620_Create_mention_notification_for_case_worker branch from 848dcf9 to f2f2b8e Compare February 8, 2024 16:54
@hnryjmes hnryjmes changed the title wip: create mention notification for case worker when exporter has replied Create mention notification for case worker when exporter has replied Feb 8, 2024
@hnryjmes hnryjmes changed the title Create mention notification for case worker when exporter has replied Create mention notification for case worker when exporter responds Feb 8, 2024
@hnryjmes hnryjmes changed the title Create mention notification for case worker when exporter responds Create mention notification for caseworker when exporter responds Feb 8, 2024
@hnryjmes hnryjmes force-pushed the LTD-4620_Create_mention_notification_for_case_worker branch 2 times, most recently from be0da09 to 3915ddf Compare February 8, 2024 16:58
@hnryjmes hnryjmes changed the title Create mention notification for caseworker when exporter responds Create mention notification for case worker when exporter responds Feb 8, 2024
@hnryjmes hnryjmes marked this pull request as ready for review February 8, 2024 17:42
api/cases/views/views.py Outdated Show resolved Hide resolved
api/cases/views/views.py Outdated Show resolved Hide resolved
api/cases/views/views.py Outdated Show resolved Hide resolved
Copy link
Contributor

@depsiatwal depsiatwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check case_notes think it can be omitted
normally just major effects to do with the case

api/cases/models.py Outdated Show resolved Hide resolved
@hnryjmes hnryjmes force-pushed the LTD-4620_Create_mention_notification_for_case_worker branch from 18b9e4d to 6edb861 Compare February 9, 2024 13:52
Copy link

codecov bot commented Feb 9, 2024

The author of this PR, hnryjmes, is not an activated member of this organization on Codecov.
Please activate this user on Codecov to display this PR comment.
Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.
Please don't hesitate to email us at [email protected] with any questions.

api/cases/views/views.py Outdated Show resolved Hide resolved
Comment on lines 655 to 657
ecju_query.case.create_system_mention(
case_note_text=f"{exporter_user_full_name} has responded to a query.",
mention_user=ecju_query.raised_by_user,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need not block this call till we create a mention so this can easily be deferred to a celery task.
It also indicates a clear separation between the two actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea but probably need some guidance to get started with writing a celery task, do you have a good example of a task I can look at? or I will just look at all of them currently there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api/cases/views/views.py Show resolved Hide resolved
Comment on lines 629 to 630
exporter_user_full_name = getattr(get_user_by_pk(request.user.pk), "full_name", "Exporter user")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_user_by_pk() can fail if the user doesn't exist but we are assigning a default value.
Should we also not fail if the user doesn't exist?

we already have is_govuser above so we can use that and query ExporterUser model directly instead of this or even request.user may already contain these details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can look at using the ExporterUser model

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it to use the ExporterUser model directly. I tried also with a try-except block initially, but this didn't seem to help much, so I removed it. if we need to test for this scenario we might need to mock request.user which seemed a bit strange hence not going down that path

"""
Create a LITE system mention e.g. exporter responded to an ECJU query
"""
from api.audit_trail import service as audit_trail_service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming this is unavoidable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually just copied this pattern because it's already in the file. There are 4-5 other methods that do this in the file so assumed there was a reason we can't reuse this audit trail service object by putting it as a file-level import.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be there are circular dependencies which cannot be avoided unless we refactor quite a bit.
See moving this to the top causes any issues and if they are not easy to fix then it can be retained otherwise no reason to leave it here.

api/cases/models.py Outdated Show resolved Hide resolved
@@ -649,7 +651,16 @@ def put(self, request, pk, ecju_pk):
target=serializer.instance.case,
payload={"ecju_response": data.get("response")},
)
return JsonResponse(data={"ecju_query": serializer.data}, status=status.HTTP_201_CREATED)

ecju_query.case.create_system_mention(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

far too much coupling

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has been updated

Create a LITE system mention e.g. exporter responded to an ECJU query
"""
# to avoid circular import ImportError these must be imported here
from api.cases.models import CaseNote, CaseNoteMentions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh I hate inline imports they can lead to all kind of problems.
how about moving to common or in it's own helper class ?

Copy link
Contributor

@depsiatwal depsiatwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@hnryjmes hnryjmes force-pushed the LTD-4620_Create_mention_notification_for_case_worker branch from 5bcaa05 to 24393c2 Compare February 13, 2024 11:59
@hnryjmes hnryjmes merged commit 6e5d039 into dev Feb 14, 2024
17 checks passed
@delete-merged-branch delete-merged-branch bot deleted the LTD-4620_Create_mention_notification_for_case_worker branch February 14, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants