mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 07:08:44 +08:00
f14c6d81f4
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.
107 lines
2.8 KiB
JavaScript
107 lines
2.8 KiB
JavaScript
import computed from "ember-addons/ember-computed-decorators";
|
|
import WatchedWord from "admin/models/watched-word";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import { fmt } from "discourse/lib/computed";
|
|
|
|
export default Ember.Controller.extend({
|
|
actionNameKey: null,
|
|
adminWatchedWords: Ember.inject.controller(),
|
|
showWordsList: Ember.computed.or(
|
|
"adminWatchedWords.filtered",
|
|
"adminWatchedWords.showWords"
|
|
),
|
|
downloadLink: fmt(
|
|
"actionNameKey",
|
|
"/admin/logs/watched_words/action/%@/download"
|
|
),
|
|
|
|
findAction(actionName) {
|
|
return (this.get("adminWatchedWords.model") || []).findBy(
|
|
"nameKey",
|
|
actionName
|
|
);
|
|
},
|
|
|
|
@computed("actionNameKey", "adminWatchedWords.model")
|
|
currentAction(actionName) {
|
|
return this.findAction(actionName);
|
|
},
|
|
|
|
@computed("currentAction.words.[]", "adminWatchedWords.model")
|
|
filteredContent(words) {
|
|
return words || [];
|
|
},
|
|
|
|
@computed("actionNameKey")
|
|
actionDescription(actionNameKey) {
|
|
return I18n.t("admin.watched_words.action_descriptions." + actionNameKey);
|
|
},
|
|
|
|
@computed("currentAction.count")
|
|
wordCount(count) {
|
|
return count || 0;
|
|
},
|
|
|
|
actions: {
|
|
recordAdded(arg) {
|
|
const a = this.findAction(this.actionNameKey);
|
|
if (a) {
|
|
a.words.unshiftObject(arg);
|
|
a.incrementProperty("count");
|
|
Ember.run.schedule("afterRender", () => {
|
|
// remove from other actions lists
|
|
let match = null;
|
|
this.get("adminWatchedWords.model").forEach(action => {
|
|
if (match) return;
|
|
|
|
if (action.nameKey !== this.actionNameKey) {
|
|
match = action.words.findBy("id", arg.id);
|
|
if (match) {
|
|
action.words.removeObject(match);
|
|
action.decrementProperty("count");
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
},
|
|
|
|
recordRemoved(arg) {
|
|
if (this.currentAction) {
|
|
this.currentAction.words.removeObject(arg);
|
|
this.currentAction.decrementProperty("count");
|
|
}
|
|
},
|
|
|
|
uploadComplete() {
|
|
WatchedWord.findAll().then(data => {
|
|
this.set("adminWatchedWords.model", data);
|
|
});
|
|
},
|
|
|
|
clearAll() {
|
|
const actionKey = this.actionNameKey;
|
|
bootbox.confirm(
|
|
I18n.t(`admin.watched_words.clear_all_confirm_${actionKey}`),
|
|
I18n.t("no_value"),
|
|
I18n.t("yes_value"),
|
|
result => {
|
|
if (result) {
|
|
ajax(`/admin/logs/watched_words/action/${actionKey}.json`, {
|
|
method: "DELETE"
|
|
}).then(() => {
|
|
const action = this.findAction(actionKey);
|
|
if (action) {
|
|
action.setProperties({
|
|
words: [],
|
|
count: 0
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
);
|
|
}
|
|
}
|
|
});
|