censor_bear 0.1.9 → 0.1.13

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: 995b08638f4f34912cf688f3e0bf2ca6989766119595d8bd84ae98c9daf85409
4
- data.tar.gz: f7be07a68fe5aeefe1ef4f9da1cbc589fca9a42d110e7ba992d5b5a75038eee1
3
+ metadata.gz: a3bf3dd6d88b6f7ece7434deabf56aa6322c305536e44d5ead4bae5c1aa94111
4
+ data.tar.gz: 9484d90389880990a519229d851394f7a484455972316f90f3d9891dda32851d
5
5
  SHA512:
6
- metadata.gz: b0e1a136b46f06f977b400925cfa351ac2aa10f9ca546662cc5f9d5c6c69089b4b38f456b72aa76aec0dbe8f8affcbdd48dcf29a49db6f43fc05f3d3375ae164
7
- data.tar.gz: 67abd4a402d55b81ae48e8942ecbef814c30f56f02f2da97c287ad5cacc7b612078461b3919f429d8e700d9ef56fa317882abec4aa9b71e8985c5e2b10016b7a
6
+ metadata.gz: e283297831488e216fe57089166d37084725ef93a387ea615d6897298d95616b181880af06c19e1ce3caf536ac29bdaedf1a25408f7392719390da40d721be8d
7
+ data.tar.gz: 11568a082cc47a024aecb4bd7a2b1f09e785b7690e88bba1bb6acb5445b7eb31ac4f4834f4a63c5429fe8a2c1c40ae6e6c72c21efd130903d3cdb4df81a25d16
@@ -79,7 +79,7 @@ module CensorBear
79
79
  end
80
80
 
81
81
  def load_mod_logs
82
- builder ||= mod_log_scope
82
+ builder ||= mod_log_scope.includes(:record)
83
83
  builder = builder.where("content ilike ?", "%#{params[:q]}%") if params[:q].present?
84
84
 
85
85
  builder = builder.order(id: :desc)
@@ -1,4 +1,4 @@
1
- require_dependency "censor_bear/application_controller"
1
+ require_dependency 'censor_bear/application_controller'
2
2
 
3
3
  module CensorBear
4
4
  class StopWordsController < ApplicationController
@@ -46,7 +46,16 @@ module CensorBear
46
46
 
47
47
  def load_stop_words
48
48
  builder ||= stop_word_scope
49
- builder = builder.where("key ilike ?", "%#{params[:q]}%") if params[:q].present?
49
+ builder = builder.where('key ilike ?', "%#{params[:q]}%") if params[:q].present?
50
+ case params[:filter]
51
+ when 'size_one'
52
+ builder = builder.where('length(key) = 1')
53
+ when 'size_two'
54
+ builder = builder.where('length(key) = 2')
55
+ when 'size_three'
56
+ builder = builder.where('length(key) = 3')
57
+ end
58
+ builder = builder.where('key ilike ?', "%#{params[:q]}%")
50
59
  builder = builder.order(id: :desc)
51
60
 
52
61
  @pagy, @stop_words = pagy(builder)
@@ -10,6 +10,8 @@ module CensorBear
10
10
  end
11
11
 
12
12
  def delete(reason)
13
+ return if record.blank?
14
+ return if record.discarded?
13
15
  # ugc内容需要开软删,便于撤销&查看统计,可以定时删除统计并删除软删内容,类似回收站机制
14
16
  raise NoMethodError.new("undefined censor_delete for record") unless record.respond_to?(:censor_delete)
15
17
 
@@ -18,6 +20,7 @@ module CensorBear
18
20
  end
19
21
 
20
22
  def approve
23
+ return if record.blank?
21
24
  raise NoMethodError unless record.respond_to?(:censor_approve)
22
25
 
23
26
  ret = record.censor_approve
@@ -25,6 +28,7 @@ module CensorBear
25
28
  end
26
29
 
27
30
  def ban_user
31
+ return if record.blank?
28
32
  raise NoMethodError unless record.respond_to?(:censor_ban_user)
29
33
 
30
34
  ret = record.censor_ban_user
