mirror of
https://github.com/mastodon/mastodon.git
synced 2026-09-11 19:27:19 -05:00
Add Json schema validation for action logs (#39670)
This commit is contained in:
@@ -38,8 +38,8 @@ module Admin
|
||||
|
||||
def log_action_from_change
|
||||
action_log = current_account.action_logs.new(action: 'update', target: @tag)
|
||||
|
||||
action_log.recorded_changes = @tag.saved_changes.slice('usable', 'trendable', 'listable').transform_values(&:last)
|
||||
action_log.recorded_changes_format = 'tags_format_1.0'
|
||||
action_log.save
|
||||
end
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ module Admin::ActionLogsHelper
|
||||
end
|
||||
|
||||
def permutation_of_key(log, key)
|
||||
# we're utilizing the store_accessors here, to get the values from the jsonb like: log.listable => true
|
||||
return if log.public_send(key).nil?
|
||||
|
||||
log.public_send(key) ? key : :"not_#{key}"
|
||||
|
||||
@@ -20,12 +20,18 @@ RSpec.describe 'Admin Tags' do
|
||||
let(:tag) { Fabricate :tag, name: '#supertag' }
|
||||
|
||||
it 'redirects to tag page and saves update log action for all attribute statuses' do
|
||||
put admin_tag_path(tag.id, params: { tag: { trendable: true, listable: false } })
|
||||
put admin_tag_path(tag.id, params: { tag: { trendable: true, listable: false, unallowed: true } })
|
||||
|
||||
expect(response).to have_http_status(302)
|
||||
expect(Admin::ActionLog.last.human_identifier).to eq('#supertag')
|
||||
expect(Admin::ActionLog.pluck(:action)).to eq(%w(update))
|
||||
expect(Admin::ActionLog.pluck(:recorded_changes)).to eq([{ 'listable' => false, 'trendable' => true }])
|
||||
expect(Admin::ActionLog.last.recorded_changes).to match_json_schema('tags_format_1.0')
|
||||
end
|
||||
|
||||
it 'returns invalid when the schema does not match' do
|
||||
put admin_tag_path(tag.id, params: { tag: { trendable: true } })
|
||||
|
||||
Admin::ActionLog.last.update(recorded_changes: { 'unallowed' => false })
|
||||
expect(Admin::ActionLog.last.recorded_changes).to_not match_json_schema('tags_format_1.0')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
9
spec/support/schema/tags_format_1.0.json
Normal file
9
spec/support/schema/tags_format_1.0.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"usable": { "type": "boolean" },
|
||||
"trendable": { "type": "boolean" },
|
||||
"listable": { "type": "boolean" }
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
Reference in New Issue
Block a user