Class: Decidim::SpamSignal::Admin::ApplicationRulesController
- Inherits:
-
ApplicationController
- Object
- Admin::ApplicationController
- ApplicationController
- Decidim::SpamSignal::Admin::ApplicationRulesController
show all
- Includes:
- FormFactory
- Defined in:
- app/controllers/decidim/spam_signal/admin/application_rules_controller.rb
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/decidim/spam_signal/admin/application_rules_controller.rb', line 57
def create
unless params["rules"]
flash[:alert] = "Can not add empty rules"
return redirect_to spam_filter_reports_path
end
rule = params.require(:rules)
rule_id = rule.keys.first
raise "No rule_id given" unless rule_id
form = RuleForm.from_params(rules: rule.require(rule_id).permit!.to_h).with_context(handler_name: rule_type)
AddRuleCommand.call(
current_config,
resource_config,
form,
rule_id
) do |on|
on(:invalid) { |e| flash[:alert] = "Can not add the rule" }
on(:ok) { flash[:notice] = "Rule has been added" }
redirect_to spam_filter_reports_path
end
end
|
#destroy ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/decidim/spam_signal/admin/application_rules_controller.rb', line 44
def destroy
raise "No rule found" unless current_rule
RemoveRuleCommand.call(
current_config,
resource_config,
current_rule
) do |on|
on(:invalid) { flash[:alert] = "error on deleting rule" }
on(:ok) { flash[:notice] = "rule have been removed" }
end
redirect_to spam_filter_reports_path
end
|
#edit ⇒ Object
39
40
41
42
|
# File 'app/controllers/decidim/spam_signal/admin/application_rules_controller.rb', line 39
def edit
rule = resource_config.rule(current_rule)
@form = RuleForm.from_params(rules: rule["rules"]).with_context(handler_name: rule["handler_name"], id: current_rule)
end
|
#new ⇒ Object
13
14
15
|
# File 'app/controllers/decidim/spam_signal/admin/application_rules_controller.rb', line 13
def new
@form = RuleForm.new.with_context(handler_name: rule_type)
end
|
#resource_config ⇒ Object
78
79
80
|
# File 'app/controllers/decidim/spam_signal/admin/application_rules_controller.rb', line 78
def resource_config
raise Error, "Not implemented"
end
|
#update ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/decidim/spam_signal/admin/application_rules_controller.rb', line 17
def update
unless params["rules"]
flash[:alert] = "Can not empty a rule, delete it instead"
return redirect_to spam_filter_reports_path
end
rule = params.require(:rules)
rule_id = rule.keys.first
raise "No rule_id given" unless rule_id
prev_rule = resource_config.rule(rule_id)
form = RuleForm.from_params(rules: rule.require(rule_id).permit!.to_h).with_context(handler_name: prev_rule["handler_name"])
UpdateRuleCommand.call(
current_config,
resource_config,
form,
rule_id
) do |on|
on(:invalid) { |e| flash[:alert] = "Can not update the rule" }
on(:ok) { flash[:notice] = "Rule has been updated" }
redirect_to spam_filter_reports_path
end
end
|