discourse_dev 0.0.7 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +40 -4
- data/auth/app/views/fake_discourse_connect/form.html.erb +120 -0
- data/auth/plugin.rb +219 -0
- data/avatars/03F55412-DE8A-4F83-AAA6-D67EE5CE48DA-200w.jpeg +0 -0
- data/avatars/1C4EEDC2-FE9C-40B3-A2C9-A038873EE692-200w.jpeg +0 -0
- data/avatars/26CFEFB3-21C8-49FC-8C19-8E6A62B6D2E0-200w.jpeg +0 -0
- data/avatars/282A12CA-E0D7-4011-8BDD-1FAFAAB035F7-200w.jpeg +0 -0
- data/avatars/2DDDE973-40EC-4004-ABC0-73FD4CD6D042-200w.jpeg +0 -0
- data/avatars/344CFC24-61FB-426C-B3D1-CAD5BCBD3209-200w.jpeg +0 -0
- data/avatars/852EC6E1-347C-4187-9D42-DF264CCF17BF-200w.jpeg +0 -0
- data/avatars/A7299C8E-CEFC-47D9-939A-3C8CA0EA4D13-200w.jpeg +0 -0
- data/avatars/AEF44435-B547-4B84-A2AE-887DFAEE6DDF-200w.jpeg +0 -0
- data/avatars/B3CF5288-34B0-4A5E-9877-5965522529D6-200w.jpeg +0 -0
- data/avatars/BA0CB1F2-8C79-4376-B13B-DD5FB8772537-200w.jpeg +0 -0
- data/avatars/E0B4CAB3-F491-4322-BEF2-208B46748D4A-200w.jpeg +0 -0
- data/avatars/FBEBF655-4886-455A-A4A4-D62B77DD419B-200w.jpeg +0 -0
- data/config/dev.yml +38 -0
- data/config/locales/client.en.yml +6 -0
- data/{lib/faker/locales/en.yml → config/locales/faker.en.yml} +0 -0
- data/discourse_dev.gemspec +1 -0
- data/lib/discourse_dev.rb +49 -4
- data/lib/discourse_dev/category.rb +3 -3
- data/lib/discourse_dev/config.rb +101 -29
- data/lib/discourse_dev/group.rb +4 -5
- data/lib/discourse_dev/post.rb +35 -16
- data/lib/discourse_dev/record.rb +13 -11
- data/lib/discourse_dev/tag.rb +14 -2
- data/lib/discourse_dev/tasks/dev.rake +6 -2
- data/lib/discourse_dev/topic.rb +48 -11
- data/lib/discourse_dev/user.rb +58 -7
- data/lib/discourse_dev/version.rb +1 -1
- data/lib/faker/discourse_markdown.rb +96 -0
- metadata +36 -4
- data/lib/discourse_dev/config.yml +0 -4
File without changes
|
data/discourse_dev.gemspec
CHANGED
data/lib/discourse_dev.rb
CHANGED
@@ -2,12 +2,57 @@
|
|
2
2
|
|
3
3
|
require 'i18n'
|
4
4
|
|
5
|
-
Dir[File.dirname(__FILE__) + '/**/*.rb'].each {|file| require file }
|
6
|
-
|
7
|
-
I18n.load_path += Dir[File.join(__dir__, 'faker', 'locales', '**/*.yml')]
|
8
|
-
I18n.reload! if I18n.backend.initialized?
|
5
|
+
Dir[File.dirname(__FILE__) + '/**/*.rb'].each { |file| require file }
|
9
6
|
|
10
7
|
module DiscourseDev
|
11
8
|
require 'discourse_dev/railtie'
|
12
9
|
require 'discourse_dev/engine'
|
10
|
+
|
11
|
+
def self.auth_plugin_enabled?
|
12
|
+
config.auth_plugin_enabled
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
@config ||= Config.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.auth_plugin
|
20
|
+
return unless auth_plugin_enabled?
|
21
|
+
|
22
|
+
@auth_plugin ||= begin
|
23
|
+
path = File.join(root, 'auth', 'plugin.rb')
|
24
|
+
source = File.read(path)
|
25
|
+
metadata = Plugin::Metadata.parse(source)
|
26
|
+
Plugin::Instance.new(metadata, path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.settings_file
|
31
|
+
File.join(root, "config", "settings.yml")
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.client_locale_files(locale_str)
|
35
|
+
Dir[File.join(root, "config", "locales", "client*.#{locale_str}.yml")]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.root
|
39
|
+
File.expand_path("..", __dir__)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
require "active_record/database_configurations"
|
44
|
+
|
45
|
+
ActiveRecord::Tasks::DatabaseTasks.module_eval do
|
46
|
+
alias_method :rails_each_current_configuration, :each_current_configuration
|
47
|
+
|
48
|
+
private
|
49
|
+
def each_current_configuration(environment, name = nil)
|
50
|
+
rails_each_current_configuration(environment, name) { |db_config|
|
51
|
+
next if environment == "development" &&
|
52
|
+
ENV["SKIP_TEST_DATABASE"] == "1" &&
|
53
|
+
db_config.configuration_hash[:database] != "discourse_development"
|
54
|
+
|
55
|
+
yield db_config
|
56
|
+
}
|
57
|
+
end
|
13
58
|
end
|
@@ -7,8 +7,8 @@ require 'faker'
|
|
7
7
|
module DiscourseDev
|
8
8
|
class Category < Record
|
9
9
|
|
10
|
-
def initialize
|
11
|
-
super(::Category, count)
|
10
|
+
def initialize
|
11
|
+
super(::Category, DiscourseDev.config.category[:count])
|
12
12
|
@parent_category_ids = ::Category.where(parent_category_id: nil).pluck(:id)
|
13
13
|
end
|
14
14
|
|
@@ -36,7 +36,7 @@ module DiscourseDev
|
|
36
36
|
def permissions
|
37
37
|
return @permissions if @permissions.present?
|
38
38
|
return { everyone: :full } if Faker::Boolean.boolean(true_ratio: 0.75)
|
39
|
-
|
39
|
+
|
40
40
|
permission = {}
|
41
41
|
group = Group.random
|
42
42
|
permission[group.id] = Faker::Number.between(from: 1, to: 3)
|
data/lib/discourse_dev/config.rb
CHANGED
@@ -1,77 +1,149 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rails'
|
4
|
+
require 'highline/import'
|
4
5
|
|
5
6
|
module DiscourseDev
|
6
7
|
class Config
|
7
|
-
attr_reader :config, :
|
8
|
+
attr_reader :config, :file_path
|
8
9
|
|
9
10
|
def initialize
|
10
|
-
|
11
|
-
file_path = File.join(Rails.root, "config", "dev.yml")
|
11
|
+
default_file_path = File.join(DiscourseDev.root, "config", "dev.yml")
|
12
|
+
@file_path = File.join(Rails.root, "config", "dev.yml")
|
13
|
+
default_config = YAML.load_file(default_file_path)
|
12
14
|
|
13
15
|
if File.exists?(file_path)
|
14
|
-
|
16
|
+
user_config = YAML.load_file(file_path)
|
15
17
|
else
|
16
|
-
|
18
|
+
puts "I did no detect a custom `config/dev.yml` file, creating one for you where you can amend defaults."
|
19
|
+
FileUtils.cp(default_file_path, file_path)
|
20
|
+
user_config = {}
|
17
21
|
end
|
22
|
+
|
23
|
+
@config = default_config.deep_merge(user_config).deep_symbolize_keys
|
18
24
|
end
|
19
25
|
|
20
26
|
def update!
|
21
27
|
update_site_settings
|
22
28
|
create_admin_user
|
29
|
+
create_new_user
|
23
30
|
set_seed
|
24
31
|
end
|
25
32
|
|
33
|
+
private
|
34
|
+
|
26
35
|
def update_site_settings
|
27
36
|
puts "Updating site settings..."
|
28
37
|
|
29
|
-
site_settings = config[
|
38
|
+
site_settings = config[:site_settings] || {}
|
30
39
|
|
31
40
|
site_settings.each do |key, value|
|
32
41
|
puts "#{key} = #{value}"
|
33
42
|
SiteSetting.set(key, value)
|
34
43
|
end
|
35
44
|
|
36
|
-
keys = site_settings.keys
|
37
|
-
|
38
|
-
default_config["site_settings"].each do |key, value|
|
39
|
-
next if keys.include?(key)
|
40
|
-
|
41
|
-
puts "#{key} = #{value}"
|
42
|
-
SiteSetting.set(key, value)
|
43
|
-
end
|
44
|
-
|
45
45
|
SiteSetting.refresh!
|
46
46
|
end
|
47
47
|
|
48
48
|
def create_admin_user
|
49
49
|
puts "Creating default admin user account..."
|
50
50
|
|
51
|
-
settings = config[
|
51
|
+
settings = config[:admin]
|
52
|
+
|
53
|
+
if settings.present?
|
54
|
+
create_admin_user_from_settings(settings)
|
55
|
+
else
|
56
|
+
create_admin_user_from_input
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_new_user
|
61
|
+
settings = config[:new_user]
|
52
62
|
|
53
63
|
if settings.present?
|
54
|
-
email = settings[
|
64
|
+
email = settings[:email] || "new_user@example.com"
|
55
65
|
|
56
|
-
|
66
|
+
new_user = ::User.create!(
|
57
67
|
email: email,
|
58
|
-
username: settings[
|
59
|
-
password: settings["password"]
|
68
|
+
username: settings[:username] || UserNameSuggester.suggest(email)
|
60
69
|
)
|
61
|
-
|
62
|
-
|
63
|
-
admin.change_trust_level!(1)
|
64
|
-
end
|
65
|
-
admin.email_tokens.update_all confirmed: true
|
66
|
-
admin.activate
|
67
|
-
else
|
68
|
-
Rake::Task['admin:create'].invoke
|
70
|
+
new_user.email_tokens.update_all confirmed: true
|
71
|
+
new_user.activate
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
75
|
def set_seed
|
73
|
-
seed =
|
76
|
+
seed = self.seed || 1
|
74
77
|
Faker::Config.random = Random.new(seed)
|
75
78
|
end
|
79
|
+
|
80
|
+
def start_date
|
81
|
+
DateTime.parse(config[:start_date])
|
82
|
+
end
|
83
|
+
|
84
|
+
def method_missing(name)
|
85
|
+
config[name.to_sym]
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_admin_user_from_settings(settings)
|
89
|
+
email = settings[:email]
|
90
|
+
|
91
|
+
admin = ::User.create!(
|
92
|
+
email: email,
|
93
|
+
username: settings[:username] || UserNameSuggester.suggest(email),
|
94
|
+
password: settings[:password]
|
95
|
+
)
|
96
|
+
admin.grant_admin!
|
97
|
+
if admin.trust_level < 1
|
98
|
+
admin.change_trust_level!(1)
|
99
|
+
end
|
100
|
+
admin.email_tokens.update_all confirmed: true
|
101
|
+
admin.activate
|
102
|
+
end
|
103
|
+
|
104
|
+
def create_admin_user_from_input
|
105
|
+
begin
|
106
|
+
email = ask("Email: ")
|
107
|
+
password = ask("Password (optional, press ENTER to skip): ")
|
108
|
+
username = UserNameSuggester.suggest(email)
|
109
|
+
|
110
|
+
admin = ::User.new(
|
111
|
+
email: email,
|
112
|
+
username: username
|
113
|
+
)
|
114
|
+
|
115
|
+
if password.present?
|
116
|
+
admin.password = password
|
117
|
+
else
|
118
|
+
puts "Once site is running use https://localhost:9292/user/#{username}/become to access the account in development"
|
119
|
+
end
|
120
|
+
|
121
|
+
admin.name = ask("Full name: ") if SiteSetting.full_name_required
|
122
|
+
saved = admin.save
|
123
|
+
|
124
|
+
if saved
|
125
|
+
File.open(file_path, 'a') do | file|
|
126
|
+
file.puts("admin:")
|
127
|
+
file.puts(" username: #{admin.username}")
|
128
|
+
file.puts(" email: #{admin.email}")
|
129
|
+
file.puts(" password: #{password}") if password.present?
|
130
|
+
end
|
131
|
+
else
|
132
|
+
say(admin.errors.full_messages.join("\n"))
|
133
|
+
end
|
134
|
+
end while !saved
|
135
|
+
|
136
|
+
admin.active = true
|
137
|
+
admin.save
|
138
|
+
|
139
|
+
admin.grant_admin!
|
140
|
+
if admin.trust_level < 1
|
141
|
+
admin.change_trust_level!(1)
|
142
|
+
end
|
143
|
+
admin.email_tokens.update_all confirmed: true
|
144
|
+
admin.activate
|
145
|
+
|
146
|
+
say("\nAdmin account created successfully with username #{admin.username}")
|
147
|
+
end
|
76
148
|
end
|
77
149
|
end
|
data/lib/discourse_dev/group.rb
CHANGED
@@ -7,10 +7,8 @@ require 'faker'
|
|
7
7
|
module DiscourseDev
|
8
8
|
class Group < Record
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(count = DEFAULT_COUNT)
|
13
|
-
super(::Group, count)
|
10
|
+
def initialize
|
11
|
+
super(::Group, DiscourseDev.config.group[:count])
|
14
12
|
end
|
15
13
|
|
16
14
|
def data
|
@@ -18,7 +16,8 @@ module DiscourseDev
|
|
18
16
|
name: Faker::Discourse.unique.group,
|
19
17
|
public_exit: Faker::Boolean.boolean,
|
20
18
|
public_admission: Faker::Boolean.boolean,
|
21
|
-
primary_group: Faker::Boolean.boolean
|
19
|
+
primary_group: Faker::Boolean.boolean,
|
20
|
+
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
22
21
|
}
|
23
22
|
end
|
24
23
|
|
data/lib/discourse_dev/post.rb
CHANGED
@@ -8,31 +8,47 @@ module DiscourseDev
|
|
8
8
|
|
9
9
|
attr_reader :topic
|
10
10
|
|
11
|
-
def initialize(topic, count
|
11
|
+
def initialize(topic, count)
|
12
12
|
super(::Post, count)
|
13
13
|
@topic = topic
|
14
14
|
|
15
15
|
category = topic.category
|
16
|
+
@max_likes_count = DiscourseDev.config.post[:max_likes_count]
|
16
17
|
unless category.groups.blank?
|
17
18
|
group_ids = category.groups.pluck(:id)
|
18
19
|
@user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
|
19
20
|
@user_count = @user_ids.count
|
21
|
+
@max_likes_count = @user_count - 1
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
25
|
def data
|
24
26
|
{
|
25
27
|
topic_id: topic.id,
|
26
|
-
raw: Faker::
|
27
|
-
|
28
|
+
raw: Faker::DiscourseMarkdown.sandwich(sentences: 5),
|
29
|
+
created_at: Faker::Time.between(from: topic.last_posted_at, to: DateTime.now),
|
30
|
+
skip_validations: true,
|
31
|
+
skip_guardian: true
|
28
32
|
}
|
29
33
|
end
|
30
34
|
|
31
35
|
def create!
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
user = self.user
|
37
|
+
data = Faker::DiscourseMarkdown.with_user(user.id) { self.data }
|
38
|
+
post = PostCreator.new(user, data).create!
|
39
|
+
topic.reload
|
40
|
+
generate_likes(post)
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate_likes(post)
|
44
|
+
user_ids = [post.user_id]
|
45
|
+
|
46
|
+
Faker::Number.between(from: 0, to: @max_likes_count).times do
|
47
|
+
user = self.user
|
48
|
+
next if user_ids.include?(user.id)
|
49
|
+
|
50
|
+
PostActionCreator.new(user, post, PostActionType.types[:like], created_at: Faker::Time.between(from: post.created_at, to: DateTime.now)).perform
|
51
|
+
user_ids << user.id
|
36
52
|
end
|
37
53
|
end
|
38
54
|
|
@@ -45,8 +61,9 @@ module DiscourseDev
|
|
45
61
|
end
|
46
62
|
|
47
63
|
def populate!
|
48
|
-
|
49
|
-
|
64
|
+
generate_likes(topic.first_post)
|
65
|
+
|
66
|
+
@count.times do
|
50
67
|
create!
|
51
68
|
end
|
52
69
|
end
|
@@ -68,14 +85,16 @@ module DiscourseDev
|
|
68
85
|
puts "Creating #{count} replies in '#{topic.title}'"
|
69
86
|
|
70
87
|
count.times do |i|
|
71
|
-
@index = i
|
72
88
|
begin
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
89
|
+
user = User.random
|
90
|
+
reply = Faker::DiscourseMarkdown.with_user(user.id) do
|
91
|
+
{
|
92
|
+
topic_id: topic.id,
|
93
|
+
raw: Faker::DiscourseMarkdown.sandwich(sentences: 5),
|
94
|
+
skip_validations: true
|
95
|
+
}
|
96
|
+
end
|
97
|
+
PostCreator.new(user, reply).create!
|
79
98
|
rescue ActiveRecord::RecordNotSaved => e
|
80
99
|
puts e
|
81
100
|
end
|
data/lib/discourse_dev/record.rb
CHANGED
@@ -11,11 +11,15 @@ module DiscourseDev
|
|
11
11
|
attr_reader :model, :type
|
12
12
|
|
13
13
|
def initialize(model, count = DEFAULT_COUNT)
|
14
|
-
|
14
|
+
@@initialized ||= begin
|
15
|
+
Faker::Discourse.unique.clear
|
16
|
+
RateLimiter.disable
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
15
20
|
@model = model
|
16
21
|
@type = model.to_s
|
17
22
|
@count = count
|
18
|
-
@index = nil
|
19
23
|
end
|
20
24
|
|
21
25
|
def create!
|
@@ -25,7 +29,7 @@ module DiscourseDev
|
|
25
29
|
|
26
30
|
def populate!
|
27
31
|
if current_count >= @count
|
28
|
-
puts "Already have #{
|
32
|
+
puts "Already have #{current_count} #{type.downcase} records"
|
29
33
|
|
30
34
|
Rake.application.top_level_tasks.each do |task_name|
|
31
35
|
Rake::Task[task_name].reenable
|
@@ -33,12 +37,14 @@ module DiscourseDev
|
|
33
37
|
|
34
38
|
Rake::Task['dev:repopulate'].invoke
|
35
39
|
return
|
40
|
+
elsif current_count > 0
|
41
|
+
@count -= current_count
|
42
|
+
puts "There are #{current_count} #{type.downcase} records. Creating #{@count} more."
|
43
|
+
else
|
44
|
+
puts "Creating #{@count} sample #{type.downcase} records"
|
36
45
|
end
|
37
46
|
|
38
|
-
|
39
|
-
|
40
|
-
@count.times do |i|
|
41
|
-
@index = i
|
47
|
+
@count.times do
|
42
48
|
create!
|
43
49
|
putc "."
|
44
50
|
end
|
@@ -46,10 +52,6 @@ module DiscourseDev
|
|
46
52
|
puts
|
47
53
|
end
|
48
54
|
|
49
|
-
def index
|
50
|
-
@index
|
51
|
-
end
|
52
|
-
|
53
55
|
def current_count
|
54
56
|
model.count
|
55
57
|
end
|