-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I believe these changes will make it easier to extend the `annual_leave_request#update_status` method to accomodate other actions, such as editing and withdrawing annual leave requests. The present solution is very rigid, requiring new EmailsHelper methods to be written for each new update action. The new solution simply needs a new StatusUpdate class to be added for the new action, and for that action to be added to the case options in the private `status_update` method in AnnualLeaveRequestController. This brings the code much closer to being open for extension.
- Loading branch information
Jonathan Young
committed
Sep 8, 2023
1 parent
8f5e6bb
commit 2d9c4b7
Showing
8 changed files
with
108 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
class ApprovedStatusUpdate | ||
include Rails.application.routes.url_helpers | ||
|
||
attr_reader :annual_leave_request, :user, :line_manager | ||
|
||
def initialize(annual_leave_request) | ||
@annual_leave_request = annual_leave_request | ||
@user = annual_leave_request.user | ||
@line_manager = user.line_manager | ||
end | ||
|
||
def confirmation_page_path | ||
confirm_annual_leave_request_approval_path | ||
end | ||
|
||
def action | ||
"approve" | ||
end | ||
|
||
def email_hash | ||
{ | ||
email_address: user.email, | ||
template_id: "34542d49-8b91-412c-9393-c186a04a7d1c", | ||
personalisation: { | ||
line_manager_name: "#{line_manager.given_name} #{line_manager.family_name}", | ||
name: "#{user.given_name} #{user.family_name}", | ||
date_from: annual_leave_request.date_from.to_fs(:rfc822), | ||
date_to: annual_leave_request.date_to.to_fs(:rfc822), | ||
}, | ||
} | ||
end | ||
end | ||
|
||
class DeniedStatusUpdate | ||
include Rails.application.routes.url_helpers | ||
|
||
attr_reader :annual_leave_request, :user, :line_manager | ||
|
||
def initialize(annual_leave_request) | ||
@annual_leave_request = annual_leave_request | ||
@user = annual_leave_request.user | ||
@line_manager = user.line_manager | ||
end | ||
|
||
def confirmation_page_path | ||
confirm_annual_leave_request_denial_path | ||
end | ||
|
||
def action | ||
"deny" | ||
end | ||
|
||
def email_hash | ||
{ | ||
email_address: user.email, | ||
template_id: "ec9035df-9c98-4e0e-8826-47768c311745", | ||
personalisation: { | ||
line_manager_name: "#{line_manager.given_name} #{line_manager.family_name}", | ||
name: "#{user.given_name} #{user.family_name}", | ||
date_from: annual_leave_request.date_from.to_fs(:rfc822), | ||
date_to: annual_leave_request.date_to.to_fs(:rfc822), | ||
denial_reason: annual_leave_request.denial_reason, | ||
}, | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.