Class: DataMigration::MigrationPlansController

Inherits:
ApplicationController show all
Includes:
PunditAuthorization
Defined in:
app/controllers/data_migration/migration_plans_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 22

def create
  @migration_plan = MigrationPlan.new(migration_plan_params)
  @migration_plan.user = current_user
  authorize @migration_plan

  if @migration_plan.save
    redirect_to "/data_migration/migration_plans/#{@migration_plan.id}",
                notice: 'Migration plan was successfully created.'
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 50

def destroy
  authorize @migration_plan

  if @migration_plan.destroy
    redirect_to '/data_migration/migration_plans', notice: 'Migration plan was successfully destroyed.'
  else
    redirect_to "/data_migration/migration_plans/#{@migration_plan.id}",
                alert: 'Cannot delete migration plan with existing executions.'
  end
end

#editObject



35
36
37
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 35

def edit
  authorize @migration_plan
end

#export_configObject



61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 61

def export_config
  authorize @migration_plan

  service = MigrationPlans::ExportConfigService.new(@migration_plan)
  json_config = service.call

  send_data json_config,
            filename: "#{@migration_plan.name.parameterize}_config.json",
            type: 'application/json',
            disposition: 'attachment'
end

#import_configObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 73

def import_config
  authorize MigrationPlan.new

  unless params[:config_file].present?
    redirect_to '/data_migration/migration_plans', alert: 'Please select a configuration file to import.'
    return
  end

  config_json = params[:config_file].read
  service = MigrationPlans::ImportConfigService.new(config_json, current_user)

  imported_plan = service.call

  if service.success? && imported_plan
    redirect_to "/data_migration/migration_plans/#{imported_plan.id}",
                notice: 'Migration plan configuration imported successfully!'
  else
    redirect_to '/data_migration/migration_plans', alert: "Import failed: #{service.errors.join(', ')}"
  end
end

#indexObject



9
10
11
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 9

def index
  @migration_plans = policy_scope(MigrationPlan).ordered_by_name
end

#newObject



17
18
19
20
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 17

def new
  @migration_plan = MigrationPlan.new
  authorize @migration_plan
end

#showObject



13
14
15
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 13

def show
  authorize @migration_plan
end

#updateObject



39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 39

def update
  authorize @migration_plan

  if @migration_plan.update(migration_plan_params)
    redirect_to "/data_migration/migration_plans/#{@migration_plan.id}",
                notice: 'Migration plan was successfully updated.'
  else
    render :edit, status: :unprocessable_entity
  end
end