censor_bear 0.1.15 → 0.1.17

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: 775cd9c238b951f9b9d5ce8564ae76e3e4b5d38fb3e9b71dc599d6a75bc04f5e
4
- data.tar.gz: f8daa1001d2682697143aec92e6098d1e291d3c4d8cb7c9d28f60455fee7e6b4
3
+ metadata.gz: da82f8fafa1a258c9009099fc66621805e19ac0750662f92153eb3a1a8ba5b01
4
+ data.tar.gz: 4a51f1c4260ba69397dfc583093fb59417ba0f9b95b458243d2b28ec58087454
5
5
  SHA512:
6
- metadata.gz: 3bd8ea39fb05994a01083fdaf574501657bf085238a1c9a24b883bddadf374a8a441f910a95594f7a42081d981a2800b9b2b02c9b3cc578e200536faa52ed4b8
7
- data.tar.gz: 6ee79015b14bf37b4f070e041c91738d906bb3d1f8c39b215a94ccf6fbe89ccc0816a9d919e1436ee3689b3bb62bd9be2df1a025afbe1090e09ee9bf0be1022d
6
+ metadata.gz: 0fed9c06844c55e4fca2c9d997d8f7af7a1bb04c33c0cc73f7fe1d1cbf4c1f0bce029a239f058a0eda4bd8bd11c9b670ad4019d8f3d75e9916d00f8d66a6ddf2
7
+ data.tar.gz: 11a70e93051a636a39240dd09327ef38778c82fc22af53b325e28e1635036de93f9ab85ab4b66d6cc8e78d1c04ae6b74ad31b7fa31ee5a958a75b9ac09dcccb7
@@ -52,6 +52,23 @@ module CensorBear
52
52
  end
53
53
  end
54
54
 
55
+ def remove_data
56
+ builder = log_scope
57
+ case params[:type]
58
+ when '3days'
59
+ builder = builder.where("created_at >= ?", (Time.now - 3.days).beginning_of_day)
60
+ when '7days'
61
+ builder = builder.where("created_at >= ?", (Time.now - 7.days).beginning_of_day)
62
+ when '30days'
63
+ builder = builder.where("created_at >= ?", (Time.now - 30.days).beginning_of_day)
64
+ when 'all'
65
+ builder
66
+ end
67
+ builder.delete_all
68
+
69
+ redirect_to logs_url, notice: "Mod log was successfully destroyed."
70
+ end
71
+
55
72
  def load_logs
56
73
  builder ||= log_scope
57
74
  builder = builder.where("original_content ilike ?", "%#{params[:q]}%") if params[:q].present?
@@ -45,7 +45,6 @@ module CensorBear
45
45
  end
46
46
  end
47
47
 
48
-
49
48
  def suspend
50
49
  @mod_log.suspend!
51
50
 
@@ -59,8 +58,11 @@ module CensorBear
59
58
  end
60
59
 
61
60
  def undo
62
- # TODO: 判断状态,确定是撤销通过呢还是撤销删除
63
- @mod_log.cancel
61
+ if @mod_log.passed?
62
+ @mod_log.undo_approve
63
+ elsif @mod_log.rejected?
64
+ @mod_log.undo_remove
65
+ end
64
66
 
65
67
  redirect_to mod_logs_url, notice: 'Mod log was successfully ignored.'
66
68
  end
@@ -5,6 +5,16 @@ module CensorBear
5
5
  REASONS = %w(无 广告/SPAM 恶意灌水 违规内容 文不对题 重复发布 其它).freeze
6
6
  belongs_to :record, polymorphic: true, required: false
7
7
 
8
+ validates :record_id, uniqueness: { scope: [:record_type] }
9
+
10
+ def images
11
+ return [] if record.blank?
12
+
13
+ raise NoMethodError, 'undefined censor_images for record' unless record.respond_to?(:censor_images)
14
+
15
+ record.censor_images
16
+ end
17
+
8
18
  def record_path
9
19
  return '#' if record.blank?
10
20
 
@@ -21,6 +31,14 @@ module CensorBear
21
31
  reject!(reason) if ret
22
32
  end
23
33
 
34
+ def undo_remove
35
+ return if record.blank?
36
+ raise NoMethodError unless record.respond_to?(:censor_undo_remove)
37
+
38
+ ret = record.censor_undo_remove
39
+ undo! if ret
40
+ end
41
+
24
42
  def approve
25
43
  return if record.blank?
