-
Notifications
You must be signed in to change notification settings - Fork 154
/
integrations_controller.rb
66 lines (59 loc) · 2.21 KB
/
integrations_controller.rb
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
module Backend
class IntegrationsController < Backend::BaseController
manage_restfully only: []
def index
@integration_types = ActionIntegration::Base.descendants.sort_by(&:name)
respond_to do |format|
format.html
format.xml { render xml: resource_model.all }
format.json { render json: resource_model.all }
end
end
def new
unless params[:nature]
head :unprocessable_entity
return
end
if existing = Integration.find_by(nature: params[:nature])
redirect_to action: :edit, controller: :integrations, id: existing.id
return
end
@integration = Integration.new(nature: params[:nature], parameters: (params[:parameters] || {}))
t3e(@integration.attributes.merge(name: @integration.name))
render(locals: { cancel_url: :back })
end
def edit
return unless @integration = find_and_check(:integration)
t3e(@integration.attributes.merge(name: @integration.name))
render(locals: { cancel_url: :back })
end
def destroy
return unless existing = Integration.find_by(nature: params[:nature])
redirect_to action: :index, controller: :integrations if existing.destroy!
end
def create
@integration = resource_model.new(permitted_params)
t3e(@integration.attributes.merge(name: @integration.name))
return if save_and_redirect(@integration, url: :backend_integrations)
render(locals: { cancel_url: :backend_integrations })
end
def update
return unless @integration = find_and_check(:integration)
t3e(@integration.attributes.merge(name: @integration.name))
@integration.attributes = permitted_params
return if save_and_redirect(@integration, url: :backend_integrations)
render(locals: { cancel_url: :back })
end
def check
unless params[:nature]
head :unprocessable_entity
return
end
@integration = Integration.find_or_initialize_by(nature: params[:nature])
@integration.parameters[:access_token] = params[:access_token]
@integration.parameters[:token_type] = params[:token_type] if params[:token_type]
@integration.save!
redirect_to action: :index
end
end
end