@@ -16,7 +16,6 @@
16
16
  - unless log.labels.blank?
17
17
  - log.labels.each do |label|
18
18
  %span{class: "text-sm bg-red-100 text-red-600 py-1 px-2 rounded-lg"}=t("censor_log.label.#{label}")
19
-
20
19
  %span{class: "text-sm bg-gray-100 text-gray-600 py-1 px-2 rounded-lg"}= log.created_at
21
20
  %div{class: "flex space-x-2 items-center"}
22
21
  %span
@@ -33,5 +32,5 @@
33
32
  %div{class: "text-yellow-500 font-meidum text-xl"}
34
33
  - log.mod_words.each do |word|
35
34
  %span [
36
- %span= link_to word, stop_words_path(q: word)
35
+ %span= link_to word, stop_words_path(q: word), data: { turbo: false }
37
36
  %span ]
@@ -7,7 +7,7 @@
7
7
  = f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
8
8
  = link_to "重置", logs_path, class: "text-sm"
9
9
 
10
- %div="共 #{@pagy.count} 条"
10
+ %div{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
11
11
  %div
12
12
  - if @logs.blank?
13
13
  %div{class: "flex justify-center text-gray-500 p-8 border rounded-md"} 空空如也
@@ -3,7 +3,7 @@
3
3
  %div{class: "border rounded-md mb-2 p-2 flex flex-col space-y-1"}
4
4
  %div{class: "flex justify-between"}
5
5
  %div{class: ""}
6
- = link_to mod_log.record_path do
6
+ = link_to mod_log.record_path, data: { turbo: false }, target: "_blank" do
7
7
  %span{class: "text-sm bg-indigo-100 text-indigo-600 py-1 px-2 rounded-lg"}="#{mod_log.record_type.upcase}##{mod_log.record_id}"
8
8
  - unless mod_log.labels.blank?
9
9
  - mod_log.labels.each do |label|
@@ -24,7 +24,7 @@
24
24
  - if mod_log.status == 2
25
25
  = "暂缓"
26
26
  %span
27
- = link_to "详情", mod_log
27
+ = link_to "详情", mod_log, data: { turbo: false }, target: "_blank"
28
28
  %span
29
29
  = button_to '删除', mod_log, method: :delete, data: { confirm: 'Are you sure?'}, class: "text-red-600 rounded-md px-2 py-0.5"
30
30
  %div{class: "flex justify-between items-center"}
@@ -7,7 +7,7 @@
7
7
  = f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
8
8
  = link_to "重置", mod_logs_path, class: "text-sm"
9
9
 
10
- %div="共 #{@pagy.count} 条"
10
+ %div{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
11
11
  %div
12
12
  - if @mod_logs.blank?
13
13
  %div{class: "flex justify-center text-gray-500 p-8 border rounded-md"} 空空如也
@@ -4,10 +4,11 @@
4
4
  = form_with(url: stop_words_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 :filter, options_for_select([%w[长度为1 size_one], %w[长度为2 size_two], %w[长度为3 size_three]], params[:filter]), {include_blank: "-- 按敏感词长度筛选 --"}, class: "border rounded-md m py-0.5 px-1"
7
8
  = f.submit "检索", class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
8
9
  = link_to "重置", stop_words_path, class: "text-sm"
9
-
10
10
  %div
11
+ %span{class: "text-sm text-gray-600"}="共 #{@pagy.count} 条"
11
12
  = link_to '批量导入', "#", class: "text-sm"
12
13
  = link_to '新增', new_stop_word_path, class: "rounded-md px-2 py-1 text-sm bg-black text-white cursor-pointer"
13
14
  %div
@@ -10,9 +10,9 @@
10
10
  %body{class: "flex flex-col space-y-6 p-4"}
11
11
  %ul{class: "flex justify-end items-center space-x-2 text-blue-600"}
12
12
  %li= link_to "审查(#{CensorBear::ModLog.pending.count})", mod_logs_path
13
- %li= link_to "敏感词", stop_words_path
14
13
  %li= link_to "日志", logs_path
15
- %li= link_to "回主站", "/"
14
+ %li= link_to "敏感词", stop_words_path
15
+ %li= link_to "控制台", main_app.send(CensorBear.config.main_app_root_path_method.to_sym)
16
16
  %li= current_user.email
17
17
  %div
18
18
  = yield
@@ -9,11 +9,12 @@ en:
9
9
  pass: 忽略
10
10
  review: 审核
11
11
  stage:
12
- aliyun_check: "阿里云检查"
13
- tencent_check: "腾讯云检查"
14
- local_check: "本地检查"
15
- qq_regex: "QQ正则检查"
16
- wechat_regex: "微信正则检查"
12
+ check_search: 搜索检查
13
+ aliyun_check: 阿里云检查
14
+ tencent_check: 腾讯云检查
15
+ local_check: 本地检查
16
+ qq_regex: QQ正则检查
17
+ wechat_regex: 微信正则检查
17
18
  label:
18
19
  normal: 正常文本
19
20
  spam: 含垃圾信息
@@ -30,15 +30,15 @@ module CensorBear
30
30
  return Result.new(@content) unless CensorBear::StopWord::FIELDS.include?(@type)
31
31
 
32
32
  # 正则过滤
33
- if @content.match(QQ_REG)
34
- CensorBear.info(@content, @type, 'BANNED', 'qq_regex', ip: @ip, user_id: @user_id)
35
- raise NotPassedException
36
- end
33
+ # if @content.match(QQ_REG)
34
+ # CensorBear.info(@content, @type, 'BANNED', 'qq_regex', ip: @ip, user_id: @user_id)
35
+ # raise NotPassedException
36
+ # end
37
37
 
38
- if @content.match(WX_REG)
39
- CensorBear.info(@content, @type, 'BANNED', 'wx_regex', ip: @ip, user_id: @user_id)
40
- raise NotPassedException
41
- end
38
+ # if @content.match(WX_REG)
39
+ # CensorBear.info(@content, @type, 'BANNED', 'wx_regex', ip: @ip, user_id: @user_id)
40
+ # raise NotPassedException
41
+ # end
42
42
 
43
43
  # 本地自定义词库粗查
44
44
  local_check
@@ -115,7 +115,7 @@ 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 abuse].include?(r['label'])
118
+ if action == 'block' && rate >= 70 && %w[politics terrorism].include?(r['label'])
119
119
  CensorBear.info(
120
120
  d['content'], @type, action, 'aliyun_check',
121
121
  filtered_content: d['filteredContent'],
@@ -148,6 +148,7 @@ module CensorBear
148
148
  private
149
149
 
150
150
  def concat_labels(data)
151
+ return [] if data.blank?
151
152
  labels = []
152
153
  data.map do |d|
153
154
  next if d['label'].blank?
@@ -158,6 +159,7 @@ module CensorBear
158
159
  end
159
160
 
160
161
  def concat_words(data)
162
+ return [] if data.blank?
161
163
  words = []
162
164
  data.each do |d|
163
165
  next if d['contexts'].blank?
@@ -17,5 +17,7 @@ module CensorBear
17
17
  attr_accessor :aliyun_green_access_key_id
18
18
  attr_accessor :aliyun_green_access_key_secret
19
19
  attr_accessor :aliyun_green_enable_internal
20
+
21
+ attr_accessor :main_app_root_path_method
20
22
  end
21
23
  end
@@ -1,3 +1,3 @@
1
1
  module CensorBear
2
- VERSION = '0.1.9'.freeze
2
+ VERSION = '0.1.13'.freeze
3
3
  end
data/lib/censor_bear.rb CHANGED
@@ -24,6 +24,8 @@ module CensorBear
24
24
  @config.aliyun_green_access_key_id = ''
25
25
  @config.aliyun_green_access_key_secret = ''
26
26
  @config.aliyun_green_enable_internal = false
27
+ @config.main_app_root_path_method = 'root_path'
28
+
27
29
  @config
28
30
  end
29
31
 
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.9
4
+ version: 0.1.13
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-08 00:00:00.000000000 Z
11
+ date: 2021-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails