mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-06 09:51:24 +00:00
Whole word import/export
This commit is contained in:
parent
3e6fac42c1
commit
9c9dd66129
|
@ -56,9 +56,9 @@ class Export
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_filters_csv
|
def to_filters_csv
|
||||||
CSV.generate(headers: ['Title', 'Context', 'Keywords', 'Action', 'Expire after'], write_headers: true) do |csv|
|
CSV.generate(headers: ['Title', 'Context', 'Keywords', 'Whole Word', 'Action', 'Expire after'], write_headers: true) do |csv|
|
||||||
account.custom_filters.reorder(id: :desc).each do |filter|
|
account.custom_filters.reorder(id: :desc).each do |filter|
|
||||||
csv << [filter.title, filter.context, filter.keywords.map(&:keyword), filter.action, filter.expires_at]
|
csv << [filter.title, filter.context, filter.keywords.map(&:keyword), filter.keywords.map(&:whole_word), filter.action, filter.expires_at]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Form::Import
|
||||||
domain_blocking: ['#domain'],
|
domain_blocking: ['#domain'],
|
||||||
bookmarks: ['#uri'],
|
bookmarks: ['#uri'],
|
||||||
lists: ['List name', 'Account address'],
|
lists: ['List name', 'Account address'],
|
||||||
filters: ['Title', 'Context', 'Keywords', 'Action', 'Expire after'],
|
filters: ['Title', 'Context', 'Keywords', 'Whole Word', 'Action', 'Expire after'],
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
KNOWN_FIRST_HEADERS = EXPECTED_HEADERS_BY_TYPE.values.map(&:first).uniq.freeze
|
KNOWN_FIRST_HEADERS = EXPECTED_HEADERS_BY_TYPE.values.map(&:first).uniq.freeze
|
||||||
|
@ -38,6 +38,7 @@ class Form::Import
|
||||||
'Title' => 'title',
|
'Title' => 'title',
|
||||||
'Context' => 'context',
|
'Context' => 'context',
|
||||||
'Keywords' => 'keywords',
|
'Keywords' => 'keywords',
|
||||||
|
'Whole Word' => 'whole_word',
|
||||||
'Action' => 'action',
|
'Action' => 'action',
|
||||||
'Expire after' => 'expires_at',
|
'Expire after' => 'expires_at',
|
||||||
}.freeze
|
}.freeze
|
||||||
|
@ -124,7 +125,7 @@ class Form::Import
|
||||||
case type.to_sym
|
case type.to_sym
|
||||||
when :filters
|
when :filters
|
||||||
case field_info.header
|
case field_info.header
|
||||||
when 'Context', 'Keywords'
|
when 'Context', 'Keywords', 'Whole Word'
|
||||||
Oj.load(field)
|
Oj.load(field)
|
||||||
when 'Expire after'
|
when 'Expire after'
|
||||||
field.blank? ? nil : Time.zone.parse(field)
|
field.blank? ? nil : Time.zone.parse(field)
|
||||||
|
|
|
@ -42,7 +42,7 @@ class BulkImportRowService
|
||||||
when :filters
|
when :filters
|
||||||
filter = @account.custom_filters.find_or_initialize_by(title: @data['title'])
|
filter = @account.custom_filters.find_or_initialize_by(title: @data['title'])
|
||||||
filter.context = @data['context']
|
filter.context = @data['context']
|
||||||
filter.keywords = @data['keywords'].map { |keyword| CustomFilterKeyword.new(keyword: keyword) }
|
filter.keywords = @data['keywords'].map.with_index { |keyword, i| CustomFilterKeyword.new(keyword: keyword, whole_word: @data['whole_word'][i]) }
|
||||||
filter.action = @data['action'].to_sym
|
filter.action = @data['action'].to_sym
|
||||||
filter.expires_at = @data['expires_at']
|
filter.expires_at = @data['expires_at']
|
||||||
filter.save!
|
filter.save!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user