Class: HrLite::CompOffRequestsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/hr_lite/comp_off_requests_controller.rb

Overview

Employee-side comp-off: request a credit for working a weekend/holiday. Scoping to hr_current_user IS the authorization.

Instance Method Summary collapse

Instance Method Details

#cancelObject



26
27
28
29
30
31
32
# File 'app/controllers/hr_lite/comp_off_requests_controller.rb', line 26

def cancel
  request = CompOffRequest.where(user_id: hr_current_user.id).find(params[:id])
  request.cancel!(actor: hr_current_user)
  redirect_to comp_off_requests_path, notice: "Request cancelled."
rescue ActiveRecord::RecordInvalid
  redirect_to comp_off_requests_path, alert: "Only pending requests can be cancelled."
end

#createObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/hr_lite/comp_off_requests_controller.rb', line 14

def create
  @request = CompOffRequest.new(request_params.merge(user_id: hr_current_user.id))
  if @request.save
    redirect_to comp_off_requests_path, notice: "Comp-off request sent for approval."
  else
    render :new, status: :unprocessable_entity
  end
rescue ActiveRecord::RecordNotUnique
  @request.errors.add(:date_worked, "already has a comp-off request")
  render :new, status: :unprocessable_entity
end

#indexObject



5
6
7
8
# File 'app/controllers/hr_lite/comp_off_requests_controller.rb', line 5

def index
  @requests = paginate(CompOffRequest.where(user_id: hr_current_user.id).recent_first)
  @comp_off_type = LeaveType.comp_off_type
end

#newObject



10
11
12
# File 'app/controllers/hr_lite/comp_off_requests_controller.rb', line 10

def new
  @request = CompOffRequest.new(date_worked: default_date)
end