Skip to content

Commit

Permalink
Fix mail redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
AdJez committed Jan 7, 2025
1 parent 089afb2 commit 3cfe307
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 84 deletions.
51 changes: 15 additions & 36 deletions src/backend/partaj/core/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ def sent_referrals_referral_answer(cls, referral):
return f"{cls.sent_referrals_referral_detail(referral)}/answer"

@staticmethod
def unit_referral_detail(unit, referral):
def unit_referral_detail(referral):
"""
Link to a referral detail view in a given unit.
"""
return f"/app/unit/{unit}/referrals-list/referral-detail/{referral}"
return f"/app/unit/referral-detail/{referral}"

@classmethod
def unit_referral_detail_messages(cls, unit, referral):
def unit_referral_detail_messages(cls, referral):
"""
Link to a referral detail view in a given unit, opening the "Messages" tab.
"""
return f"{cls.unit_referral_detail(unit, referral)}/messages"
return f"{cls.unit_referral_detail(referral)}/messages"

@classmethod
def unit_referral_detail_answer(cls, unit, referral):
def unit_referral_detail_answer(cls, referral):
"""
Link to a referral detail view in a given unit, opening the "Answer" tab.
"""
return f"{cls.unit_referral_detail(unit, referral)}/answer"
return f"{cls.unit_referral_detail(referral)}/answer"

@staticmethod
def referral_report(referral_id):
Expand Down Expand Up @@ -126,10 +126,7 @@ def send_new_message_for_unit_member(cls, contact, referral, message):
]

# Get the path to the referral detail view from the unit inbox
unit = referral.units.filter(members=contact).first()
link_path = FrontendLink.unit_referral_detail_messages(
unit=unit.id, referral=referral.id
)
link_path = FrontendLink.unit_referral_detail_messages(referral=referral.id)

