discourse_dev 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/discourse_dev.gemspec +3 -3
- data/lib/discourse_dev/category.rb +43 -8
- data/lib/discourse_dev/config.rb +46 -0
- data/lib/discourse_dev/config.yml +3 -0
- data/lib/discourse_dev/group.rb +44 -0
- data/lib/discourse_dev/record.rb +4 -7
- data/lib/discourse_dev/tasks/dev.rake +8 -0
- data/lib/discourse_dev/tasks/populate.rake +10 -0
- data/lib/discourse_dev/topic.rb +1 -1
- data/lib/discourse_dev/user.rb +14 -0
- data/lib/discourse_dev/version.rb +1 -1
- data/lib/faker/discourse.rb +4 -0
- data/lib/faker/locales/en.yml +44 -1
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f6b6919dea52805f8b6b7f561e77d3101e447c93dc307eeac4b8638580f065c
|
4
|
+
data.tar.gz: 9694e92b6004f660b7feac692523a7c5551d75e2bedb4ebe5b7b81a2ca9378a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e84c18461298fd93b39bb9af3950a09dc8c79cdcc44cbea8aba8bdac0f45c680d497e4468b35e8598cdee7d437e81e8b66b97b954f99a4cc5af4c29a91c2fc1
|
7
|
+
data.tar.gz: 5cd31e7f82f8cac62a7efa69626ea26da804b43b7e16e95e0c7aef0ce95c3c900914e6d2427209bc551a27bfa8ab8c1691dc21153d6b7d89290f973ef31eeb17
|
data/README.md
CHANGED
data/discourse_dev.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ["Vinoth Kannan"]
|
11
11
|
spec.email = ["svkn.87@gmail.com"]
|
12
12
|
|
13
|
-
spec.summary = %q{Rake helper for Discourse developers}
|
14
|
-
spec.description = %q{Rake helper for Discourse developers}
|
13
|
+
spec.summary = %q{Rake helper tasks for Discourse developers}
|
14
|
+
spec.description = %q{Rake helper tasks for Discourse developers}
|
15
15
|
spec.homepage = "https://github.com/discourse/discourse_dev"
|
16
16
|
spec.license = "MIT"
|
17
17
|
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_runtime_dependency "faker", "~> 2.16"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 2.0"
|
24
|
-
spec.add_development_dependency "rake", "
|
24
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
25
25
|
|
26
26
|
spec.required_ruby_version = '>= 2.6.0'
|
27
27
|
end
|
@@ -9,21 +9,56 @@ module DiscourseDev
|
|
9
9
|
|
10
10
|
def initialize(count = DEFAULT_COUNT)
|
11
11
|
super(::Category, count)
|
12
|
+
@existing_names = ::Category.pluck(:name)
|
13
|
+
@parent_category_ids = ::Category.where(parent_category_id: nil).pluck(:id)
|
14
|
+
@group_count = ::Group.count
|
12
15
|
end
|
13
16
|
|
14
17
|
def data
|
15
|
-
name = Faker::
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
name = Faker::Discourse.category
|
19
|
+
parent_category_id = nil
|
20
|
+
|
21
|
+
while @existing_names.include? name
|
22
|
+
name = Faker::Discourse.category
|
23
|
+
end
|
24
|
+
|
25
|
+
@existing_names << name
|
26
|
+
|
27
|
+
if Faker::Boolean.boolean(true_ratio: 0.6)
|
28
|
+
parent_category_id = @parent_category_ids.sample
|
29
|
+
@permissions = ::Category.find(parent_category_id).permissions_params.presence
|
30
|
+
else
|
31
|
+
@permissions = nil
|
32
|
+
end
|
19
33
|
|
20
34
|
{
|
21
35
|
name: name,
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
36
|
+
description: Faker::Lorem.paragraph,
|
37
|
+
user_id: ::Discourse::SYSTEM_USER_ID,
|
38
|
+
color: Faker::Color.hex_color.last(6),
|
39
|
+
parent_category_id: parent_category_id
|
26
40
|
}
|
27
41
|
end
|
42
|
+
|
43
|
+
def permissions
|
44
|
+
return @permissions if @permissions.present?
|
45
|
+
return { everyone: :full } if Faker::Boolean.boolean(true_ratio: 0.75)
|
46
|
+
|
47
|
+
permission = {}
|
48
|
+
offset = rand(@group_count)
|
49
|
+
group = ::Group.offset(offset).first
|
50
|
+
permission[group.id] = Faker::Number.between(from: 1, to: 3)
|
51
|
+
|
52
|
+
permission
|
53
|
+
end
|
54
|
+
|
55
|
+
def create!
|
56
|
+
super do |category|
|
57
|
+
category.set_permissions(permissions)
|
58
|
+
category.save!
|
59
|
+
|
60
|
+
@parent_category_ids << category.id if category.parent_category_id.blank?
|
61
|
+
end
|
62
|
+
end
|
28
63
|
end
|
29
64
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
module DiscourseDev
|
6
|
+
class Config
|
7
|
+
attr_reader :config, :default_config
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@default_config = YAML.load_file(File.join(File.expand_path(__dir__), "config.yml"))
|
11
|
+
file_path = File.join(Rails.root, "config", "dev.yml")
|
12
|
+
|
13
|
+
if File.exists?(file_path)
|
14
|
+
@config = YAML.load_file(file_path)
|
15
|
+
else
|
16
|
+
@config = {}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def update!
|
21
|
+
update_site_settings
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_site_settings
|
25
|
+
puts "Updating site settings..."
|
26
|
+
|
27
|
+
site_settings = config["site_settings"] || {}
|
28
|
+
|
29
|
+
site_settings.each do |key, value|
|
30
|
+
puts "#{key} = #{value}"
|
31
|
+
SiteSetting.set(key, value)
|
32
|
+
end
|
33
|
+
|
34
|
+
keys = site_settings.keys
|
35
|
+
|
36
|
+
default_config["site_settings"].each do |key, value|
|
37
|
+
next if keys.include?(key)
|
38
|
+
|
39
|
+
puts "#{key} = #{value}"
|
40
|
+
SiteSetting.set(key, value)
|
41
|
+
end
|
42
|
+
|
43
|
+
SiteSetting.refresh!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'discourse_dev/record'
|
4
|
+
require 'rails'
|
5
|
+
require 'faker'
|
6
|
+
|
7
|
+
module DiscourseDev
|
8
|
+
class Group < Record
|
9
|
+
|
10
|
+
DEFAULT_COUNT = 15.freeze
|
11
|
+
|
12
|
+
def initialize(count = DEFAULT_COUNT)
|
13
|
+
super(::Group, count)
|
14
|
+
@existing_names = ::Group.where(automatic: false).pluck(:name)
|
15
|
+
end
|
16
|
+
|
17
|
+
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
|
+
{
|
27
|
+
name: name,
|
28
|
+
public_exit: Faker::Boolean.boolean,
|
29
|
+
public_admission: Faker::Boolean.boolean,
|
30
|
+
primary_group: Faker::Boolean.boolean
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def create!
|
35
|
+
super do |group|
|
36
|
+
if Faker::Boolean.boolean
|
37
|
+
group.add_owner(::Discourse.system_user)
|
38
|
+
group.allow_membership_requests = true
|
39
|
+
group.save!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/discourse_dev/record.rb
CHANGED
@@ -8,7 +8,7 @@ module DiscourseDev
|
|
8
8
|
class Record
|
9
9
|
DEFAULT_COUNT = 30.freeze
|
10
10
|
|
11
|
-
attr_reader :model, :type
|
11
|
+
attr_reader :model, :type, :count
|
12
12
|
|
13
13
|
def initialize(model, count = DEFAULT_COUNT)
|
14
14
|
@model = model
|
@@ -17,20 +17,17 @@ module DiscourseDev
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def create!
|
20
|
-
model.create!(data)
|
20
|
+
record = model.create!(data)
|
21
|
+
yield(record)
|
21
22
|
putc "."
|
22
23
|
end
|
23
24
|
|
24
25
|
def populate!
|
25
|
-
puts "Creating #{count} sample #{type.downcase}
|
26
|
+
puts "Creating #{count} sample #{type.downcase} records"
|
26
27
|
count.times { create! }
|
27
28
|
puts
|
28
29
|
end
|
29
30
|
|
30
|
-
def count
|
31
|
-
@count || DEFAULT_COUNT
|
32
|
-
end
|
33
|
-
|
34
31
|
def self.populate!
|
35
32
|
self.new.populate!
|
36
33
|
end
|
@@ -11,12 +11,20 @@ task 'dev:reset' => ['db:load_config'] do |_, args|
|
|
11
11
|
check_environment!
|
12
12
|
|
13
13
|
Rake::Task['db:migrate:reset'].invoke
|
14
|
+
Rake::Task['dev:config'].invoke
|
14
15
|
Rake::Task['admin:create'].invoke
|
15
16
|
Rake::Task['dev:populate'].invoke
|
16
17
|
end
|
17
18
|
|
19
|
+
desc 'Initialize development environment'
|
20
|
+
task 'dev:config' => ['db:load_config'] do |_, args|
|
21
|
+
DiscourseDev::Config.new.update!
|
22
|
+
end
|
23
|
+
|
18
24
|
desc 'Populate sample content for development environment'
|
19
25
|
task 'dev:populate' => ['db:load_config'] do |_, args|
|
26
|
+
Rake::Task['groups:populate'].invoke
|
20
27
|
Rake::Task['users:populate'].invoke
|
28
|
+
Rake::Task['categories:populate'].invoke
|
21
29
|
Rake::Task['topics:populate'].invoke
|
22
30
|
end
|
@@ -1,10 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
desc 'Creates sample categories'
|
4
|
+
task 'groups:populate' => ['db:load_config'] do |_, args|
|
5
|
+
DiscourseDev::Group.populate!
|
6
|
+
end
|
7
|
+
|
3
8
|
desc 'Creates sample user accounts'
|
4
9
|
task 'users:populate' => ['db:load_config'] do |_, args|
|
5
10
|
DiscourseDev::User.populate!
|
6
11
|
end
|
7
12
|
|
13
|
+
desc 'Creates sample categories'
|
14
|
+
task 'categories:populate' => ['db:load_config'] do |_, args|
|
15
|
+
DiscourseDev::Category.populate!
|
16
|
+
end
|
17
|
+
|
8
18
|
desc 'Creates sample topics'
|
9
19
|
task 'topics:populate' => ['db:load_config'] do |_, args|
|
10
20
|
DiscourseDev::Topic.populate!
|
data/lib/discourse_dev/topic.rb
CHANGED
@@ -16,7 +16,7 @@ module DiscourseDev
|
|
16
16
|
{
|
17
17
|
title: Faker::Lorem.sentence(word_count: 3, supplemental: true, random_words_to_add: 4).chomp(".")[0, SiteSetting.max_topic_title_length],
|
18
18
|
raw: Faker::Markdown.sandwich(sentences: 5),
|
19
|
-
|
19
|
+
category: @category_ids.sample,
|
20
20
|
topic_opts: { custom_fields: { dev_sample: true } },
|
21
21
|
skip_validations: true
|
22
22
|
}
|
data/lib/discourse_dev/user.rb
CHANGED
@@ -9,6 +9,8 @@ module DiscourseDev
|
|
9
9
|
|
10
10
|
def initialize(count = DEFAULT_COUNT)
|
11
11
|
super(::User, count)
|
12
|
+
@groups = ::Group.where(automatic: false)
|
13
|
+
@group_count = @groups.count
|
12
14
|
end
|
13
15
|
|
14
16
|
def data
|
@@ -22,8 +24,20 @@ module DiscourseDev
|
|
22
24
|
email: email,
|
23
25
|
username: username,
|
24
26
|
username_lower: username_lower,
|
27
|
+
moderator: Faker::Boolean.boolean(true_ratio: 0.1),
|
25
28
|
trust_level: Faker::Number.between(from: 1, to: 4)
|
26
29
|
}
|
27
30
|
end
|
31
|
+
|
32
|
+
def create!
|
33
|
+
super do |user|
|
34
|
+
Faker::Number.between(from: 0, to: 2).times do
|
35
|
+
offset = rand(@group_count)
|
36
|
+
group = @groups.offset(offset).first
|
37
|
+
|
38
|
+
group.add(user)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
28
42
|
end
|
29
43
|
end
|
data/lib/faker/discourse.rb
CHANGED
data/lib/faker/locales/en.yml
CHANGED
@@ -4,7 +4,6 @@ en:
|
|
4
4
|
categories:
|
5
5
|
- movies
|
6
6
|
- tech
|
7
|
-
- general
|
8
7
|
- videos
|
9
8
|
- gaming
|
10
9
|
- sports
|
@@ -19,3 +18,47 @@ en:
|
|
19
18
|
- announcements
|
20
19
|
- bug
|
21
20
|
- community
|
21
|
+
- Events
|
22
|
+
- Education
|
23
|
+
- General Discussion
|
24
|
+
- News
|
25
|
+
- Suggestions
|
26
|
+
- Introduce Yourself
|
27
|
+
- Frequently Asked Questions
|
28
|
+
- Off-Topic
|
29
|
+
- Expert Advice
|
30
|
+
- Home and Living
|
31
|
+
- Babies and Kids
|
32
|
+
- International
|
33
|
+
- Partners
|
34
|
+
- Getting Started
|
35
|
+
- Creator's Corner
|
36
|
+
- Feature Requests
|
37
|
+
- Other Languages
|
38
|
+
- Travelling
|
39
|
+
- Recipes
|
40
|
+
- Newbies
|
41
|
+
- Covid-19
|
42
|
+
- Resources
|
43
|
+
- Docs
|
44
|
+
- Publishing
|
45
|
+
- Marketplace
|
46
|
+
- Community Guidelines
|
47
|
+
- Archived
|
48
|
+
- Meta
|
49
|
+
- Software and Operating Systems
|
50
|
+
- Arts & Media
|
51
|
+
- Science and Engineering
|
52
|
+
- Quizzes and Challenges
|
53
|
+
- Politics
|
54
|
+
- Roadmap
|
55
|
+
- Share Tips and Tricks
|
56
|
+
groups:
|
57
|
+
- team
|
58
|
+
- designers
|
59
|
+
- authors
|
60
|
+
- contributors
|
61
|
+
- customers
|
62
|
+
- subscribers
|
63
|
+
- creators
|
64
|
+
- translators
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinoth Kannan
|
@@ -42,17 +42,17 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 12.3.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
description: Rake helper for Discourse developers
|
54
|
+
version: 12.3.3
|
55
|
+
description: Rake helper tasks for Discourse developers
|
56
56
|
email:
|
57
57
|
- svkn.87@gmail.com
|
58
58
|
executables: []
|
@@ -68,6 +68,9 @@ files:
|
|
68
68
|
- discourse_dev.gemspec
|
69
69
|
- lib/discourse_dev.rb
|
70
70
|
- lib/discourse_dev/category.rb
|
71
|
+
- lib/discourse_dev/config.rb
|
72
|
+
- lib/discourse_dev/config.yml
|
73
|
+
- lib/discourse_dev/group.rb
|
71
74
|
- lib/discourse_dev/railtie.rb
|
72
75
|
- lib/discourse_dev/record.rb
|
73
76
|
- lib/discourse_dev/tasks/dev.rake
|
@@ -99,5 +102,5 @@ requirements: []
|
|
99
102
|
rubygems_version: 3.0.3
|
100
103
|
signing_key:
|
101
104
|
specification_version: 4
|
102
|
-
summary: Rake helper for Discourse developers
|
105
|
+
summary: Rake helper tasks for Discourse developers
|
103
106
|
test_files: []
|