Class: HrLite::Admin::LeaveRequestsController
- Inherits:
-
BaseController
- Object
- HrLite::ApplicationController
- BaseController
- HrLite::Admin::LeaveRequestsController
- Defined in:
- app/controllers/hr_lite/admin/leave_requests_controller.rb
Instance Method Summary collapse
- #approve ⇒ Object
-
#cancel ⇒ Object
LeaveRequest#cancellable_by? has always allowed an admin to call off approved future leave, but no route reached it — the only cancel action was the employee's own, scoped to their own rows.
- #index ⇒ Object
- #reject ⇒ Object
- #show ⇒ Object
Instance Method Details
#approve ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/hr_lite/admin/leave_requests_controller.rb', line 15 def approve request = LeaveRequest.find(params[:id]) if request.approve!(actor: hr_current_user, note: params[:decision_note].presence) redirect_to admin_leave_requests_path, notice: "Leave approved." else redirect_to admin_leave_request_path(request), alert: "Cannot approve — balance no longer covers this request." end rescue ActiveRecord::RecordInvalid redirect_to admin_leave_request_path(request), alert: "Only pending requests can be decided." end |
#cancel ⇒ Object
LeaveRequest#cancellable_by? has always allowed an admin to call off approved future leave, but no route reached it — the only cancel action was the employee's own, scoped to their own rows. A trip called off while the person was unreachable, or after they were offboarded, could not be released at all, and the quota stayed spent.
32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/hr_lite/admin/leave_requests_controller.rb', line 32 def cancel request = LeaveRequest.find(params[:id]) if request.cancellable_by?(hr_current_user) request.cancel!(actor: hr_current_user) redirect_to admin_leave_requests_path, notice: "Leave cancelled — the balance is released." else redirect_to admin_leave_request_path(request), alert: "Only pending leave, or approved leave that has not started, can be cancelled." end end |
#index ⇒ Object
4 5 6 7 8 |
# File 'app/controllers/hr_lite/admin/leave_requests_controller.rb', line 4 def index scope = LeaveRequest.includes(:leave_type, :user).recent_first @status = params[:status].presence_in(LeaveRequest::STATUSES) || "pending" @requests = paginate(scope.where(status: @status)) end |
#reject ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/hr_lite/admin/leave_requests_controller.rb', line 43 def reject request = LeaveRequest.find(params[:id]) note = params[:decision_note].to_s.strip if note.blank? return redirect_to admin_leave_request_path(request), alert: "A note is required to reject." end request.reject!(actor: hr_current_user, note: note) redirect_to admin_leave_requests_path, notice: "Leave rejected." rescue ActiveRecord::RecordInvalid redirect_to admin_leave_request_path(request), alert: "Only pending requests can be decided." end |
#show ⇒ Object
10 11 12 13 |
# File 'app/controllers/hr_lite/admin/leave_requests_controller.rb', line 10 def show @request = LeaveRequest.includes(:leave_type).find(params[:id]) @balance = @request.balance end |