data = {
"params": {
Expand Down Expand Up @@ -230,9 +227,7 @@ def send_referral_answered_to_unit_owners(cls, referral, published_by):
unitmembership__role=UnitMembershipRole.OWNER
)
# Get the path to the referral detail view from the requester's "my referrals" view
link_path = FrontendLink.unit_referral_detail_answer(
unit=unit.id, referral=referral.id
)
link_path = FrontendLink.unit_referral_detail_answer(referral=referral.id)

for contact in contacts:
data = {
Expand Down Expand Up @@ -279,9 +274,7 @@ def send_referral_assigned(cls, referral, assignment, assigned_by):
template_id = settings.SENDINBLUE["REFERRAL_ASSIGNED_TEMPLATE_ID"]

# Get the path to the referral detail view from the unit inbox
link_path = FrontendLink.unit_referral_detail(
unit=assignment.unit.id, referral=referral.id
)
link_path = FrontendLink.unit_referral_detail(referral=referral.id)

data = {
"params": {
Expand Down Expand Up @@ -323,9 +316,7 @@ def send_validation_performed(cls, validation_request, assignees, is_validated):
unit = referral.units.filter(members__id=contact.id).first()

# Get the path to the referral detail view from the unit inbox
link_path = FrontendLink.unit_referral_detail(
unit=unit.id, referral=referral.id
)
link_path = FrontendLink.unit_referral_detail(referral=referral.id)

data = {
"params": {
Expand Down Expand Up @@ -355,9 +346,7 @@ def send_referral_assigned_unit(
template_id = settings.SENDINBLUE["REFERRAL_ASSIGNED_UNIT_TEMPLATE_ID"]

# Get the path to the referral detail view from the unit inbox
link_path = FrontendLink.unit_referral_detail(
unit=assignment.unit.id, referral=referral.id
)
link_path = FrontendLink.unit_referral_detail(referral=referral.id)

for owner in assignment.unit.members.filter(
unitmembership__role=UnitMembershipRole.OWNER
Expand Down Expand Up @@ -391,9 +380,7 @@ def send_referral_received(cls, referral, contact, unit):
template_id = settings.SENDINBLUE["REFERRAL_RECEIVED_TEMPLATE_ID"]

# Get the path to the referral detail view from the unit inbox
link_path = FrontendLink.unit_referral_detail(
unit=unit.id, referral=referral.id
)
link_path = FrontendLink.unit_referral_detail(referral=referral.id)

data = {
"params": {
Expand Down Expand Up @@ -565,9 +552,7 @@ def send_validation_requested(cls, validation_request, activity):
unit = referral.units.filter(members__id=activity.actor.id).first()

# Get the path to the referral detail view from the unit inbox
link_path = FrontendLink.unit_referral_detail(
unit=unit.id, referral=referral.id
)
link_path = FrontendLink.unit_referral_detail(referral=referral.id)

data = {
"params": {
Expand Down Expand Up @@ -672,10 +657,7 @@ def send_referral_closed(cls, contact, referral, close_explanation, closed_by):
else:
template_id = unit_member_template_id
# Get the path to the referral detail view from the unit inbox
unit = referral.units.filter(members=contact).first()
link_path = FrontendLink.unit_referral_detail(
unit=unit.id, referral=referral.id
)
link_path = FrontendLink.unit_referral_detail(referral=referral.id)

data = {
"params": {
Expand Down Expand Up @@ -715,10 +697,7 @@ def send_referral_changeurgencylevel(
else:
template_id = unit_member_template_id
# Get the path to the referral detail view from the unit inbox
unit = referral.units.filter(members=contact).first()
link_path = FrontendLink.unit_referral_detail(
unit=unit.id, referral=referral.id
)
link_path = FrontendLink.unit_referral_detail(referral=referral.id)

data = {
"params": {
Expand Down
12 changes: 4 additions & 8 deletions src/backend/tests/partaj/core/test_api_referral_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ def test_assign_referral_by_linked_unit_organizer(self, mock_mailer_send):
"assigned_by": user.get_full_name(),
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.object,
Expand Down Expand Up @@ -202,8 +201,7 @@ def test_assign_already_assigned_referral_with_title_filled(self, mock_mailer_se
"assigned_by": user.get_full_name(),
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.title,
Expand Down Expand Up @@ -254,8 +252,7 @@ def test_assign_referral_from_processing_state(self, mock_mailer_send):
"assigned_by": user.get_full_name(),
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.object,
Expand Down Expand Up @@ -306,8 +303,7 @@ def test_assign_referral_from_in_validation_state(self, mock_mailer_send):
"assigned_by": user.get_full_name(),
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.object,
Expand Down
12 changes: 4 additions & 8 deletions src/backend/tests/partaj/core/test_api_referral_assign_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def test_assign_unit_referral_by_linked_unit_organizer_with_title_filled(
1,
)
link = (
f"https://partaj/app/unit/{str(other_unit.id)}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
)
mock_mailer_send.assert_called_with(
{
Expand Down Expand Up @@ -329,8 +328,7 @@ def test_assign_unit_referral_from_received_state(self, mock_mailer_send):
1,
)
link = (
f"https://partaj/app/unit/{str(other_unit.id)}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
)
mock_mailer_send.assert_called_with(
{
Expand Down Expand Up @@ -392,8 +390,7 @@ def test_assign_unit_referral_from_processing_state(self, mock_mailer_send):
1,
)
link = (
f"https://partaj/app/unit/{str(other_unit.id)}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
)
mock_mailer_send.assert_called_with(
{
Expand Down Expand Up @@ -459,8 +456,7 @@ def test_assign_unit_referral_from_in_validation_state_with_title_filled(
1,
)
link = (
f"https://partaj/app/unit/{str(other_unit.id)}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
)
mock_mailer_send.assert_called_with(
{
Expand Down
3 changes: 1 addition & 2 deletions src/backend/tests/partaj/core/test_api_referral_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ def test_close_by_linked_user(self, mock_mailer_send):
"case_number": referral.id,
"closed_by": user.get_full_name(),
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"message": "La justification de la cloture.",
"referral_authors": referral.users.first().get_full_name(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ def test_referral_perform_answer_validation_by_requested_validator_does_validate
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.object,
Expand Down Expand Up @@ -281,8 +280,7 @@ def test_referral_perform_answer_validation_by_requested_validator_does_validate
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.title,
Expand Down Expand Up @@ -351,8 +349,7 @@ def test_referral_perform_answer_validation_by_requested_validator_does_not_vali
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.object,
Expand Down Expand Up @@ -424,8 +421,7 @@ def test_referral_perform_answer_validation_by_requested_validator_does_not_vali
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ def test_publish_referral_answer_by_linked_unit_member(self, mock_mailer_send):
"answer_sender": user.get_full_name(),
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}/answer"
f"https://partaj/app/unit/referral-detail/{referral.id}/answer"
),
"title": referral.object,
},
Expand Down Expand Up @@ -302,8 +301,7 @@ def test_publish_referral_with_title_filled_answer_by_linked_unit_member(
"answer_sender": user.get_full_name(),
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}/answer"
f"https://partaj/app/unit/referral-detail/{referral.id}/answer"
),
"title": referral.title,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ def test_referral_request_answer_validation_by_linked_unit_member_with_title_fil
"case_number": referral.id,
"created_by": user.get_full_name(),
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.title,
Expand Down Expand Up @@ -292,8 +291,7 @@ def test_referral_request_answer_validation_from_in_validation_state(
"case_number": referral.id,
"created_by": user.get_full_name(),
"link_to_referral": (
f"https://partaj/app/unit/{referral.units.get().id}"
f"/referrals-list/referral-detail/{referral.id}"
f"https://partaj/app/unit/referral-detail/{referral.id}"
),
"referral_users": referral.users.first().get_full_name(),
"title": referral.object,
Expand Down
18 changes: 6 additions & 12 deletions src/backend/tests/partaj/core/test_api_referralmessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ def test_create_referralmessage_by_referral_linked_user_with_title_filled(
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{owner_membership.unit.id}"
f"/referrals-list/referral-detail/{referral.id}/messages"
f"https://partaj/app/unit/referral-detail/{referral.id}/messages"
),
"message_author": referral.users.first().get_full_name(),
"referral_author": referral.users.first().get_full_name(),
Expand Down Expand Up @@ -272,8 +271,7 @@ def test_create_referralmessage_by_referral_linked_unit_member_with_all_notifica
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{membership.unit.id}"
f"/referrals-list/referral-detail/{referral.id}/messages"
f"https://partaj/app/unit/referral-detail/{referral.id}/messages"
),
"message_author": user.get_full_name(),
"referral_author": referral.get_users_text_list(),
Expand Down Expand Up @@ -466,8 +464,7 @@ def test_create_referralmessage_by_requester_with_all_notifications_types(
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{membership.unit.id}"
f"/referrals-list/referral-detail/{referral.id}/messages"
f"https://partaj/app/unit/referral-detail/{referral.id}/messages"
),
"message_author": requester_all.get_full_name(),
"referral_author": referral.get_users_text_list(),
Expand Down Expand Up @@ -661,8 +658,7 @@ def test_create_referralmessage_by_referral_linked_unit_member(
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{unit1_member_membership.unit.id}"
f"/referrals-list/referral-detail/{referral.id}/messages"
f"https://partaj/app/unit/referral-detail/{referral.id}/messages"
),
"message_author": user.get_full_name(),
"referral_author": referral.users.first().get_full_name(),
Expand Down Expand Up @@ -694,8 +690,7 @@ def test_create_referralmessage_by_referral_linked_unit_member(
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{unit2_owner_membership.unit.id}"
f"/referrals-list/referral-detail/{referral.id}/messages"
f"https://partaj/app/unit/referral-detail/{referral.id}/messages"
),
"message_author": user.get_full_name(),
"referral_author": referral.users.first().get_full_name(),
Expand Down Expand Up @@ -726,8 +721,7 @@ def test_create_referralmessage_by_referral_linked_unit_member(
"params": {
"case_number": referral.id,
"link_to_referral": (
f"https://partaj/app/unit/{unit1_member_membership.unit.id}"
f"/referrals-list/referral-detail/{referral.id}/messages"
f"https://partaj/app/unit/referral-detail/{referral.id}/messages"
),
"message_author": user.get_full_name(),
"referral_author": referral.users.first().get_full_name(),
Expand Down
Loading

0 comments on commit 3cfe307

Please sign in to comment.