Module: Maestrano::Concerns::SynchronizationsController

Extended by:
ActiveSupport::Concern
Included in:
SynchronizationsController
Defined in:
app/controllers/maestrano/concerns/synchronizations_controller.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#createObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/maestrano/concerns/synchronizations_controller.rb', line 37

def create
  tenant = params[:tenant]
  uid = params[:group_id]
  opts = params[:opts] || {}
  organization = Maestrano::Connector::Rails::Organization.find_by(uid: uid, tenant: tenant)
  return render json: {errors: [{message: 'Organization not found', code: 404}]}, status: :not_found unless organization

  organization.sync_enabled = organization.synchronized_entities.values.any? { |settings| settings.values.any? { |v| v } }
  organization.save if organization.sync_enabled_changed?

  status = organization_status(organization)

  unless %w[RUNNING ENQUEUED].include?(status)
    Maestrano::Connector::Rails::SynchronizationJob.perform_later(organization.id, opts.with_indifferent_access)
    status = 'ENQUEUED'
  end

  render_organization_sync(organization, status, 201)
end

#showObject

Instance methods



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/maestrano/concerns/synchronizations_controller.rb', line 26

def show
  tenant = params[:tenant]
  uid = params[:id]
  organization = Maestrano::Connector::Rails::Organization.find_by(uid: uid, tenant: tenant)
  return render json: {errors: [{message: 'Organization not found', code: 404}]}, status: :not_found unless organization

  status = organization_status organization

  render_organization_sync(organization, status, 200)
end

#toggle_syncObject



68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/maestrano/concerns/synchronizations_controller.rb', line 68

def toggle_sync
  tenant = params[:tenant]
  uid = params[:group_id]
  organization = Maestrano::Connector::Rails::Organization.find_by(uid: uid, tenant: tenant)
  return render json: {errors: [{message: 'Organization not found', code: 404}]}, status: :not_found unless organization

  organization.toggle(:sync_enabled)
  organization.save
  status = organization_status organization
  render_organization_sync(organization, status, 200)
end

#update_metadataObject



57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/maestrano/concerns/synchronizations_controller.rb', line 57

def 
  tenant = params[:tenant]
  uid = params[:group_id]
  organization = Maestrano::Connector::Rails::Organization.find_by(uid: uid, tenant: tenant)
  return render json: {errors: [{message: 'Organization not found', code: 404}]}, status: :not_found unless organization

  organization.
  organization.reset_synchronized_entities
  render_organization_sync(organization, status, 200)
end