Class: Decidim::SpamSignal::Admin::ApplicationScansController

Inherits:
ApplicationController
  • Object
show all
Includes:
FormFactory
Defined in:
app/controllers/decidim/spam_signal/admin/application_scans_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/decidim/spam_signal/admin/application_scans_controller.rb', line 61

def create
  raise "No scanner found" unless current_scanner
  form = current_scanner.form.from_params(params.require("#{scan_key}")).with_context(handler_name: current_scanner.handler_name)
  AddScannerCommand.call(
    current_config,
    resource_config,
    form
  ) do |on|
    on(:invalid) { flash[:alert] = "Can not create the scanner" }
    on(:ok) { flash[:notice] = "Scanner has been created"  }
    redirect_to spam_filter_reports_path
  end
end

#destroyObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/decidim/spam_signal/admin/application_scans_controller.rb', line 48

def destroy
  raise "No scanner found" unless current_scanner
  RemoveScannerCommand.call(
    current_config,
    resource_config,
    current_scanner.handler_name
  ) do |on|
    on(:invalid) { flash[:alert] = "error on deleting #{current_scanner.handler_name} scanner" }
    on(:ok) { flash[:notice] = "#{current_scanner.handler_name} scanner have been removed" }
  end
  redirect_to spam_filter_reports_path
end

#editObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/decidim/spam_signal/admin/application_scans_controller.rb', line 38

def edit
  raise "No scanner found" unless current_scanner
  @form = current_scanner.form.new(
    **(resource_config.scan_options(current_scanner.handler_name) || {})
  ).with_context(
    config: current_config,
    handler_name: current_scanner.handler_name
  )
end

#newObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/decidim/spam_signal/admin/application_scans_controller.rb', line 12

def new
  @form = nil
  if current_scanner && current_scanner.form
    @form = current_scanner.form.new(
      **(resource_config.scan_options(current_scanner.handler_name) || {})
    ).with_context(
      config: current_config,
      handler_name: current_scanner.handler_name
    )
  end
end

#resource_configObject

Raises:



74
75
76
# File 'app/controllers/decidim/spam_signal/admin/application_scans_controller.rb', line 74

def resource_config
  raise Error, "Not implemented"
end

#updateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/decidim/spam_signal/admin/application_scans_controller.rb', line 24

def update
  raise "No scanner found" unless current_scanner
  form = current_scanner.form.from_params(params.require("#{scan_key}".to_sym)).with_context(handler_name: current_scanner.handler_name)
  UpdateScannerCommand.call(
    current_config,
    resource_config,
    form
  ) do |on|
    on(:invalid) { flash[:alert] = "Can not update the scanner" }
    on(:ok) { flash[:notice] = "Scanner has been updated"  }
    redirect_to spam_filter_reports_path
  end
end