mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
FEATURE: Watched words improvements (#7899)
This commit contains 3 features: - FEATURE: Allow downloading watched words This introduces a button that allows admins to download watched words per action in a `.txt` file. - FEATURE: Allow clearing watched words in bulk This adds a "Clear All" button that clears all deleted words per action (e.g. block, flag etc.) - FEATURE: List all blocked words contained in the post when it's blocked When a post is rejected because it contains one or more blocked words, the error message now lists all the blocked words contained in the post. ------- This also changes the format of the file for importing watched words from `.csv` to `.txt` so it becomes inconsistent with the extension of the file when watched words are exported.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::WatchedWordsController < Admin::AdminController
|
||||
skip_before_action :check_xhr, only: [:download]
|
||||
|
||||
def index
|
||||
render_json_dump WatchedWordListSerializer.new(WatchedWord.by_action, scope: guardian, root: false)
|
||||
@ -35,12 +36,36 @@ class Admin::WatchedWordsController < Admin::AdminController
|
||||
rescue => e
|
||||
data = failed_json.merge(errors: [e.message])
|
||||
end
|
||||
MessageBus.publish("/uploads/csv", data.as_json, client_ids: [params[:client_id]])
|
||||
MessageBus.publish("/uploads/txt", data.as_json, client_ids: [params[:client_id]])
|
||||
end
|
||||
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
def download
|
||||
params.require(:id)
|
||||
name = watched_words_params[:id].to_sym
|
||||
action = WatchedWord.actions[name]
|
||||
raise Discourse::NotFound if !action
|
||||
|
||||
content = WatchedWord.where(action: action).pluck(:word).join("\n")
|
||||
headers['Content-Length'] = content.bytesize.to_s
|
||||
send_data content,
|
||||
filename: "#{Discourse.current_hostname}-watched-words-#{name}.txt",
|
||||
content_type: "text/plain"
|
||||
end
|
||||
|
||||
def clear_all
|
||||
params.require(:id)
|
||||
name = watched_words_params[:id].to_sym
|
||||
action = WatchedWord.actions[name]
|
||||
raise Discourse::NotFound if !action
|
||||
|
||||
WatchedWord.where(action: action).delete_all
|
||||
WordWatcher.clear_cache!
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def watched_words_params
|
||||
|
Reference in New Issue
Block a user