diff --git a/app/services/flow/base_flow.rb b/app/services/flow/base_flow.rb deleted file mode 100644 index 18e201ed721..00000000000 --- a/app/services/flow/base_flow.rb +++ /dev/null @@ -1,85 +0,0 @@ -# frozen_string_literal: true - -module Flow - class BaseFlow - include Failure - - attr_accessor :flow_session - attr_reader :current_user, :current_sp, :params, :request, :json, - :http_status, :controller - - def initialize(controller, session) - @controller = controller - @redirect = nil - @json = nil - @flow_session = session - end - - def next_step - return @redirect if @redirect - step, _klass = steps.find do |_step, klass| - !@flow_session[klass.to_s] - end - step - end - - def redirect_to(url) - @redirect = url - end - - def render_json(json, status: nil) - @json = json - @http_status = status || :ok - end - - def step_handler(step) - steps[step] || actions[step] - end - - def step_handler_instance(step) - @step_handler_instances ||= {} - @step_handler_instances[step] ||= step_handler(step)&.new(self) - end - - def handle(step) - @flow_session[:error_message] = nil - handler = step_handler_instance(step) - return failure("Unhandled step #{step}") unless handler - wrap_send(handler) - end - - def extra_view_variables(step) - handler = step_handler_instance(step) - return failure("Unhandled step #{step}") unless handler - handler.extra_view_variables - end - - def extra_analytics_properties - {} - end - - def flow_path - 'standard' - end - - private - - def wrap_send(handler) - value = handler.base_call - form_response(handler, value) - end - - def form_response(obj, value) - response = BaseStep.acceptable_response_object?(value) ? value : successful_response - obj.mark_step_complete if response.success? - response - end - - def successful_response - FormResponse.new(success: true) - end - - delegate :flash, :session, :current_user, :current_sp, :params, :request, - :poll_with_meta_refresh, :analytics, to: :@controller - end -end diff --git a/app/services/flow/base_step.rb b/app/services/flow/base_step.rb deleted file mode 100644 index b273da8fd12..00000000000 --- a/app/services/flow/base_step.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -module Flow - class BaseStep - include Rails.application.routes.url_helpers - include Failure - - def initialize(flow, name) - @flow = flow - @name = name - end - - def base_call - form_response = form_submit - unless form_response.success? - flow_session[:error_message] = form_response.first_error_message - return form_response - end - create_response(form_response, call) - end - - def mark_step_complete(step = nil) - klass = step.nil? ? self.class : steps[step] - flow_session[klass.to_s] = true - end - - def mark_step_incomplete(step = nil) - klass = step.nil? ? self.class : steps[step] - flow_session.delete(klass.to_s) - nil - end - - def self.acceptable_response_object?(obj) - obj.is_a?(FormResponse) || obj.is_a?(DocAuth::Response) - end - - # Return a hash of local variables required for step view template - def extra_view_variables - {} - end - - def url_options - @flow.controller.url_options - end - - delegate :analytics_visited_event, :analytics_submitted_event, to: :class - - private - - def create_response(form_submit_response, call_response) - return form_submit_response unless BaseStep.acceptable_response_object?(call_response) - form_submit_response.merge(call_response) - end - - def form_submit - FormResponse.new(success: true) - end - - def flow_params - params[@name] - end - - def permit(*args) - params.require(:doc_auth).permit(*args) - end - - def redirect_to(url) - @flow.redirect_to(url) - end - - def render_json(json, status: nil) - @flow.render_json(json, status: status) - end - - def reset - @flow.flow_session = {} - end - - def amzn_trace_id - request.headers['X-Amzn-Trace-Id'] - end - - delegate :flash, :session, :flow_session, :current_user, :current_sp, :params, :steps, :request, - :poll_with_meta_refresh, to: :@flow - end -end diff --git a/app/services/flow/failure.rb b/app/services/flow/failure.rb deleted file mode 100644 index 23ac1d45e92..00000000000 --- a/app/services/flow/failure.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module Flow - module Failure - private - - def failure(message, extra = nil) - flow_session[:error_message] = message - form_response_params = { success: false, errors: { message: message } } - form_response_params[:extra] = extra unless extra.nil? - FormResponse.new(**form_response_params) - end - end -end