beetle_reporter 0.1.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 224576858692394234faa775751f23ebfa338a9aaabd4fd50330f60d87b38751
4
- data.tar.gz: 34afd7af8fa7c95315722dc50ee4110c5c8f1924a0bcf02aa334650fc3dc46b1
3
+ metadata.gz: c8c4ae7fc8b53cb021dece1af970833d533766605f1f8a93fb030186f5354a2a
4
+ data.tar.gz: e0ecb462118820163770227a8526c70826db2083fafada52e8f23737fbdb655b
5
5
  SHA512:
6
- metadata.gz: d3c6f2ce890632f07592eeedbe7a7a6d8dbea53d303b28325f931ed0ed4cf934f191c0c0bf0ccf48b60961476fbfc84063f70171cb31016610aaebe0c78117b4
7
- data.tar.gz: 667a1644f4244932806802bb813729d9a3569f4d43a8e0f961007ae87c269f2ac1b2638d485d110fc6a5974aea3e32f1c2c7073642162e27c30f3c39aea8b91c
6
+ metadata.gz: b61c8f8abbf0ec9b48ba55495b1d74c1b73b9ecd800a30d56e85e3c0b08155e47ec6bff73e260aad5fac83f09eb1cb46f1555bb52942ccc60c726b477dab70ff
7
+ data.tar.gz: 3261b751d9c67649c3abe72d0d8dbfb8a6dd08cb7f75f34f000203cec42b1b337f1af73a9ebc1199837616c6afce8642150f31ed5a6b658b60c0593611d2f73d
data/README.md CHANGED
@@ -76,8 +76,8 @@ class Diary
76
76
  true
77
77
  end
78
78
 
79
- def beetle_images
80
- pictures.map{|pic| {src: pic.full_url} }
79
+ def beetle_record_partial_path
80
+ "admins/diaries/beetle"
81
81
  end
82
82
  end