26
44
  raise NoMethodError unless record.respond_to?(:censor_approve)
@@ -29,11 +47,11 @@ module CensorBear
29
47
  pass! if ret
30
48
  end
31
49
 
32
- def cancel
50
+ def undo_approve
33
51
  return if record.blank?
34
- raise NoMethodError unless record.respond_to?(:censor_cancel)
52
+ raise NoMethodError unless record.respond_to?(:censor_undo_approve)
35
53
 
36
- ret = record.censor_cancel
54
+ ret = record.censor_undo_approve
37
55
  undo! if ret
38
56
  end
39
57
 
@@ -2,7 +2,7 @@
2
2
  %h2{class: "text-xl font-medium text-center"} 在线调试
3
3
  %div{class: "flex justify-center"}
4
4
  = form_with(url: debug_path, method: :post, class: "flex flex-col items-center w-full space-y-4") do |f|
5
- = f.select :stage, options_for_select([%w[check_text check_text], %w[check_search check_search], %w[check_search check_search], %w[qq_regex qq_regex], %w[wx_regex wx_regex]], params[:stage]), {}, class: "border rounded-md m py-0.5 px-1"
5
+ = f.select :stage, options_for_select([%w[check_text check_text], %w[aliyun_check aliyun_check], %w[check_search check_search], %w[qq_regex qq_regex], %w[wx_regex wx_regex]], params[:stage]), {}, class: "border rounded-md m py-0.5 px-1"
6
6
  = f.select :type, options_for_select(CensorBear::StopWord::FIELDS.map{|f| [f.upcase, f]}, params[:type]), {}, class: "border rounded-md m py-0.5 px-1"
7
7
  = f.text_area :content, value: params[:content], placeholder: "输入正文", rows: 6, class: "bg-gray-100 rounded-lg p-4 w-full"
8
8
  = f.submit "检测", class: "rounded-lg px-10 py-1 bg-black text-white cursor-pointer"
@@ -4,11 +4,15 @@
4
4
  = form_with(url: logs_path, method: :get, class: "flex items-center") do |f|
5
5
  %div{class: "space-x-0.5"}
6
6
  = f.text_field :q, value: params[:q], placeholder: "关键词", class: "border rounded-md m py-0.5 px-1"
7
- = f.select :stage, options_for_select([%w[aliyun_check aliyun_check], %w[aliyun_check aliyun_check], %w[qq_regex qq_regex], %w[wx_regex wx_regex], %w[local_check local_check]], params[:stage]), {include_blank: "-- 按Stage筛选 --"}, class: "border rounded-md m py-0.5 px-1"
7
+ = f.select :stage, options_for_select([%w[aliyun_check aliyun_check], %w[check_search check_search], %w[qq_regex qq_regex], %w[wx_regex wx_regex], %w[local_check local_check]], params[:stage]), {include_blank: "-- 按Stage筛选 --"}, class: "border rounded-md m py-0.5 px-1"
8
8
  = f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
9
9
  = link_to "重置", logs_path, class: "text-sm"
10
10
 
