Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
20e832d5
Unverified
Commit
20e832d5
authored
2 years ago
by
Sébastien Gaya
Browse files
Options
Downloads
Patches
Plain Diff
service + task
parent
5e83a464
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/services/active_storage_key_converter.rb
+19
-0
19 additions, 0 deletions
app/services/active_storage_key_converter.rb
app/services/blocks_migration.rb
+30
-0
30 additions, 0 deletions
app/services/blocks_migration.rb
lib/tasks/app.rake
+1
-0
1 addition, 0 deletions
lib/tasks/app.rake
with
50 additions
and
0 deletions
app/services/active_storage_key_converter.rb
0 → 100644
+
19
−
0
View file @
20e832d5
class
ActiveStorageKeyConverter
def
self
.
convert
(
legacy_signed_id
)
# Try to find blob with the un-modified legacy_signed_id
blob
=
ActiveStorage
::
Blob
.
find_signed!
(
legacy_signed_id
)
legacy_signed_id
rescue
ActiveSupport
::
MessageVerifier
::
InvalidSignature
#
key_generator
=
ActiveSupport
::
KeyGenerator
.
new
(
Rails
.
application
.
secrets
.
secret_key_base
,
iterations:
1000
,
hash_digest_class:
OpenSSL
::
Digest
::
SHA1
)
key_generator
=
ActiveSupport
::
CachingKeyGenerator
.
new
(
key_generator
)
secret
=
key_generator
.
generate_key
(
"ActiveStorage"
)
verifier
=
ActiveSupport
::
MessageVerifier
.
new
(
secret
)
ActiveStorage
::
Blob
.
find_by_id
(
verifier
.
verify
(
legacy_signed_id
,
purpose: :blob_id
)).
try
(
:signed_id
)
end
end
This diff is collapsed.
Click to expand it.
app/services/blocks_migration.rb
0 → 100644
+
30
−
0
View file @
20e832d5
class
BlocksMigration
def
self
.
cleanup
Communication
::
Block
.
all
.
find_each
{
|
block
|
self
.
crawl
(
block
.
data
)
block
.
save
}
end
protected
def
self
.
crawl
(
enumerable
)
case
enumerable
when
Array
enumerable
.
each
do
|
item
|
crawl
(
item
)
if
[
Array
,
Hash
].
include?
(
item
.
class
)
end
when
Hash
enumerable
.
keys
.
each
do
|
key
|
if
key
==
"signed_id"
# Convert value
enumerable
[
key
]
=
ActiveStorageKeyConverter
.
convert
(
enumerable
[
key
])
if
key
==
"signed_id"
elsif
[
Array
,
Hash
].
include?
(
enumerable
[
key
].
class
)
crawl
(
enumerable
[
key
])
end
end
end
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/tasks/app.rake
+
1
−
0
View file @
20e832d5
...
...
@@ -8,6 +8,7 @@ namespace :app do
desc
'Fix things'
task
fix: :environment
do
BlocksMigration
.
cleanup
end
namespace
:websites
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment