Sha256: 4b35d2a761958037c39ee2bd6c5e0eabfec3a7ff1b602870ebe2badf446c58c2

Contents?: true

Size: 1.73 KB

Versions: 9

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true
class HomeController < ApplicationController
  def update
    return redirect_to(:back) unless is_admin

    # Update list of entities to synchronize
    current_organization.synchronized_entities.keys.each do |entity|
      current_organization.synchronized_entities[entity][:can_push_to_connec] = params[entity.to_s]["to_connec"] == "1"
      current_organization.synchronized_entities[entity][:can_push_to_external] = params[entity.to_s]["to_external"] == "1"
    end
    full_sync = params['historical-data'].present? && !current_organization.historical_data
    opts = {full_sync: full_sync}
    current_organization.sync_enabled = current_organization.synchronized_entities.values.any? { |settings| settings.values.any? { |v| v } }
    current_organization.enable_historical_data(params['historical-data'].present?)
    trigger_sync = current_organization.sync_enabled
    current_organization.save

    # Trigger sync only if the sync has been enabled
    start_synchronization(opts) if trigger_sync

    redirect_to(:back)
  end

  def synchronize
    return redirect_to(:back) unless is_admin
    Maestrano::Connector::Rails::SynchronizationJob.perform_later(current_organization.id, (params['opts'] || {}).merge(forced: true))
    flash[:info] = 'Synchronization requested'
    redirect_to(:back)
  end

  # Implement the redirection to the external application
  def redirect_to_external
    redirect_to 'https://path/to/external/app'
  end

  private

    def start_synchronization(opts)
      Maestrano::Connector::Rails::SynchronizationJob.perform_later(current_organization.id, opts)
      flash[:info] = 'Congrats, you\'re all set up! Your data are now being synced' if current_organization.sync_enabled_changed?
    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
maestrano-connector-rails-2.2.1 lib/generators/connector/templates/home_controller.rb
maestrano-connector-rails-2.2.0 lib/generators/connector/templates/home_controller.rb
maestrano-connector-rails-2.1.3 lib/generators/connector/templates/home_controller.rb
maestrano-connector-rails-2.1.2 lib/generators/connector/templates/home_controller.rb
maestrano-connector-rails-2.1.1 lib/generators/connector/templates/home_controller.rb
maestrano-connector-rails-2.1.0 lib/generators/connector/templates/home_controller.rb
maestrano-connector-rails-2.0.2.pre.RC12 lib/generators/connector/templates/home_controller.rb
maestrano-connector-rails-2.0.2.pre.RC11 lib/generators/connector/templates/home_controller.rb
maestrano-connector-rails-2.0.2.pre.RC10 lib/generators/connector/templates/home_controller.rb