discourse_dev 0.0.3 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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/routes.rb +5 -0
- data/lib/discourse_dev.rb +20 -1
- data/lib/discourse_dev/category.rb +8 -12
- data/lib/discourse_dev/config.rb +44 -1
- data/lib/discourse_dev/config.yml +4 -1
- data/lib/discourse_dev/engine.rb +5 -0
- data/lib/discourse_dev/group.rb +7 -11
- data/lib/discourse_dev/post.rb +104 -0
- data/lib/discourse_dev/record.rb +38 -5
- data/lib/discourse_dev/tag.rb +20 -0
- data/lib/discourse_dev/tasks/dev.rake +19 -2
- data/lib/discourse_dev/tasks/populate.rake +10 -0
- data/lib/discourse_dev/topic.rb +61 -13
- data/lib/discourse_dev/user.rb +60 -8
- data/lib/discourse_dev/version.rb +1 -1
- data/lib/faker/discourse.rb +8 -0
- data/lib/faker/locales/en.yml +70 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c041cf9d05c586e547562729b749c5f86bc388a8311cd2a12fbb48e6ef3d56f
|
4
|
+
data.tar.gz: 69ddc047893ac6f4deeaf5f723eceb4317f6ba17a9d7b18bccfe520455286e76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afcf13989b8677fe40aa5c80201d6b8fcc77bd1f7465bc03d8fbce153d009b2efd9a71de72f5950820d5f7b275ec7bbff16bed5d7b43c7264af02a382aa3b54f
|
7
|
+
data.tar.gz: dbad0056c7af12f508f623b7ddaac2ffbf04c452fb26580d257822fc34d990146cf4722375450934de3b78e2ec8e5f70f594e52764e3c68f6448f9c78eb71181
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/config/routes.rb
ADDED
data/lib/discourse_dev.rb
CHANGED
@@ -8,5 +8,24 @@ I18n.load_path += Dir[File.join(__dir__, 'faker', 'locales', '**/*.yml')]
|
|
8
8
|
I18n.reload! if I18n.backend.initialized?
|
9
9
|
|
10
10
|
module DiscourseDev
|
11
|
-
require 'discourse_dev/railtie'
|
11
|
+
require 'discourse_dev/railtie'
|
12
|
+
require 'discourse_dev/engine'
|
13
|
+
|
14
|
+
def self.config
|
15
|
+
@config ||= Config.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "active_record/database_configurations"
|
20
|
+
|
21
|
+
ActiveRecord::Tasks::DatabaseTasks.module_eval do
|
22
|
+
alias_method :rails_each_current_configuration, :each_current_configuration
|
23
|
+
|
24
|
+
private
|
25
|
+
def each_current_configuration(environment, name = nil)
|
26
|
+
rails_each_current_configuration(environment, name) { |db_config|
|
27
|
+
next if environment == "development" && ENV["SKIP_TEST_DATABASE"] == "1" && db_config["database"] != "discourse_development"
|
28
|
+
yield db_config
|
29
|
+
}
|
30
|
+
end
|
12
31
|
end
|
@@ -9,23 +9,16 @@ module DiscourseDev
|
|
9
9
|
|
10
10
|
def initialize(count = DEFAULT_COUNT)
|
11
11
|
super(::Category, count)
|
12
|
-
@existing_names = ::Category.pluck(:name)
|
13
12
|
@parent_category_ids = ::Category.where(parent_category_id: nil).pluck(:id)
|
14
|
-
@group_count = ::Group.count
|
15
13
|
end
|
16
14
|
|
17
15
|
def data
|
18
|
-
name = Faker::Discourse.category
|
16
|
+
name = Faker::Discourse.unique.category
|
19
17
|
parent_category_id = nil
|
20
18
|
|
21
|
-
while @existing_names.include? name
|
22
|
-
name = Faker::Discourse.category
|
23
|
-
end
|
24
|
-
|
25
|
-
@existing_names << name
|
26
|
-
|
27
19
|
if Faker::Boolean.boolean(true_ratio: 0.6)
|
28
|
-
|
20
|
+
offset = Faker::Number.between(from: 0, to: @parent_category_ids.count - 1)
|
21
|
+
parent_category_id = @parent_category_ids[offset]
|
29
22
|
@permissions = ::Category.find(parent_category_id).permissions_params.presence
|
30
23
|
else
|
31
24
|
@permissions = nil
|
@@ -45,8 +38,7 @@ module DiscourseDev
|
|
45
38
|
return { everyone: :full } if Faker::Boolean.boolean(true_ratio: 0.75)
|
46
39
|
|
47
40
|
permission = {}
|
48
|
-
|
49
|
-
group = ::Group.offset(offset).first
|
41
|
+
group = Group.random
|
50
42
|
permission[group.id] = Faker::Number.between(from: 1, to: 3)
|
51
43
|
|
52
44
|
permission
|
@@ -60,5 +52,9 @@ module DiscourseDev
|
|
60
52
|
@parent_category_ids << category.id if category.parent_category_id.blank?
|
61
53
|
end
|
62
54
|
end
|
55
|
+
|
56
|
+
def self.random
|
57
|
+
super(::Category)
|
58
|
+
end
|
63
59
|
end
|
64
60
|
end
|
data/lib/discourse_dev/config.rb
CHANGED
@@ -7,18 +7,23 @@ module DiscourseDev
|
|
7
7
|
attr_reader :config, :default_config
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
|
10
|
+
default_file_path = File.join(File.expand_path(__dir__), "config.yml")
|
11
11
|
file_path = File.join(Rails.root, "config", "dev.yml")
|
12
|
+
@default_config = YAML.load_file(default_file_path)
|
12
13
|
|
13
14
|
if File.exists?(file_path)
|
14
15
|
@config = YAML.load_file(file_path)
|
15
16
|
else
|
17
|
+
puts "I did no detect a custom `config/dev.yml` file, creating one for you where you can amend defaults."
|
18
|
+
FileUtils.cp(default_file_path, file_path)
|
16
19
|
@config = {}
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
23
|
def update!
|
21
24
|
update_site_settings
|
25
|
+
create_admin_user
|
26
|
+
set_seed
|
22
27
|
end
|
23
28
|
|
24
29
|
def update_site_settings
|
@@ -42,5 +47,43 @@ module DiscourseDev
|
|
42
47
|
|
43
48
|
SiteSetting.refresh!
|
44
49
|
end
|
50
|
+
|
51
|
+
def create_admin_user
|
52
|
+
puts "Creating default admin user account..."
|
53
|
+
|
54
|
+
settings = config["admin"]
|
55
|
+
|
56
|
+
if settings.present?
|
57
|
+
email = settings["email"]
|
58
|
+
|
59
|
+
admin = ::User.create!(
|
60
|
+
email: email,
|
61
|
+
username: settings["username"] || UserNameSuggester.suggest(email),
|
62
|
+
password: settings["password"]
|
63
|
+
)
|
64
|
+
admin.grant_admin!
|
65
|
+
if admin.trust_level < 1
|
66
|
+
admin.change_trust_level!(1)
|
67
|
+
end
|
68
|
+
admin.email_tokens.update_all confirmed: true
|
69
|
+
admin.activate
|
70
|
+
else
|
71
|
+
Rake::Task['admin:create'].invoke
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_seed
|
76
|
+
seed = self.seed || 1
|
77
|
+
Faker::Config.random = Random.new(seed)
|
78
|
+
end
|
79
|
+
|
80
|
+
def start_date
|
81
|
+
DateTime.parse(config["start_date"] || default_config["start_date"])
|
82
|
+
end
|
83
|
+
|
84
|
+
def method_missing(name)
|
85
|
+
name = name.to_s
|
86
|
+
config[name] || default_config[name]
|
87
|
+
end
|
45
88
|
end
|
46
89
|
end
|
data/lib/discourse_dev/group.rb
CHANGED
@@ -11,23 +11,15 @@ module DiscourseDev
|
|
11
11
|
|
12
12
|
def initialize(count = DEFAULT_COUNT)
|
13
13
|
super(::Group, count)
|
14
|
-
@existing_names = ::Group.where(automatic: false).pluck(:name)
|
15
14
|
end
|
16
15
|
|
17
16
|
def data
|
18
|
-
name = Faker::Discourse.group
|
19
|
-
|
20
|
-
while @existing_names.include? name
|
21
|
-
name = Faker::Company.profession.gsub(" ", "-")
|
22
|
-
end
|
23
|
-
|
24
|
-
@existing_names << name
|
25
|
-
|
26
17
|
{
|
27
|
-
name:
|
18
|
+
name: Faker::Discourse.unique.group,
|
28
19
|
public_exit: Faker::Boolean.boolean,
|
29
20
|
public_admission: Faker::Boolean.boolean,
|
30
|
-
primary_group: Faker::Boolean.boolean
|
21
|
+
primary_group: Faker::Boolean.boolean,
|
22
|
+
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
31
23
|
}
|
32
24
|
end
|
33
25
|
|
@@ -40,5 +32,9 @@ module DiscourseDev
|
|
40
32
|
end
|
41
33
|
end
|
42
34
|
end
|
35
|
+
|
36
|
+
def self.random
|
37
|
+
super(::Group)
|
38
|
+
end
|
43
39
|
end
|
44
40
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'discourse_dev/record'
|
4
|
+
require 'faker'
|
5
|
+
|
6
|
+
module DiscourseDev
|
7
|
+
class Post < Record
|
8
|
+
|
9
|
+
attr_reader :topic
|
10
|
+
|
11
|
+
def initialize(topic, count = DEFAULT_COUNT)
|
12
|
+
super(::Post, count)
|
13
|
+
@topic = topic
|
14
|
+
|
15
|
+
category = topic.category
|
16
|
+
@max_likes_count = DiscourseDev.config.max_likes_count
|
17
|
+
unless category.groups.blank?
|
18
|
+
group_ids = category.groups.pluck(:id)
|
19
|
+
@user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
|
20
|
+
@user_count = @user_ids.count
|
21
|
+
@max_likes_count = @user_count - 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def data
|
26
|
+
{
|
27
|
+
topic_id: topic.id,
|
28
|
+
raw: Faker::Markdown.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
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def create!
|
36
|
+
post = PostCreator.new(user, data).create!
|
37
|
+
topic.reload
|
38
|
+
generate_likes(post)
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_likes(post)
|
42
|
+
user_ids = [post.user_id]
|
43
|
+
|
44
|
+
Faker::Number.between(from: 0, to: @max_likes_count).times do
|
45
|
+
user = self.user
|
46
|
+
next if user_ids.include?(user.id)
|
47
|
+
|
48
|
+
PostActionCreator.new(user, post, PostActionType.types[:like], created_at: Faker::Time.between(from: post.created_at, to: DateTime.now)).perform
|
49
|
+
user_ids << user.id
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def user
|
54
|
+
return User.random if topic.category.groups.blank?
|
55
|
+
return Discourse.system_user if @user_ids.blank?
|
56
|
+
|
57
|
+
position = Faker::Number.between(from: 0, to: @user_count - 1)
|
58
|
+
::User.find(@user_ids[position])
|
59
|
+
end
|
60
|
+
|
61
|
+
def populate!
|
62
|
+
generate_likes(topic.first_post)
|
63
|
+
|
64
|
+
@count.times do |i|
|
65
|
+
@index = i
|
66
|
+
create!
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.add_replies!(args)
|
71
|
+
if !args[:topic_id]
|
72
|
+
puts "Topic ID is required. Aborting."
|
73
|
+
return
|
74
|
+
end
|
75
|
+
|
76
|
+
if !::Topic.find_by_id(args[:topic_id])
|
77
|
+
puts "Topic ID does not match topic in DB, aborting."
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
topic = ::Topic.find_by_id(args[:topic_id])
|
82
|
+
count = args[:count] ? args[:count].to_i : 50
|
83
|
+
|
84
|
+
puts "Creating #{count} replies in '#{topic.title}'"
|
85
|
+
|
86
|
+
count.times do |i|
|
87
|
+
@index = i
|
88
|
+
begin
|
89
|
+
reply = {
|
90
|
+
topic_id: topic.id,
|
91
|
+
raw: Faker::Markdown.sandwich(sentences: 5),
|
92
|
+
skip_validations: true
|
93
|
+
}
|
94
|
+
PostCreator.new(User.random, reply).create!
|
95
|
+
rescue ActiveRecord::RecordNotSaved => e
|
96
|
+
puts e
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
puts "Done!"
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
data/lib/discourse_dev/record.rb
CHANGED
@@ -8,28 +8,61 @@ module DiscourseDev
|
|
8
8
|
class Record
|
9
9
|
DEFAULT_COUNT = 30.freeze
|
10
10
|
|
11
|
-
attr_reader :model, :type
|
11
|
+
attr_reader :model, :type
|
12
12
|
|
13
13
|
def initialize(model, count = DEFAULT_COUNT)
|
14
|
+
Faker::Discourse.unique.clear
|
15
|
+
RateLimiter.disable
|
16
|
+
|
14
17
|
@model = model
|
15
18
|
@type = model.to_s
|
16
19
|
@count = count
|
20
|
+
@index = nil
|
17
21
|
end
|
18
22
|
|
19
23
|
def create!
|
20
24
|
record = model.create!(data)
|
21
|
-
yield(record)
|
22
|
-
putc "."
|
25
|
+
yield(record) if block_given?
|
23
26
|
end
|
24
27
|
|
25
28
|
def populate!
|
26
|
-
|
27
|
-
|
29
|
+
if current_count >= @count
|
30
|
+
puts "Already have #{@count}+ #{type.downcase} records."
|
31
|
+
|
32
|
+
Rake.application.top_level_tasks.each do |task_name|
|
33
|
+
Rake::Task[task_name].reenable
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::Task['dev:repopulate'].invoke
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
puts "Creating #{@count} sample #{type.downcase} records"
|
41
|
+
|
42
|
+
@count.times do |i|
|
43
|
+
@index = i
|
44
|
+
create!
|
45
|
+
putc "."
|
46
|
+
end
|
47
|
+
|
28
48
|
puts
|
29
49
|
end
|
30
50
|
|
51
|
+
def index
|
52
|
+
@index
|
53
|
+
end
|
54
|
+
|
55
|
+
def current_count
|
56
|
+
model.count
|
57
|
+
end
|
58
|
+
|
31
59
|
def self.populate!
|
32
60
|
self.new.populate!
|
33
61
|
end
|
62
|
+
|
63
|
+
def self.random(model)
|
64
|
+
offset = Faker::Number.between(from: 0, to: model.count - 1)
|
65
|
+
model.offset(offset).first
|
66
|
+
end
|
34
67
|
end
|
35
68
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'discourse_dev/record'
|
4
|
+
require 'rails'
|
5
|
+
require 'faker'
|
6
|
+
|
7
|
+
module DiscourseDev
|
8
|
+
class Tag < Record
|
9
|
+
|
10
|
+
def initialize(count = DEFAULT_COUNT)
|
11
|
+
super(::Tag, count)
|
12
|
+
end
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
name: Faker::Discourse.unique.tag,
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -4,6 +4,9 @@ def check_environment!
|
|
4
4
|
if !Rails.env.development?
|
5
5
|
raise "Database commands are only supported in development environment"
|
6
6
|
end
|
7
|
+
|
8
|
+
ENV['SKIP_TEST_DATABASE'] = "1"
|
9
|
+
ENV['SKIP_MULTISITE'] = "1"
|
7
10
|
end
|
8
11
|
|
9
12
|
desc 'Run db:migrate:reset task and populate sample content for development environment'
|
@@ -12,13 +15,12 @@ task 'dev:reset' => ['db:load_config'] do |_, args|
|
|
12
15
|
|
13
16
|
Rake::Task['db:migrate:reset'].invoke
|
14
17
|
Rake::Task['dev:config'].invoke
|
15
|
-
Rake::Task['admin:create'].invoke
|
16
18
|
Rake::Task['dev:populate'].invoke
|
17
19
|
end
|
18
20
|
|
19
21
|
desc 'Initialize development environment'
|
20
22
|
task 'dev:config' => ['db:load_config'] do |_, args|
|
21
|
-
DiscourseDev
|
23
|
+
DiscourseDev.config.update!
|
22
24
|
end
|
23
25
|
|
24
26
|
desc 'Populate sample content for development environment'
|
@@ -26,5 +28,20 @@ task 'dev:populate' => ['db:load_config'] do |_, args|
|
|
26
28
|
Rake::Task['groups:populate'].invoke
|
27
29
|
Rake::Task['users:populate'].invoke
|
28
30
|
Rake::Task['categories:populate'].invoke
|
31
|
+
Rake::Task['tags:populate'].invoke
|
29
32
|
Rake::Task['topics:populate'].invoke
|
33
|
+
system("redis-cli flushall")
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Repopulate sample datas in development environment'
|
37
|
+
task 'dev:repopulate' => ['db:load_config'] do |_, args|
|
38
|
+
require 'highline/import'
|
39
|
+
|
40
|
+
answer = ask("Do you want to repopulate the database with fresh data? It will recreate DBs and run migration from scratch before generating all the samples. (Y/n) ")
|
41
|
+
|
42
|
+
if (answer == "" || answer.downcase == 'y')
|
43
|
+
Rake::Task['dev:reset'].invoke
|
44
|
+
else
|
45
|
+
puts "You can run `dev:reset` rake task to do this repopulate action anytime."
|
46
|
+
end
|
30
47
|
end
|
@@ -15,7 +15,17 @@ task 'categories:populate' => ['db:load_config'] do |_, args|
|
|
15
15
|
DiscourseDev::Category.populate!
|
16
16
|
end
|
17
17
|
|
18
|
+
desc 'Creates sample tags'
|
19
|
+
task 'tags:populate' => ['db:load_config'] do |_, args|
|
20
|
+
DiscourseDev::Tag.populate!
|
21
|
+
end
|
22
|
+
|
18
23
|
desc 'Creates sample topics'
|
19
24
|
task 'topics:populate' => ['db:load_config'] do |_, args|
|
20
25
|
DiscourseDev::Topic.populate!
|
21
26
|
end
|
27
|
+
|
28
|
+
desc 'Add replies to a topic'
|
29
|
+
task 'replies:populate', [:topic_id, :count] => ['db:load_config'] do |_, args|
|
30
|
+
DiscourseDev::Post.add_replies!(args)
|
31
|
+
end
|
data/lib/discourse_dev/topic.rb
CHANGED
@@ -8,38 +8,86 @@ module DiscourseDev
|
|
8
8
|
|
9
9
|
def initialize(count = DEFAULT_COUNT)
|
10
10
|
super(::Topic, count)
|
11
|
-
@category_ids = ::Category.pluck(:id)
|
12
|
-
@user_count = ::User.count
|
13
11
|
end
|
14
12
|
|
15
13
|
def data
|
14
|
+
max_views = 0
|
15
|
+
|
16
|
+
case Faker::Number.between(from: 0, to: 5)
|
17
|
+
when 0
|
18
|
+
max_views = 10
|
19
|
+
when 1
|
20
|
+
max_views = 100
|
21
|
+
when 2
|
22
|
+
max_views = SiteSetting.topic_views_heat_low
|
23
|
+
when 3
|
24
|
+
max_views = SiteSetting.topic_views_heat_medium
|
25
|
+
when 4
|
26
|
+
max_views = SiteSetting.topic_views_heat_high
|
27
|
+
when 5
|
28
|
+
max_views = SiteSetting.topic_views_heat_high + SiteSetting.topic_views_heat_medium
|
29
|
+
end
|
30
|
+
|
16
31
|
{
|
17
|
-
title:
|
32
|
+
title: title[0, SiteSetting.max_topic_title_length],
|
18
33
|
raw: Faker::Markdown.sandwich(sentences: 5),
|
19
|
-
category: @
|
34
|
+
category: @category.id,
|
35
|
+
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
20
36
|
tags: tags,
|
21
|
-
topic_opts: {
|
37
|
+
topic_opts: {
|
38
|
+
import_mode: true,
|
39
|
+
views: Faker::Number.between(from: 1, to: max_views),
|
40
|
+
custom_fields: { dev_sample: true }
|
41
|
+
},
|
22
42
|
skip_validations: true
|
23
43
|
}
|
24
44
|
end
|
25
45
|
|
46
|
+
def title
|
47
|
+
if index <= I18n.t("faker.discourse.topics").count
|
48
|
+
Faker::Discourse.unique.topic
|
49
|
+
else
|
50
|
+
Faker::Lorem.unique.sentence(word_count: 3, supplemental: true, random_words_to_add: 4).chomp(".")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
26
54
|
def tags
|
27
55
|
@tags = []
|
28
|
-
keys = ["model", "make", "manufacture"]
|
29
56
|
|
30
|
-
Faker::Number.between(from: 0, to: 3).times do
|
31
|
-
@tags << Faker::
|
57
|
+
Faker::Number.between(from: 0, to: 3).times do
|
58
|
+
@tags << Faker::Discourse.tag
|
32
59
|
end
|
33
60
|
|
34
|
-
@tags
|
61
|
+
@tags.uniq
|
35
62
|
end
|
36
63
|
|
37
64
|
def create!
|
38
|
-
|
39
|
-
|
65
|
+
@category = Category.random
|
66
|
+
topic = data
|
67
|
+
post = PostCreator.new(user, topic).create!
|
68
|
+
|
69
|
+
if topic[:title] == "Coolest thing you have seen today"
|
70
|
+
reply_count = 99
|
71
|
+
else
|
72
|
+
reply_count = Faker::Number.between(from: 0, to: 12)
|
73
|
+
end
|
74
|
+
|
75
|
+
Post.new(post.topic, reply_count).populate!
|
76
|
+
end
|
77
|
+
|
78
|
+
def user
|
79
|
+
return User.random if @category.groups.blank?
|
80
|
+
|
81
|
+
group_ids = @category.groups.pluck(:id)
|
82
|
+
user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
|
83
|
+
user_count = user_ids.count
|
84
|
+
position = Faker::Number.between(from: 0, to: user_count - 1)
|
85
|
+
::User.find(user_ids[position] || Discourse::SYSTEM_USER_ID)
|
86
|
+
end
|
40
87
|
|
41
|
-
|
42
|
-
|
88
|
+
def current_count
|
89
|
+
category_definition_topic_ids = ::Category.pluck(:topic_id)
|
90
|
+
::Topic.where(archetype: :regular).where.not(id: category_definition_topic_ids).count
|
43
91
|
end
|
44
92
|
end
|
45
93
|
end
|
data/lib/discourse_dev/user.rb
CHANGED
@@ -6,17 +6,20 @@ require 'faker'
|
|
6
6
|
|
7
7
|
module DiscourseDev
|
8
8
|
class User < Record
|
9
|
+
attr_reader :images
|
9
10
|
|
10
11
|
def initialize(count = DEFAULT_COUNT)
|
11
12
|
super(::User, count)
|
12
|
-
|
13
|
-
|
13
|
+
|
14
|
+
# Using the stock avatar images from https://tinyfac.es
|
15
|
+
# Tiny Faces is a free crowd-sourced avatar gallery
|
16
|
+
@images = Dir[File.join(__dir__, '..', '..', 'avatars', '*.*')]
|
14
17
|
end
|
15
18
|
|
16
19
|
def data
|
17
|
-
name = Faker::Name.name
|
18
|
-
email = Faker::Internet.email(name: name)
|
19
|
-
username = Faker::Internet.username(specifier: name)[0, SiteSetting.max_username_length]
|
20
|
+
name = Faker::Name.unique.name
|
21
|
+
email = Faker::Internet.unique.email(name: name)
|
22
|
+
username = Faker::Internet.unique.username(specifier: name)[0, SiteSetting.max_username_length]
|
20
23
|
username_lower = username.downcase
|
21
24
|
|
22
25
|
{
|
@@ -25,19 +28,68 @@ module DiscourseDev
|
|
25
28
|
username: username,
|
26
29
|
username_lower: username_lower,
|
27
30
|
moderator: Faker::Boolean.boolean(true_ratio: 0.1),
|
28
|
-
trust_level: Faker::Number.between(from: 1, to: 4)
|
31
|
+
trust_level: Faker::Number.between(from: 1, to: 4),
|
32
|
+
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
29
33
|
}
|
30
34
|
end
|
31
35
|
|
32
36
|
def create!
|
33
37
|
super do |user|
|
38
|
+
user.activate
|
39
|
+
set_random_avatar(user)
|
34
40
|
Faker::Number.between(from: 0, to: 2).times do
|
35
|
-
|
36
|
-
group = @groups.offset(offset).first
|
41
|
+
group = Group.random
|
37
42
|
|
38
43
|
group.add(user)
|
39
44
|
end
|
40
45
|
end
|
41
46
|
end
|
47
|
+
|
48
|
+
def self.random
|
49
|
+
super(::User)
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_random_avatar(user)
|
53
|
+
return if images.blank?
|
54
|
+
return unless Faker::Boolean.boolean
|
55
|
+
|
56
|
+
avatar_index = Faker::Number.between(from: 0, to: images.count - 1)
|
57
|
+
avatar_path = images[avatar_index]
|
58
|
+
create_avatar(user, avatar_path)
|
59
|
+
@images.delete_at(avatar_index)
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_avatar(user, avatar_path)
|
63
|
+
tempfile = copy_to_tempfile(avatar_path)
|
64
|
+
filename = "avatar#{File.extname(avatar_path)}"
|
65
|
+
upload = UploadCreator.new(tempfile, filename, type: "avatar").create_for(user.id)
|
66
|
+
|
67
|
+
if upload.present? && upload.persisted?
|
68
|
+
user.create_user_avatar
|
69
|
+
user.user_avatar.update(custom_upload_id: upload.id)
|
70
|
+
user.update(uploaded_avatar_id: upload.id)
|
71
|
+
else
|
72
|
+
STDERR.puts "Failed to upload avatar for user #{user.username}: #{avatar_path}"
|
73
|
+
STDERR.puts upload.errors.inspect if upload
|
74
|
+
end
|
75
|
+
rescue
|
76
|
+
STDERR.puts "Failed to create avatar for user #{user.username}: #{avatar_path}"
|
77
|
+
ensure
|
78
|
+
tempfile.close! if tempfile
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def copy_to_tempfile(source_path)
|
84
|
+
extension = File.extname(source_path)
|
85
|
+
tmp = Tempfile.new(['discourse-upload', extension])
|
86
|
+
|
87
|
+
File.open(source_path) do |source_stream|
|
88
|
+
IO.copy_stream(source_stream, tmp)
|
89
|
+
end
|
90
|
+
|
91
|
+
tmp.rewind
|
92
|
+
tmp
|
93
|
+
end
|
42
94
|
end
|
43
95
|
end
|
data/lib/faker/discourse.rb
CHANGED
@@ -6,6 +6,10 @@ module Faker
|
|
6
6
|
class Discourse < Base
|
7
7
|
class << self
|
8
8
|
|
9
|
+
def tag
|
10
|
+
fetch('discourse.tags')
|
11
|
+
end
|
12
|
+
|
9
13
|
def category
|
10
14
|
fetch('discourse.categories')
|
11
15
|
end
|
@@ -13,6 +17,10 @@ module Faker
|
|
13
17
|
def group
|
14
18
|
fetch('discourse.groups')
|
15
19
|
end
|
20
|
+
|
21
|
+
def topic
|
22
|
+
fetch('discourse.topics')
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
data/lib/faker/locales/en.yml
CHANGED
@@ -62,3 +62,73 @@ en:
|
|
62
62
|
- subscribers
|
63
63
|
- creators
|
64
64
|
- translators
|
65
|
+
- editors
|
66
|
+
- developers
|
67
|
+
- publishers
|
68
|
+
- leaders
|
69
|
+
- advertisers
|
70
|
+
- early-birds
|
71
|
+
- partners
|
72
|
+
topics:
|
73
|
+
- Whoa. Check out this crazy paper artwork
|
74
|
+
- What’s the coolest thing you have worked on?
|
75
|
+
- A bear, however hard he tries, grows tubby without exercise
|
76
|
+
- Impressions Games City Builders
|
77
|
+
- Recommended reading for Community and FOSS enthusiasts
|
78
|
+
- Robots are taking our jobs!
|
79
|
+
- Modernizing the antiquated boxing scoring system
|
80
|
+
- Death by poisonous and electric watermelon
|
81
|
+
- D&D Gallery - Prey for Smiley Bob play session [with terrain]
|
82
|
+
- Why is uninhabited land in the US so closed off?
|
83
|
+
- The Room Appreciation Topic
|
84
|
+
- Recommend a great YouTube video
|
85
|
+
- Favorite TV show scene?
|
86
|
+
- Is the Second Amendment still relevant today?
|
87
|
+
- What methods/books did you use to learn Ruby?
|
88
|
+
- What is your favorite TED Video
|
89
|
+
- MLP:FIM Season 3 (spoilers ahoy!)
|
90
|
+
- Do you use a mobile device for ALL your work? Tell me how!
|
91
|
+
- What’s your all-time favorite movie scene?
|
92
|
+
- Enjoyable children’s shows for adults
|
93
|
+
- Totally amped about the 80s
|
94
|
+
- Do microwave ovens kill bacteria?
|
95
|
+
- Most inspirational movie you have ever seen?
|
96
|
+
- Catching all 151 in 2 hours 😀
|
97
|
+
- Charlie The Unicorn 4
|
98
|
+
- Video Games for Pre-Teens?
|
99
|
+
- Online learning
|
100
|
+
- Mark of the Ninja
|
101
|
+
- Funniest thing you’ve seen today?
|
102
|
+
- Coolest thing you have seen today
|
103
|
+
- Share your Hallowe’en pictures
|
104
|
+
tags:
|
105
|
+
- art
|
106
|
+
- code
|
107
|
+
- official
|
108
|
+
- feedback
|
109
|
+
- fun
|
110
|
+
- dev
|
111
|
+
- design
|
112
|
+
- test
|
113
|
+
- blog
|
114
|
+
- cloud
|
115
|
+
- tv
|
116
|
+
- movies
|
117
|
+
- review
|
118
|
+
- news
|
119
|
+
- link
|
120
|
+
- video
|
121
|
+
- photos
|
122
|
+
- lead
|
123
|
+
- mobile
|
124
|
+
- music
|
125
|
+
- release
|
126
|
+
- notes
|
127
|
+
- todo
|
128
|
+
- duplicate
|
129
|
+
- praise
|
130
|
+
- faq
|
131
|
+
- job-application
|
132
|
+
- rfc
|
133
|
+
- email
|
134
|
+
- wiki
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_dev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinoth Kannan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -65,14 +65,31 @@ files:
|
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
67
67
|
- Rakefile
|
68
|
+
- avatars/03F55412-DE8A-4F83-AAA6-D67EE5CE48DA-200w.jpeg
|
69
|
+
- avatars/1C4EEDC2-FE9C-40B3-A2C9-A038873EE692-200w.jpeg
|
70
|
+
- avatars/26CFEFB3-21C8-49FC-8C19-8E6A62B6D2E0-200w.jpeg
|
71
|
+
- avatars/282A12CA-E0D7-4011-8BDD-1FAFAAB035F7-200w.jpeg
|
72
|
+
- avatars/2DDDE973-40EC-4004-ABC0-73FD4CD6D042-200w.jpeg
|
73
|
+
- avatars/344CFC24-61FB-426C-B3D1-CAD5BCBD3209-200w.jpeg
|
74
|
+
- avatars/852EC6E1-347C-4187-9D42-DF264CCF17BF-200w.jpeg
|
75
|
+
- avatars/A7299C8E-CEFC-47D9-939A-3C8CA0EA4D13-200w.jpeg
|
76
|
+
- avatars/AEF44435-B547-4B84-A2AE-887DFAEE6DDF-200w.jpeg
|
77
|
+
- avatars/B3CF5288-34B0-4A5E-9877-5965522529D6-200w.jpeg
|
78
|
+
- avatars/BA0CB1F2-8C79-4376-B13B-DD5FB8772537-200w.jpeg
|
79
|
+
- avatars/E0B4CAB3-F491-4322-BEF2-208B46748D4A-200w.jpeg
|
80
|
+
- avatars/FBEBF655-4886-455A-A4A4-D62B77DD419B-200w.jpeg
|
81
|
+
- config/routes.rb
|
68
82
|
- discourse_dev.gemspec
|
69
83
|
- lib/discourse_dev.rb
|
70
84
|
- lib/discourse_dev/category.rb
|
71
85
|
- lib/discourse_dev/config.rb
|
72
86
|
- lib/discourse_dev/config.yml
|
87
|
+
- lib/discourse_dev/engine.rb
|
73
88
|
- lib/discourse_dev/group.rb
|
89
|
+
- lib/discourse_dev/post.rb
|
74
90
|
- lib/discourse_dev/railtie.rb
|
75
91
|
- lib/discourse_dev/record.rb
|
92
|
+
- lib/discourse_dev/tag.rb
|
76
93
|
- lib/discourse_dev/tasks/dev.rake
|
77
94
|
- lib/discourse_dev/tasks/populate.rake
|
78
95
|
- lib/discourse_dev/topic.rb
|