This repository was archived by the owner on Nov 6, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathapplication_controller.rb
More file actions
64 lines (49 loc) · 1.84 KB
/
application_controller.rb
File metadata and controls
64 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class ApplicationController < ActionController::Base
include Pundit
helper_method :current_partner
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
rescue_from ActiveRecord::RecordInvalid do |exception|
Rails.logger.error(exception.message)
exception.backtrace.each do |line|
Rails.logger.error(line)
end
render json: { errors: exception.record.errors.full_messages }, status: :unprocessable_entity
end
rescue_from ActiveModel::ValidationError do |exception|
render json: { errors: exception.model.errors.full_messages }, status: :unprocessable_entity
end
def after_sign_out_path_for(*)
new_user_session_path
end
def current_partner
current_user&.partner
end
def verify_status_in_diaper_base
if current_partner.status_in_diaper_base == "deactivated"
flash[:alert] = 'Your account has been disabled, contact the organization via their email to reactivate'
redirect_to partner_requests_path
end
end
def authorize_verified_partners
return if current_partner.verified?
redirect_to partner_requests_path, notice: "Please review your application details and submit for approval in order to make a new request."
end
private
def user_not_authorized
redirect_to(request.referer || root_path, notice: "You are not authorized to perform this action.")
end
helper_method :valid_items
def valid_items
@valid_items ||= DiaperBankClient.get_available_items(current_partner.diaper_bank_id, current_partner.id)
end
helper_method :fetch_valid_item
def fetch_valid_item(id)
valid_items.find { |vi| vi["id"] == id }
end
helper_method :item_id_to_display_string_map
def item_id_to_display_string_map
@item_id_to_display_string_map ||= valid_items.each_with_object({}) do |item, hash|
hash[item["id"].to_i] = item["name"]
end
end
end