diff options
Diffstat (limited to 'app/controllers/projects/static_site_editor_controller.rb')
-rw-r--r-- | app/controllers/projects/static_site_editor_controller.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/app/controllers/projects/static_site_editor_controller.rb b/app/controllers/projects/static_site_editor_controller.rb index e97a8db0b79..7e2e32a843f 100644 --- a/app/controllers/projects/static_site_editor_controller.rb +++ b/app/controllers/projects/static_site_editor_controller.rb @@ -13,6 +13,8 @@ class Projects::StaticSiteEditorController < Projects::ApplicationController push_frontend_feature_flag(:sse_image_uploads) end + feature_category :static_site_editor + def show service_response = ::StaticSiteEditor::ConfigService.new( container: project, @@ -25,14 +27,32 @@ class Projects::StaticSiteEditorController < Projects::ApplicationController ).execute if service_response.success? - @data = service_response.payload + Gitlab::UsageDataCounters::StaticSiteEditorCounter.increment_views_count + + @data = serialize_necessary_payload_values_to_json(service_response.payload) else - respond_422 + # TODO: For now, if the service returns any error, the user is redirected + # to the root project page with the error message displayed as an alert. + # See https://gitlab.com/gitlab-org/gitlab/-/issues/213285#note_414808004 + # for discussion of plans to handle this via a page owned by the Static Site Editor. + flash[:alert] = service_response.message + redirect_to project_path(project) end end private + def serialize_necessary_payload_values_to_json(payload) + # This will convert booleans, Array-like and Hash-like objects to JSON + payload.transform_values do |value| + if value.is_a?(String) || value.is_a?(Integer) + value + else + value.to_json + end + end + end + def assign_ref_and_path @ref, @path = extract_ref(params.fetch(:id)) |