Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Leitzen <pleitzen@gitlab.com>2019-09-09 23:22:00 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2019-09-09 23:22:00 +0300
commitafe5f171db0b6b44e54c3c083fb51d24a35981b2 (patch)
tree0e419e594357e5d0c5925ff084f8a9f61dd6ee91 /app/controllers
parenta502a9d2a8b0e89c1f221e3f30016010150b300f (diff)
Expose update project service JSON endpoint
Utilize `json_fields` to expose fields via `Service#as_json(only: json_fields)`.
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/projects/services_controller.rb27
1 files changed, 23 insertions, 4 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb
index e0df51590ae..c9f680a4696 100644
--- a/app/controllers/projects/services_controller.rb
+++ b/app/controllers/projects/services_controller.rb
@@ -18,10 +18,23 @@ class Projects::ServicesController < Projects::ApplicationController
def update
@service.attributes = service_params[:service]
- if @service.save(context: :manual_change)
- redirect_to(project_settings_integrations_path(@project), notice: success_message)
- else
- render 'edit'
+ saved = @service.save(context: :manual_change)
+
+ respond_to do |format|
+ format.html do
+ if saved
+ redirect_to project_settings_integrations_path(@project),
+ notice: success_message
+ else
+ render 'edit'
+ end
+ end
+
+ format.json do
+ status = saved ? :ok : :unprocessable_entity
+
+ render json: serialize_as_json, status: status
+ end
end
end
@@ -67,4 +80,10 @@ class Projects::ServicesController < Projects::ApplicationController
def ensure_service_enabled
render_404 unless service
end
+
+ def serialize_as_json
+ @service
+ .as_json(only: @service.json_fields)
+ .merge(errors: @service.errors.as_json)
+ end
end