-
-
Notifications
You must be signed in to change notification settings - Fork 392
/
report_button_cell.rb
82 lines (63 loc) · 2.02 KB
/
report_button_cell.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true
module Decidim
class ReportButtonCell < ButtonCell
include ActionView::Helpers::FormOptionsHelper
def flag_modal
return render :already_reported_modal if model.reported_by?(current_user)
render
end
def frontend_administrable?
return true if user_reportable? && current_user&.admin?
user_entity? &&
model.can_be_administered_by?(current_user) &&
(model.respond_to?(:official?) && !model.official?)
end
private
def user_entity?
(model.respond_to?(:creator_author) && model.creator_author.respond_to?(:nickname)) ||
(model.respond_to?(:author) && model.author.respond_to?(:nickname))
end
def hide_checkbox_id
@hide_checkbox_id ||= Digest::MD5.hexdigest("report_form_hide_#{model.class.name}_#{model.id}")
end
def cache_hash
hash = []
hash.push(I18n.locale)
hash.push(current_user.try(:id))
hash.push(model.reported_by?(current_user) ? 1 : 0)
hash.push(model.class.name.gsub("::", ":"))
hash.push(model.id)
hash.join(Decidim.cache_key_separator)
end
def only_button?
options[:only_button]
end
def modal_id
options[:modal_id] || "flagModal"
end
def user_reportable?
model.is_a?(Decidim::UserReportable)
end
def report_form
@report_form ||= user_reportable? ? Decidim::ReportForm.from_params(reason: "spam") : Decidim::ReportForm.new(reason: "spam")
end
def report_path
@report_path ||= user_reportable? ? decidim.report_user_path(sgid: model.to_sgid.to_s) : decidim.report_path(sgid: model.to_sgid.to_s)
end
def builder
Decidim::FormBuilder
end
def button_classes
options[:button_classes] || "button button__sm button__text button__text-secondary"
end
def text
t("decidim.shared.flag_modal.report")
end
def icon_name
"flag-line"
end
def html_options
{ data: { "dialog-open": current_user ? modal_id : "loginModal" } }
end
end
end