2017-01-09 15:46:43 +01:00
|
|
|
class RequestsController < ApplicationController
|
2019-03-24 22:31:03 +01:00
|
|
|
load_and_authorize_resource :user, find_by: :name
|
2017-01-09 15:46:43 +01:00
|
|
|
|
|
|
|
before_action :load_request, only: [:confirm, :decline]
|
2019-05-31 02:45:49 +02:00
|
|
|
authorize_resource :request, id_param: :request_id, only: [:confirm, :decline]
|
2017-01-09 15:46:43 +01:00
|
|
|
|
|
|
|
def index
|
2017-01-09 16:22:58 +01:00
|
|
|
@requests = @user.incoming_requests.group_by(&:status)
|
2019-04-10 14:15:20 +02:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { }
|
|
|
|
format.json { render json: @requests }
|
|
|
|
end
|
2017-01-09 15:46:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def confirm
|
|
|
|
@request.confirm!
|
2017-01-14 16:22:44 +01:00
|
|
|
redirect_to root_path
|
2017-01-09 15:46:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def decline
|
|
|
|
@request.decline!
|
2017-01-14 16:22:44 +01:00
|
|
|
redirect_to root_path
|
2017-01-09 15:46:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_request
|
|
|
|
@request = Request.find params[:request_id]
|
|
|
|
end
|
|
|
|
end
|