83
83
  ```
@@ -69,43 +69,65 @@ module BeetleReporter
69
69
  def ignore
70
70
  @report.ignore!
71
71
 
72
- redirect_to reports_url, notice: 'report was successfully ignored.'
72
+ respond_to do |format|
73
+ format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
74
+ format.html { redirect_to reports_url, notice: 'report was successfully ignored.' }
75
+ end
73
76
  end
74
77
 
75
78
  def suspend
76
79
  @report.suspend!
77
80
 
78
- redirect_to reports_url, notice: 'report was successfully ignored.'
81
+ respond_to do |format|
82
+ format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
83
+ format.html { redirect_to reports_url, notice: 'report was successfully suspended.' }
84
+ end
79
85
  end
80
86
 
81
87
  def hide
82
- @report.beetle_hide("fooobar hide")
88
+ @report.beetle_hide(params[:reason])
83
89
 
84
- redirect_to reports_url, notice: 'report was successfully hidden.'
90
+ respond_to do |format|
91
+ format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
92
+ format.html { redirect_to reports_url, notice: 'report was successfully hidden.' }
93
+ end
85
94
  end
86
95
 
87
96
  def remove
88
- @report.beetle_remove("fooobar remove")
97
+ @report.beetle_remove(params[:reason])
89
98
 
90
- redirect_to reports_url, notice: 'report was successfully removed.'
99
+ respond_to do |format|
100
+ format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
101
+ format.html { redirect_to reports_url, notice: 'report was successfully removed.' }
102
+ end
91
103
  end
92
104
 
93
105
  def mute
94
- @report.beetle_mute("fooobar mute")
106
+ # TODO: 禁言时间
107
+ @report.beetle_mute(params[:reason])
95
108
 
96
- redirect_to reports_url, notice: 'report was successfully muted.'
109
+ respond_to do |format|
110
+ format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
111
+ format.html { redirect_to reports_url, notice: 'report was successfully muted.' }
112
+ end
97
113
  end
98
114
 
99
115
  def forbid
100
- @report.beetle_forbid("fooobar forbid")
116
+ @report.beetle_forbid(params[:reason])
101
117
 
102
- redirect_to reports_url, notice: 'report was successfully forbiden.'
118
+ respond_to do |format|
119
+ format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
120
+ format.html { redirect_to reports_url, notice: 'report was successfully forbiden.' }
121
+ end
103
122
  end
104
123
 
105
124
  def undo
106
125
  @report.undo!
107
126
 
108
- redirect_to reports_url, notice: 'report was successfully ignored.'
127
+ respond_to do |format|
128
+ format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
129
+ format.html { redirect_to reports_url, notice: 'report was successfully undo.' }
130
+ end
109
131
  end
110
132
 
111
133
  private
@@ -113,11 +135,12 @@ module BeetleReporter
113
135
  def load_reports
114
136
  builder = report_scope.includes(:record)
115
137
  builder = builder.where("reason ilike ?", "%#{params[:q]}%") if params[:q].present?
138
+
116
139
  if params[:filter] != 'all'
117
140
  builder = builder.pending
118
141
  builder = builder.unscope(where: :aasm_state).where(aasm_state: params[:state]) if params[:state].present?
119
142
  end
120
- builder = builder.where(record_type: params[:type]&.classify) if params[:type]
143
+ builder = builder.where(record_type: params[:type]&.classify) if params[:type].present?
121
144
 
122
145
  builder = builder.order(id: :desc, reported_count: :desc)
123
146
  builder = builder.reorder(updated_at: :desc) if params[:order] == 'last_updated'
@@ -3,6 +3,8 @@ module BeetleReporter
3
3
  include AASM
4
4
  include Discard::Model
5
5
 
6
+ REASON_TYPES = %w(垃圾广告营销 侮辱谩骂内容 淫秽色情内容 涉政敏感信息 违法有害信息 内容令人不适 内容存在错误)
7
+
6
8
  belongs_to :record, polymorphic: true, required: false
7
9
  belongs_to :user, class_name: BeetleReporter.config.user_class, optional: true
8
10
 
@@ -60,16 +62,7 @@ module BeetleReporter
60
62
  return if record&.user.blank?
61
63
  raise NoMethodError unless record.respond_to?(:beetle_mute)
62
64
 
63
- ret = record.beetle_mute
64
- mute!(reason) if ret
65
- end
66
-
67
- def beetle_mute(reason)
68
- return if record.blank?
69
- return if record&.user.blank?
70
- raise NoMethodError unless record.respond_to?(:beetle_mute)
71
-
72
- ret = record.beetle_mute
65
+ ret = record.beetle_mute(reason)
73
66
  mute!(reason) if ret
74
67
  end
75
68
 
@@ -78,7 +71,7 @@ module BeetleReporter
78
71
  return if record&.user.blank?
79
72
  raise NoMethodError unless record.respond_to?(:beetle_forbid)
80
73
 
81
- ret = record.beetle_forbid
74
+ ret = record.beetle_forbid(reason)
82
75
  forbid!(reason) if ret
83
76
  end
84
77
 
@@ -88,6 +81,10 @@ module BeetleReporter
88
81
  record.beetle_record_path
89
82
  end
90
83
 
84
+ def record_partial_path
85
+ record.beetle_record_partial_path
86
+ end
87
+
91
88
  def undo_callback
92
89
  if hidden?
93
90
  ret = record.beetle_undo_hide
@@ -106,15 +103,6 @@ module BeetleReporter
106
103
  end
107
104
  end
108
105
 
109
- def images
110
- return [] if record.blank?
111
-
112
- raise NoMethodError, 'undefined beetle_images for record' unless record.respond_to?(:beetle_images)
113
-
114
- record.beetle_images
115
- end
116
-
117
-
118
106
  def set_reason(reason)
119
107
  update_columns(reason: reason)
120
108
  end
@@ -5,12 +5,15 @@
5
5
  - unless report.record.blank?
6
6
  = link_to report.record_path, data: { turbo: false }, target: "_blank" do
7
7
  %span{class: "bg-indigo-100 text-indigo-600 py-1 px-2 rounded-lg"}="#{report.record_type.upcase}##{report.record_id}"
8
- %span{class: "bg-yellow-100 text-yellow-600 rounded-md p-1"}=t("beetle_reporter.aasm_state.#{report.aasm_state}")
8
+ %span{class: "bg-yellow-100 text-yellow-600 rounded-md p-1"}=t("beetle_reporter.aasm_state.#{report.aasm_state}")
9
+ - unless report.reasons.blank?
10
+ - report.reasons.each do |reason|
11
+ %span{class: "border border-red-600 text-red-600 rounded-lg text-xs p-0.5"}= reason
9
12
  %span{class: "flex space-x-2 items-center text-sm"}
10
13
  - if report.reason
11
14
  %span{class: "bg-red-100 text-red-600 p-1 rounded-lg"}= "处置原因:#{report.reason}"
12
15
  %span{class: "space-x-1"}
13
- - report.user_ids.each do |uid|
16
+ - report.user_ids.compact.uniq.each do |uid|
14
17
  = link_to main_app.send(BeetleReporter.config.main_app_user_path_method.to_sym, uid), data: {turbo: false} do
15
18
  %span{class: "bg-blue-100 rounded-lg px-1 py-0.5"}= "#{uid}"
16
19
  %span{class: "bg-red-600 text-white rounded-full w-5 h-5 flex justify-center items-center"}= "#{report.reported_count}"
@@ -20,38 +23,33 @@
20
23
  = button_to '删除', report, method: :delete, data: { confirm: 'Are you sure?'}, class: "bg-red-600 text-white rounded-md px-2 py-0.5 cursor-pointer"
21
24
  %div{class: "flex justify-between items-center py-2 w-full"}
22
25
  %div{class: "flex flex-col rounded-lg bg-gray-50 p-3 text-sm space-y-4 w-full"}
23
- -unless report.record
24
- %h3{class: "text-2xl text-red-600"} 对应条目已被永久删除,当前审核请求已无效,请删除
26
+ - unless report.record
27
+ %h3{class: "text-2xl text-red-600 flex items-center"}
28
+ 对应条目已被永久删除,当前审核请求已无效
29
+ =button_to "点我删除", report, method: :delete, class: "ml-2 bg-yellow-500 text-white rounded-lg px-2 py-0.5 cursor-pointer"
25
30
  - else
26
- %div
27
- %span{class: "#{report.record.is_private ? 'bg-black text-white' : 'border border-black text-black' } rounded-lg text-xs p-0.5 px-1"}=report.record.is_private ? "🙈 隐私" : "🙉 公开"
28
- %span{class: "border border-blue-600 text-blue-600 rounded-lg text-xs p-0.5"}=report.record.is_approved ? "审核通过" : "审核中..."
29
- - unless report.reasons.blank?
30
- - report.reasons.each do |reason|
31
- %span{class: "border border-red-600 text-red-600 rounded-lg text-xs p-0.5"}= reason
32
- - unless report&.record&.user_id&.blank?
33
- = link_to main_app.send(CensorBear.config.main_app_user_path_method.to_sym, report.record.user_id), data: {turbo: false} do
34
- %span{class: "text-sm bg-gray-100 text-gray-600 py-1 px-2 rounded-lg font-bold"}="✍️ ##{report.record.user_id}"
35
- - if report.record.discarded?
36
- %div{class: "text-gray-900 leading-relaxed"}
37
- %del= report.record.content
38
- - else
39
- %div{class: "text-gray-900 leading-relaxed"}= report.record.content
40
- %div
41
- - report.images.each do |img|
42
- = image_tag img[:src], class: "w-16 rounded-md"
43
- %div{class: "flex space-x-2 items-center justify-end"}
31
+ = render report.record_partial_path, record: report.record
32
+ %div{class: "flex flex-col space-y-2"}
44
33
  - if report.may_ignore?
45
- = link_to "忽略", report_ignore_path(report), class: "text-yellow-600 cursor-pointer"
34
+ = button_to "无效举报", report_ignore_path(report), class: "text-yellow-600 cursor-pointer px-2 py-0.5 bg-gray-100 rounded-lg"
35
+ - if report.may_suspend?
36
+ = button_to "暂缓处理", report_suspend_path(report), class: "text-indigo-600 cursor-pointer px-2 py-0.5 bg-gray-100 rounded-lg"
37
+ - if report.may_undo?
38
+ = button_to "撤销", report_undo_path(report), class: "text-red-600 cursor-pointer px-2 py-0.5 bg-gray-100 rounded-lg"
46
39
  - if report.may_hide?
47
- = link_to "隐藏内容", report_hide_path(report), class: "text-purple-600 cursor-pointer"
40
+ = form_with(url: report_hide_path(report), class: "space-x-1 flex items-center") do |f|
41
+ = f.text_field :reason, value: report.reason, placeholder: "隐藏原因是什么?", class: "border rounded-md m py-0.5 px-1"
42
+ = f.submit "隐藏内容", class: "bg-red-500 text-white cursor-pointer px-2 py-0.5 bg-gray-100 rounded-lg"
48
43
  - if report.may_remove?
49
- = link_to "删除内容", report_remove_path(report), class: "text-red-800 cursor-pointer"
44
+ = form_with(url: report_remove_path(report), class: "space-x-1 flex items-center") do |f|
45
+ = f.text_field :reason, value: report.reason, placeholder: "删除原因是什么?", class: "border rounded-md m py-0.5 px-1"
46
+ = f.submit "删除内容", class: "bg-red-600 text-white cursor-pointer px-2 py-0.5 bg-gray-100 rounded-lg"
50
47
  - if report.may_mute?
51
- = link_to "禁言用户", report_mute_path(report), class: "text-red-600 cursor-pointer"
48
+ = form_with(url: report_mute_path(report), class: "space-x-1 flex items-center") do |f|
49
+ -# = f.text_field :mute_days, value: report.mute_days, placeholder: "禁言天数", class: "border rounded-md m py-0.5 px-1"
50
+ = f.text_field :reason, value: report.reason, placeholder: "禁言原因是什么?", class: "border rounded-md m py-0.5 px-1"
51
+ = f.submit "禁言用户", class: "bg-red-700 text-white cursor-pointer px-2 py-0.5 bg-gray-100 rounded-lg"
52
52
  - if report.may_forbid?
53
- = link_to "封禁用户",report_forbid_path(report), class: "text-red-700 cursor-pointer"
54
- - if report.may_suspend?
55
- = link_to "暂缓处理", report_suspend_path(report), class: "text-indigo-600 cursor-pointer"
56
- - if report.may_undo?
57
- = link_to "撤销", report_undo_path(report), class: "text-red-600 cursor-pointer"
53
+ = form_with(url: report_forbid_path(report), class: "space-x-1 flex items-center") do |f|
54
+ = f.text_field :reason, value: report.reason, placeholder: "封禁原因是什么?", class: "border rounded-md m py-0.5 px-1"
55
+ = f.submit "封禁用户", class: "bg-red-800 text-white cursor-pointer px-2 py-0.5 bg-gray-100 rounded-lg"
data/config/routes.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  BeetleReporter::Engine.routes.draw do
2
2
  resources :reports do
3
- get :ignore
4
- get :suspend
5
- get :undo
6
- get :hide
7
- get :remove
8
- get :mute
9
- get :forbid
3
+ post :ignore
4
+ post :undo
5
+ post :suspend
6
+ post :hide
7
+ post :remove
8
+ post :mute
9
+ post :forbid
10
10
  end
11
11
 
12
12
  root "reports#index"
@@ -1,3 +1,3 @@
1
1
  module BeetleReporter
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -28,7 +28,7 @@ module BeetleReporter
28
28
  end
29
29
 
30
30
  def add(record, user_id, reason)
31
- report = BeetleReporter::Report.find_by(record: record)
31
+ report = BeetleReporter::Report.pending.kept.find_by(record: record)
32
32
  if report
33
33
  report.user_ids << user_id unless report.user_ids.include?(user_id)
34
34
  report.reasons << reason unless report.reasons.include?(reason)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beetle_reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - 42up
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-17 00:00:00.000000000 Z
11
+ date: 2021-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails