Class: Decidim::SpamSignal::Admin::ApplicationCopsController

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

Direct Known Subclasses

CommentCopsController, ProfileCopsController

Instance Method Summary collapse

Instance Method Details

#createObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/decidim/spam_signal/admin/application_cops_controller.rb', line 65

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

#destroyObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/decidim/spam_signal/admin/application_cops_controller.rb', line 18

def destroy
  raise "Missing id" unless cop_type
  RemoveCopCommand.call(
    current_config,
    resource_config,
    cop_type
  ) do |on|
    on(:invalid) { flash[:alert] = "Can not remove the agent" }
    on(:ok) { flash[:notice] = "Remove has been removed"  }
    redirect_to spam_filter_reports_path
  end
end

#editObject



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

def edit
  @form = nil
  if current_cop && current_cop.form
    @form = current_cop.form.new(
      **(resource_config.cop_options(current_cop.handler_name, cop_type) || {})
    ).with_context(
      config: current_config,
      handler_name: current_cop.handler_name
    )
  elsif current_cop
    @form = Decidim::SpamSignal::NoSettingsForm.new.with_context(
      config: current_config,
      handler_name: current_cop.handler_name
    )
  end
end

#indexObject



11
12
13
14
15
16
# File 'app/controllers/decidim/spam_signal/admin/application_cops_controller.rb', line 11

def index
  output_symbols = scan_repository.strategies.map do |scan_name|
    scanKlass = scan_repository.strategy(scan_name)
    scanKlass.output_symbols
  end.flatten
end

#resource_configObject

Raises:



84
85
86
# File 'app/controllers/decidim/spam_signal/admin/application_cops_controller.rb', line 84

def resource_config
  raise Error, "Not implemented"
end

#updateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/decidim/spam_signal/admin/application_cops_controller.rb', line 31

def update
  raise "No agent found" unless current_cop
  form = current_cop.form.from_params(params.require("#{cop_key}")).with_context(
    handler_name: current_cop.handler_name,
    type: cop_type
  )
  UpdateCopCommand.call(
    current_config,
    resource_config,
    form
  ) do |on|
    on(:invalid) { flash[:alert] = "Can not update the agent" }
    on(:ok) { flash[:notice] = "Agent has been updated"  }
    redirect_to spam_filter_reports_path
  end
end