forked from sketch-city/harvey-api
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcharitable_organizations_controller.rb
More file actions
92 lines (74 loc) · 2.94 KB
/
charitable_organizations_controller.rb
File metadata and controls
92 lines (74 loc) · 2.94 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class CharitableOrganizationsController < ApplicationController
before_action :set_headers
before_action :set_charitable_organization, only: [:show, :edit, :update, :destroy, :archive]
def index
@charitable_organizations = CharitableOrganization.all
end
def new
@charitable_organization = CharitableOrganization.new
end
def create
if(user_signed_in? && current_user.admin?)
@charitable_organization = CharitableOrganization.new(charitable_organization_update_params)
if @charitable_organization.save
redirect_to @charitable_organization, notice: 'Charitable Organization was successfully created.'
else
render :new
end
else
draft = Draft.new(info: charitable_organization_update_params.merge({record_type: CharitableOrganization.name}), created_by: current_user)
if draft.save
redirect_to draft, notice: 'Your new Charitable Organization is pending approval.'
send_slack_notification "New CharitableOrganization: https://irma-api.herokuapp.com/drafts/#{draft.id}"
else
@charitable_organization = CharitableOrganization.new(charitable_organization_update_params)
render :new
end
end
end
def show
@charitable_organization = CharitableOrganization.find(params[:id])
end
def destroy
end
def archive
if(user_signed_in? && current_user.admin?)
@charitable_organization.update_attributes(active: false)
redirect_to charitable_organizations_path, notice: "Archived!"
else
redirect_to charitable_organizations_path, notice: "You must be an admin to archive."
end
end
def edit
end
def update
if(user_signed_in? && current_user.admin?)
if @charitable_organization.update(charitable_organization_update_params)
redirect_to @charitable_organization, notice: 'Charitable Organization was successfully updated.'
else
render :edit
end
else
draft = Draft.new(record: @charitable_organization, info: charitable_organization_update_params, created_by: current_user)
if draft.save
redirect_to draft, notice: 'Your Charitable Organization update is pending approval.'
send_slack_notification "CharitableOrganization Updated: https://irma-api.herokuapp.com/drafts/#{draft.id}"
else
render :edit
end
end
end
def drafts
@drafts = Draft.includes(:record).where("record_type = ? OR info->>'record_type' = 'CharitableOrganization'", CharitableOrganization.name).where(accepted_by_id: nil).where(denied_by_id: nil)
end
def set_headers
@columns = CharitableOrganization::ColumnNames
@headers = CharitableOrganization::HeaderNames
end
def set_charitable_organization
@charitable_organization = CharitableOrganization.find(params[:id])
end
def charitable_organization_update_params
params.require(:charitable_organization).permit(CharitableOrganization::UpdateFields).keep_if { |_,v| v.present? }
end
end