11
- %div{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
11
+ %div{class: "flex space-x-2 items-center"}
12
+ %div{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
13
+ = form_with(url: remove_data_logs_path, method: :delete, class: "flex items-center space-x-2") do |f|
14
+ = f.select :type, options_for_select([%w[最近3天 3days], %w[最近7天 7days], %w[最近30天 30days], %w[全部 all]], params[:type]), {include_blank: "-- 选择删除范围 --"}, class: "border text-red-600 border-red-600 rounded-md m py-0.5 px-1"
15
+ = f.submit "删除日志", class: "rounded-md px-2 py-1 text-xs bg-red-600 text-white cursor-pointer"
12
16
  %div
13
17
  - if @logs.blank?
14
18
  %div{class: "flex justify-center text-gray-500 p-8 border rounded-md"} 空空如也
@@ -21,21 +21,20 @@
21
21
  %div
22
22
  %span{class: "border border-pink-600 text-pink-600 rounded-lg text-xs p-0.5"}=mod_log.record.is_private ? "隐私" : "公开"
23
23
  %span{class: "border border-blue-600 text-blue-600 rounded-lg text-xs p-0.5"}=mod_log.record.is_approved ? "审核通过" : "审核中..."
24
+ - unless mod_log.labels.blank?
25
+ - mod_log.labels.each do |label|
26
+ %span{class: "border border-yellow-600 text-yellow-600 rounded-lg text-xs p-0.5"}=t("censor_log.label.#{label}")
27
+ - unless mod_log.mod_words.blank?
28
+ - mod_log.mod_words.each do |word|
29
+ %span{class: "border border-red-600 text-red-600 rounded-lg text-xs p-0.5"}="##{word}"
24
30
  - if mod_log.record.discarded?
25
31
  %div{class: "text-gray-900 leading-relaxed"}
26
32
  %del= mod_log.record.content
27
33
  - else
28
34
  %div{class: "text-gray-900 leading-relaxed"}= mod_log.record.content
29
35
  %div
30
- - mod_log.record.pictures.each do |pic|
31
- = image_tag pic.full_url, class: "w-16 rounded-md"
32
- %div
33
- - unless mod_log.labels.blank?
34
- - mod_log.labels.each do |label|
35
- %span{class: "text-xs bg-gray-200 text-gray-600 py-0.5 px-1 rounded-lg"}=t("censor_log.label.#{label}")
36
- - unless mod_log.mod_words.blank?
37
- - mod_log.mod_words.each do |word|
38
- %span{class: "text-sm bg-gray-100 text-gray-600 py-0.5 px-1 rounded-lg"}="##{word}"
36
+ - mod_log.images.each do |img|
37
+ = image_tag img[:src], class: "w-16 rounded-md"
39
38
  %div{class: "flex space-x-2 items-center justify-end"}
40
39
  - if mod_log.may_suspend?
41
40
  = link_to "忽略", mod_log_suspend_path(mod_log), class: "text-yellow-600 cursor-pointer"
@@ -1,4 +1,4 @@
1
- en:
1
+ "zh-CN":
2
2
  censor_log:
3
3
  action:
4
4
  mod: 审核
@@ -31,4 +31,4 @@ en:
31
31
  contraband: 违禁
32
32
  meaningless: 无意义
33
33
  harmful: 不良场景
34
- customized: 自定义
34
+ customized: 自定义
data/config/routes.rb CHANGED
@@ -6,7 +6,9 @@ CensorBear::Engine.routes.draw do
6
6
  get :undo
7
7
  get :ban
8
8
  end
9
- resources :logs
9
+ resources :logs do
10
+ delete :remove_data, on: :collection
11
+ end
10
12
  resources :stop_words
11
13
 
12
14
  get '/welcome', to: 'home#index'
@@ -6,7 +6,6 @@ class CreateCensorBearModLogs < ActiveRecord::Migration[6.1]
6
6
  t.text :content
7
7
  t.string :reason
8
8
  t.string :mod_words, array: true, default: []
9
- t.integer :status, default: 0
10
9
  t.bigint :user_id
11
10
 
12
11
  t.timestamps
@@ -115,17 +115,19 @@ module CensorBear
115
115
  rate = r['rate']
116
116
  @mod_words = concat_words(r['details'])
117
117
  @labels = concat_labels(r['details'])
118
- if action == 'block' && rate >= 70 && %w[politics terrorism].include?(r['label'])
119
- CensorBear.info(
120
- d['content'], @type, 'banned', 'aliyun_check',
121
- filtered_content: d['filteredContent'],
122
- mod_words: @mod_words,
123
- labels: @labels,
124
- ip: @ip, user_id: @user_id,
125
- response: response
126
- )
127
- raise NotPassedException
128
- elsif action == 'block' && rate >= 90
118
+ # if action == 'block' && rate >= 70 && %w[politics terrorism].include?(r['label'])
119
+ # @is_mod = true
120
+ # CensorBear.info(
121
+ # d['content'], @type, 'mod', 'aliyun_check',
122
+ # filtered_content: d['filteredContent'],
123
+ # mod_words: @mod_words,
124
+ # labels: @labels,
125
+ # ip: @ip, user_id: @user_id,
126
+ # response: response
127
+ # )
128
+ # # raise NotPassedException
129
+ # elsif action == 'block' && rate >= 90
130
+ if action == 'block'
129
131
  @is_mod = true
130
132
  CensorBear.info(
131
133
  d['content'], @type, 'mod', 'aliyun_check',
@@ -1,3 +1,3 @@
1
1
  module CensorBear
2
- VERSION = '0.1.15'.freeze
2
+ VERSION = '0.1.17'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: censor_bear
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.17
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-09 00:00:00.000000000 Z
11
+ date: 2021-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails