2020-03-26 02:08:40 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module IntegrationsActions
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2021-05-04 02:10:20 -04:00
|
|
|
include Integrations::Params
|
2020-03-26 02:08:40 -04:00
|
|
|
|
|
|
|
before_action :integration, only: [:edit, :update, :test]
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
render 'shared/integrations/edit'
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2021-05-04 02:10:20 -04:00
|
|
|
saved = integration.update(integration_params[:integration])
|
2020-03-26 02:08:40 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
if saved
|
2020-09-25 17:09:51 -04:00
|
|
|
PropagateIntegrationWorker.perform_async(integration.id)
|
2020-03-26 02:08:40 -04:00
|
|
|
redirect_to scoped_edit_integration_path(integration), notice: success_message
|
|
|
|
else
|
|
|
|
render 'shared/integrations/edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
|
|
|
status = saved ? :ok : :unprocessable_entity
|
|
|
|
|
|
|
|
render json: serialize_as_json, status: status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test
|
2020-04-03 20:09:37 -04:00
|
|
|
render json: {}, status: :ok
|
2020-03-26 02:08:40 -04:00
|
|
|
end
|
|
|
|
|
2020-12-02 19:09:53 -05:00
|
|
|
def reset
|
2020-12-10 07:09:43 -05:00
|
|
|
integration.destroy!
|
|
|
|
|
2020-12-02 19:09:53 -05:00
|
|
|
flash[:notice] = s_('Integrations|This integration, and inheriting projects were reset.')
|
|
|
|
|
|
|
|
render json: {}, status: :ok
|
|
|
|
end
|
|
|
|
|
2020-03-26 02:08:40 -04:00
|
|
|
private
|
|
|
|
|
2021-05-20 11:10:13 -04:00
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2020-03-26 02:08:40 -04:00
|
|
|
def integration
|
2021-05-04 02:10:20 -04:00
|
|
|
@integration ||= find_or_initialize_non_project_specific_integration(params[:id])
|
2020-03-26 02:08:40 -04:00
|
|
|
end
|
2021-05-20 11:10:13 -04:00
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
2020-03-26 02:08:40 -04:00
|
|
|
|
|
|
|
def success_message
|
2020-09-15 14:09:43 -04:00
|
|
|
if integration.active?
|
|
|
|
s_('Integrations|%{integration} settings saved and active.') % { integration: integration.title }
|
|
|
|
else
|
|
|
|
s_('Integrations|%{integration} settings saved, but not active.') % { integration: integration.title }
|
|
|
|
end
|
2020-03-26 02:08:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def serialize_as_json
|
|
|
|
integration
|
|
|
|
.as_json(only: integration.json_fields)
|
|
|
|
.merge(errors: integration.errors.as_json)
|
|
|
|
end
|
|
|
|
end
|