Skip to content

Commit

Permalink
FIX: avoid deprecated replace_flag API
Browse files Browse the repository at this point in the history
`replace_flag` API will be deprecated. Therefore `malicious_file` score type must be entered into the database. In addition, migration is fixing IDs.
  • Loading branch information
lis2 committed May 28, 2024
1 parent aeaff25 commit 8606486
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 29 additions & 0 deletions db/migrate/20240527061406_add_malicious_file_score_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

class AddMaliciousFileScoreType < ActiveRecord::Migration[7.0]
def change
result = DB.query <<~SQL
SELECT MAX(position) FROM flags
SQL

position = result.last&.max

result = DB.query <<~SQL
INSERT INTO flags(name, name_key, applies_to, score_type, position, created_at, updated_at)
VALUES ('Malicious File', 'malicious_file', '{}', true, #{position.to_i + 1}, NOW(), NOW())
RETURNING flags.id
SQL

new_score_id = result.last&.id

DB.exec <<~SQL
UPDATE reviewable_scores rs1
SET reviewable_score_type = #{new_score_id}
FROM reviewable_scores rs2
LEFT JOIN reviewables ON reviewables.id = rs2.reviewable_id
WHERE rs2.reason = 'malicious_file'
AND reviewables.type = 'ReviewableUpload'
AND rs1.id = rs2.id
SQL
end
end
2 changes: 0 additions & 2 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

register_reviewable_type ReviewableUpload

replace_flags(settings: PostActionType.flag_settings, score_type_names: %i[malicious_file])

add_to_serializer(
:site,
:clamav_unreacheable,
Expand Down

0 comments on commit 8606486

Please sign in to comment.