Repository navigation
Expand file tree
/
Copy pathplugin.rb
More file actions
87 lines (67 loc) · 2.29 KB
/
Copy pathplugin.rb
File metadata and controls
87 lines (67 loc) · 2.29 KB
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
83
84
85
86
87
# name: Discourse 中文本地化服务集合
# about: 为 Discourse 增加了各种本地化的功能。
# version: 4.1.0
# authors: Erick Guan
# url: https://github.com/erickguan/discourse-chinese-localization-pack
enabled_site_setting :zh_l10n_enabled
gem("omniauth-weibo-oauth2", "0.5.3")
register_svg_icon "fab-weibo"
register_svg_icon "fab-qq"
# load oauth providers
Dir[File.expand_path("../lib/auth/*.rb", __FILE__)].each { |f| require f }
require "active_support/inflector"
require "ostruct"
PROVIDERS = ["Weibo"]
PLUGIN_PREFIX = "zh_l10n_".freeze
SITE_SETTING_NAME = "zh_l10n_enabled".freeze
ONEBOX_SETTING_NAME = "zh_l10n_http_onebox_override".freeze
def provider_icon(provider_name)
provider_name = provider_name.downcase
"fab-#{provider_name}"
end
PROVIDERS.each do |name|
auth_provider(
authenticator: "#{name}Authenticator".constantize.new,
icon: provider_icon(name)
)
end
Dir[File.expand_path("../lib/onebox_override/*.rb", __FILE__)].each do |f|
require f
end
register_asset "stylesheets/buttons.scss"
after_initialize do
next unless SiteSetting.zh_l10n_enabled
Dir[File.expand_path("../lib/onebox/*.rb", __FILE__)].each { |f| require f }
require_relative "app/services/problem_check/weibo_config"
register_problem_check ProblemCheck::WeiboConfig
DiscourseEvent.on(:site_setting_changed) do |site_setting|
if site_setting.name == SITE_SETTING_NAME && site_setting.value_changed? &&
site_setting.value == "f" # false
PROVIDERS.each do |provider|
SiteSetting.public_send(
"#{PLUGIN_PREFIX}enable_#{provider[0].downcase}_logins=",
false
)
end
end
end
module ::DisableUsernameSuggester
def to_client_hash
hash = defined?(super) ? super : nil
return nil unless hash
# only catch when a oauth login and a username is random
if hash[:auth_provider]
match = (hash[:username] || "").match(/^\d+$/i)
if SiteSetting.zh_l10n_disable_random_username_sugeestion && match
hash[:username] = nil
if SiteSetting.enable_names? &&
SiteSetting.zh_l10n_disable_random_username_sugeestion && match
hash[:name] = nil
end
end
end
hash
end
end
Auth::Result.class_eval { prepend ::DisableUsernameSuggester }
end