nexus_seed 0.2.24 → 0.2.26

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ff72dd41aa6c341c7cebc19a667959db38293f3e2ace20bcb06c848bf7c7f16
4
- data.tar.gz: 06f3a7c8538d4ae779c70781be7f04a45e6da3273014dd46fd377cbe3ee7c85d
3
+ metadata.gz: 350d4fe16dc0c385fc0cede423479292443443cc4ec9df4d6a3ac7883b61d419
4
+ data.tar.gz: 44603e03bd10d0409a42656a6cb0a18b3a50a28a7924a4c6da17a96fee877e9c
5
5
  SHA512:
6
- metadata.gz: 5f2a5f346350499d658724e5c22b9814358e9934e38b288798cf3331286d926c2d4e363ba39e5fb43b1d0a25553ab13a57ced7e4645117d25573c3d33e65a88b
7
- data.tar.gz: 841f6fd9e586d440b3f67c582a86ceca90abb4983223589dc5ab16fe936408172a1b1d59a615977b9aa52d3f6419fbd48e5c95ec4fc167e35486091248adeef9
6
+ metadata.gz: a6504211d65dadb4fb960a7537374eb1fac78d1d359e33560eca4951f0191cd47d8ac7ec9dcca980a1b79e61728e9b41ea704357376f186bac9d777f52f9a518
7
+ data.tar.gz: 6e62cbbcf712396ab18e6ea3f9fb8fcd5a12b7ecd739d10b55e3acd5f2b5e6b59bc0932a4ac8b4533785001b9f2a08a2ed10a853cb0cd38cdbf88c2bc09b30dc
data/.rubocop.yml CHANGED
@@ -8,4 +8,8 @@ Style/ConditionalAssignment:
8
8
  Style/GlobalVars:
9
9
  Enabled: false
10
10
  Style/FrozenStringLiteralComment:
11
- Enabled: false
11
+ Enabled: false
12
+
13
+ AllCops:
14
+ Exclude:
15
+ - 'examples/*'
data/SEED_BUILDER.md CHANGED
@@ -14,9 +14,6 @@ game = NexusSeed::Builder.build(:game,
14
14
  NexusSeed::Builder.build(:forum, { id: ENV['FORUM_COLLECTIONS_ID'] }, { find_by_params: :id })
15
15
  ```
16
16
 
17
- `NexusSeed::Base.transaction` wraps the existing AR transaction and provides some QOL methods such as destroying
18
- previously generated seeds and generating seed reports.
19
-
20
17
  `NexusSeed::Builder.build(:collection_schema)` can be viewed as something
21
18
  mimicking `FactoryBot.create(:collection_schema)`. There are a few key differences, however:
22
19
 
@@ -0,0 +1,272 @@
1
+ # see https://gitlab.nexdev.uk/pub/nexus_seed/-/wikis/Builder-examples for step by step explanation
2
+
3
+ NexusSeed::Builder.build(:collection_schema)
4
+ NexusSeed::Builder.build(:category)
5
+
6
+ game = NexusSeed::Builder.build(:game,
7
+ game_genre: NexusSeed::Builder.build(:game_genre, name: 'Some Game Genre'),
8
+ name: 'Some Random Game'
9
+ )
10
+
11
+ NexusSeed::Builder.build(:forum, { id: ENV['FORUM_COLLECTIONS_ID'] }, { find_by_params: :id })
12
+
13
+ moderation_reasons = [
14
+ {
15
+ reason: "Content used without permission",
16
+ resolution: "Please remove the infringing content or provide evidence of permission."
17
+ },
18
+ {
19
+ reason: "Inappropriate page content",
20
+ resolution: "Please make the necessary changes to this page as outlined in the notes."
21
+ },
22
+ {
23
+ reason: "Improper use of bundled assets",
24
+ resolution: "Please remove the assets you're bundling with your collection."
25
+ },
26
+ {
27
+ reason: "External link(s) to malicious/disreputable source(s)",
28
+ resolution: "Please remove any links to such sites/sources."
29
+ },
30
+ {
31
+ reason: "Collections Guidelines violation",
32
+ resolution: "Please follow the instructions provided in the notes section."
33
+ },
34
+ {
35
+ reason: "Under review",
36
+ resolution: "Your content is being reviewed by our team and has been made temporarily unavailable in the meantime."
37
+ },
38
+ {
39
+ reason: "DMCA investigation",
40
+ resolution: "Please check your inbox/email for a message from staff for details."
41
+ }
42
+ ]
43
+
44
+ moderation_reasons.each do |moderation_reason|
45
+ NexusSeed::Builder.build(:moderation_reason, moderation_reason)
46
+ end
47
+
48
+ # todo START: add into seed rake later
49
+
50
+ users = [
51
+ User.find_by_name!('superadminuser'),
52
+ User.find_by_name!('adminuser'),
53
+ User.find_by_name!('freeuser1'),
54
+ ]
55
+
56
+ mod_files = []
57
+
58
+ def attach_mods_to_revision(mod_files, revision)
59
+ mod_files.each do |mod_file|
60
+ NexusSeed::Builder.build(:collection_revision_mod,
61
+ mod_file: mod_file,
62
+ mod: mod_file.mod,
63
+ game: mod_file.game,
64
+ collection_revision: revision
65
+ )
66
+ end
67
+ end
68
+
69
+ users.each_with_index do |user, index|
70
+ 10.times do |t|
71
+ col = NexusSeed::Builder.build(:collection, slug: "slug#{index}#{t}", user: user, game: game)
72
+ rev = NexusSeed::Builder.build(:collection_revision, collection: col, revision_status: :draft)
73
+
74
+ NexusSeed::Builder.build(:collection_image, image_type: :tile, collection: col, user: user)
75
+
76
+ # create lots of mods
77
+ 31.times do |i|
78
+ mod_file = NexusSeed::Builder.build(:legacy_mod_file,
79
+ name: "Mod File Name #{i} #{t}",
80
+ game: game,
81
+ mod: NexusSeed::Builder.build(:legacy_mod,
82
+ game: game,
83
+ user: User.all.offset(i).first,
84
+ mod_category: ModCategory.last,
85
+ name: "Mod Name #{i} #{t}"
86
+ )
87
+ )
88
+
89
+ NexusSeed::Builder.build(:collection_revision_mod,
90
+ mod_file: mod_file,
91
+ mod: mod_file.mod,
92
+ game: mod_file.game,
93
+ collection_revision: rev
94
+ )
95
+
96
+ mod_files << mod_file
97
+ end
98
+
99
+ 17.times do |i|
100
+ NexusSeed::Builder.build(:external_resource, collection_revision: rev, name: "External Resource #{t} #{i}")
101
+ end
102
+
103
+ game_version = NexusSeed::Builder.build(:game_version, game: game, reference: "1.#{t}.0")
104
+
105
+ unless rev.published?
106
+ rev.game_versions << game_version
107
+ rev.save!
108
+ end
109
+
110
+ changelog_description = "
111
+ ### New Features
112
+ - When opening SSH, FTP, SFTP or SMB links, you’ll now see the option to allow all future URLs from just that same
113
+ domain instead of the whole wide world. A little more secure for us, a little more peace of mind for you.
114
+
115
+ ### Bug Fixes
116
+ - Certain versions of the app were not correctly changing availability to “Away” after 10 minutes of inactivity. While
117
+ this has been fixed, we’d like to remind you that you can use your Custom Status to let your teammates know your
118
+ whereabouts beyond simply Active or Away. Examples include: walking the dog, catching up after PTO, taking a mental
119
+ break, or tweeting nice things to the Slack social media team.
120
+
121
+ ### Security Guidance
122
+ This release includes security improvements. Updating is recommended.
123
+ "
124
+
125
+ NexusSeed::Builder.build(:collection_changelog, collection_revision: rev, description: changelog_description )
126
+
127
+ # create collection images using specific hashes that should exist on b2
128
+ [
129
+ '575d0c50-58e2-4e1c-b3ed-2e709de53356',
130
+ '958da9be-2e2f-4b7e-a709-77715c558ad6',
131
+ '02ed768a-67a4-4f3e-95f4-7ce8fffe19e5',
132
+ 'd39fe07a-4f5e-41ca-a878-711206dbc165',
133
+ '3f19ba7c-3b09-4d8d-9b9c-9dec1f53de57',
134
+ '501cba43-73e7-47d4-943f-1e042bf3a55c',
135
+ ].each_with_index do |uuid, index|
136
+ NexusSeed::Builder.build(:collection_image, {
137
+ id: uuid,
138
+ collection: col,
139
+ collection_revision_id: rev.id,
140
+ user: col.user,
141
+ title: "collection image #{index + 1} title",
142
+ alt_text: "collection image #{index + 1} alt text",
143
+ position: index + 1,
144
+ }, {find_by_params: :id})
145
+ end
146
+
147
+ rev.reload.published! unless rev.published?
148
+ col.reload.listed! unless col.listed?
149
+ end
150
+ end
151
+
152
+ # Collection with one draft revision
153
+ col = NexusSeed::Builder.build(:collection, name: 'Draft 1', slug: 'draft01', user: users[0], game: game)
154
+ rev = NexusSeed::Builder.build(:collection_revision, collection: col, revision_status: :draft)
155
+
156
+ attach_mods_to_revision(mod_files, rev)
157
+
158
+ # Collection with one published revision and one draft revision
159
+ col = NexusSeed::Builder.build(:collection, name: 'Draft 2', slug: "draft02", user: users[0], game: game)
160
+ rev1 = NexusSeed::Builder.build(:collection_revision, collection: col, revision_status: :draft)
161
+
162
+ NexusSeed::Builder.build(:collection_image, image_type: :tile, collection: col, user: users[0])
163
+
164
+ attach_mods_to_revision(mod_files, rev1)
165
+
166
+ rev1.published! unless rev1.published?
167
+ col.listed! unless col.listed?
168
+
169
+ rev2 = NexusSeed::Builder.build(:collection_revision, collection: col, revision_status: :draft)
170
+
171
+ attach_mods_to_revision(mod_files, rev2)
172
+
173
+ # create tags
174
+ 5.times do |i|
175
+ tag_cat = NexusSeed::Builder.build(:tag_category, name: "Tag Category #{i}")
176
+
177
+ 3.times do |t|
178
+ NexusSeed::Builder.build(:tag,
179
+ name: "Normal Tag #{t} #{i}",
180
+ tag_category_id: tag_cat.id
181
+ )
182
+ end
183
+
184
+ 2.times do |t|
185
+ NexusSeed::Builder.build(:tag,
186
+ name: "Global Normal Tag #{t} #{i}",
187
+ global: true,
188
+ tag_category_id: tag_cat.id
189
+ )
190
+ end
191
+
192
+ 2.times do |t|
193
+ NexusSeed::Builder.build(:tag,
194
+ name: "Adult Tag #{t} #{i}",
195
+ adult: true,
196
+ tag_category_id: tag_cat.id
197
+ )
198
+ end
199
+ end
200
+
201
+ Tag.all.each do |tag|
202
+ NexusSeed::Builder.build(:tag_game,
203
+ tag_id: tag.id,
204
+ game_id: game.id,
205
+ ) unless tag.global?
206
+ end
207
+
208
+ # create dl history entries
209
+ dls = {}
210
+
211
+ # collection downloaded 24 hours ago
212
+ collection_dl_24h_ago = Collection.find_by_slug('slug00')
213
+
214
+ dls[collection_dl_24h_ago.game.id.to_s] = [] if dls[collection_dl_24h_ago.game.id.to_s].nil?
215
+ collection_dl_24h_ago.collection_revisions.each do |r|
216
+ # randomize the dl times for easier distinction
217
+ dls[collection_dl_24h_ago.game.id.to_s] << (Time.now - 24.hours).to_i << r.id <<
218
+ collection_dl_24h_ago.id
219
+ end
220
+
221
+ # collection downloaded 1 hour ago
222
+ collection_dl_1h_ago = Collection.find_by_slug('slug01')
223
+
224
+ dls[collection_dl_1h_ago.game.id.to_s] = [] if dls[collection_dl_1h_ago.game.id.to_s].nil?
225
+ collection_dl_1h_ago.collection_revisions.each do |r|
226
+ # randomize the dl times for easier distinction
227
+ dls[collection_dl_1h_ago.game.id.to_s] << (Time.now - 1.hour).to_i << r.id <<
228
+ collection_dl_1h_ago.id
229
+ end
230
+
231
+ free_user = User.find_by(name: 'freeuser5')
232
+
233
+ dls.each do |k, v|
234
+ key = 'cl_' + 8515309.to_s
235
+ # Set object in Redis
236
+ $DL_HISTORY_REDIS.hset(key, k.to_s, v.pack('LLL*'))
237
+ end
238
+
239
+ if free_user.present?
240
+ dls.each do |k, v|
241
+ key = 'cl_' + free_user.id.to_s
242
+ # Set object in Redis
243
+ $DL_HISTORY_REDIS.hset(key, k.to_s, v.pack('LLL*'))
244
+ end
245
+ end
246
+
247
+ # Ensure modCount can be calculated
248
+ CollectionRevision.find_each do |revision|
249
+ CollectionRevision.reset_counters(revision.id, :collection_revision_mods)
250
+ CollectionRevision.reset_counters(revision.id, :external_resources)
251
+ rescue => error
252
+ p("Error seeding reset_counts: #{error.message}")
253
+ end
254
+
255
+ # Collection with one published revision and one draft revision
256
+ bug_col = NexusSeed::Builder.build(:collection, name: 'Draft 2', slug: "draft02", user: users[0], game: game)
257
+ rev1 = NexusSeed::Builder.build(:collection_revision, collection: bug_col, revision_status: :draft)
258
+
259
+ NexusSeed::Builder.build(:collection_image, image_type: :tile, collection: bug_col, user: users[0])
260
+
261
+ attach_mods_to_revision(mod_files, rev1)
262
+
263
+ rev1.published! unless rev1.published?
264
+ bug_col.listed! unless bug_col.listed?
265
+
266
+ # Collection bug reports
267
+ 50.times do |_i|
268
+ bug_report = NexusSeed::Builder.build(:bug_report, title: "Bug Report #{_i}", reporter: free_user)
269
+ NexusSeed::Builder.build(:collection_bug_report, collection: bug_col, bug_report: bug_report)
270
+ end
271
+
272
+ Collection.import
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # this task should be placed to lib/tasks. See SEED_BUILDER.md for documentation
4
+
5
+ require 'nexus_seed'
6
+
7
+ namespace :seed_common do
8
+ desc 'Common users seeds'
9
+ task :run, [:retry_limit, :sleep_interval] => [:environment] do |_task, opts|
10
+ include NexusSeed
11
+ task_options(opts)
12
+
13
+ # Common seed contains user creation which must be done in order, to avoid concurrent PK duplicates
14
+ # due to our usage of static IDs for some seed data.
15
+ def seed
16
+ seed_adult_content_hidden
17
+ seed_tos_users
18
+ seed_mod_authors
19
+ end
20
+
21
+ run
22
+ end
23
+
24
+ # Users with adult content hidden.
25
+ def seed_adult_content_hidden
26
+ (1..5).each do |i|
27
+ user = NexusSeed::Builder.build(:user, name: "hideadultcontent#{i}")
28
+ encrypted_password = User.new.send(:password_digest, 'Password1234')
29
+
30
+ NexusSeed::Builder.build(:members_preference, mid: user.member_id, adult: 0)
31
+ NexusSeed::Builder.build(:user_password,
32
+ user_id: user.member_id,
33
+ encrypted_password: encrypted_password)
34
+ end
35
+ end
36
+
37
+ # Users with no ToS signed.
38
+ def seed_tos_users
39
+ unsigned_tos_users = []
40
+ (1..5).each do |i|
41
+ user = NexusSeed::Builder.build(:user, name: "notosuser#{i}")
42
+ encrypted_password = User.new.send(:password_digest, 'Password1234')
43
+
44
+ NexusSeed::Builder.build(:user_password,
45
+ user_id: user.member_id,
46
+ encrypted_password: encrypted_password)
47
+
48
+ unsigned_tos_users << user.member_id
49
+ end
50
+
51
+ # we have to delete the ToS agreements after creating the user as they are automatically generated in after_create
52
+ # in the user model
53
+ TosAgreement.where(user_id: unsigned_tos_users).destroy_all
54
+ end
55
+
56
+ # Mod author accounts known to be used by seeds in other components.
57
+ def seed_mod_authors
58
+ # freeuser1 will be located in API seeds by name, their specific ID does not matter.
59
+ NexusSeed::Builder.build(:user, name: 'freeuser1')
60
+
61
+ # IDs are not typically set in seeds, but these user IDs must match data seeded in the api and wallet components.
62
+ mod_author_starting_id = 40100200
63
+ mod_author_seed_quantity = 5
64
+ (1..mod_author_seed_quantity).each do |i|
65
+ NexusSeed::Builder.build(:user, name: "modauthor#{i}", member_id: mod_author_starting_id + (i - 1))
66
+ end
67
+ end
68
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusSeed
3
- # Leave this as 0.2.24 in order for CI process to replace with the tagged version.
4
- VERSION = '0.2.24'
3
+ # Leave this as 0.2.26 in order for CI process to replace with the tagged version.
4
+ VERSION = '0.2.26'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_seed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 0.2.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnathon Harris
@@ -36,6 +36,8 @@ files:
36
36
  - Gemfile
37
37
  - README.md
38
38
  - SEED_BUILDER.md
39
+ - examples/nexus-api-seeds.rb
40
+ - examples/user-service-seed-task.rb
39
41
  - lib/nexus_seed.rb
40
42
  - lib/nexus_seed/builder.rb
41
43
  - lib/nexus_seed/builder/base.rb