From ec85b410783b24a2ff2ef666c3b56eaf5558fa94 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 31 Jul 2017 17:06:26 -0400 Subject: [PATCH] UX: Move watched words to the Logs section of admin --- .../admin/components/watched-word-uploader.js.es6 | 2 +- .../javascripts/admin/models/watched-word.js.es6 | 6 +++--- .../javascripts/admin/routes/admin-route-map.js.es6 | 9 ++++----- app/assets/javascripts/admin/templates/admin.hbs | 1 - app/assets/javascripts/admin/templates/logs.hbs | 1 + config/routes.rb | 13 ++++++------- .../acceptance/admin-watched-words-test.js.es6 | 6 +++--- .../fixtures/watched-words-fixtures.js.es6 | 2 +- test/javascripts/helpers/create-pretender.js.es6 | 8 ++++---- 9 files changed, 23 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/admin/components/watched-word-uploader.js.es6 b/app/assets/javascripts/admin/components/watched-word-uploader.js.es6 index c6d39c52a9a..8d9e6ba0a97 100644 --- a/app/assets/javascripts/admin/components/watched-word-uploader.js.es6 +++ b/app/assets/javascripts/admin/components/watched-word-uploader.js.es6 @@ -4,7 +4,7 @@ import UploadMixin from "discourse/mixins/upload"; export default Em.Component.extend(UploadMixin, { type: 'csv', classNames: 'watched-words-uploader', - uploadUrl: '/admin/watched_words/upload', + uploadUrl: '/admin/logs/watched_words/upload', addDisabled: Em.computed.alias("uploading"), validateUploadedFilesOptions() { diff --git a/app/assets/javascripts/admin/models/watched-word.js.es6 b/app/assets/javascripts/admin/models/watched-word.js.es6 index f5d42df1b92..c0418aef978 100644 --- a/app/assets/javascripts/admin/models/watched-word.js.es6 +++ b/app/assets/javascripts/admin/models/watched-word.js.es6 @@ -2,7 +2,7 @@ import { ajax } from 'discourse/lib/ajax'; const WatchedWord = Discourse.Model.extend({ save() { - return ajax("/admin/watched_words" + (this.id ? '/' + this.id : '') + ".json", { + return ajax("/admin/logs/watched_words" + (this.id ? '/' + this.id : '') + ".json", { type: this.id ? 'PUT' : 'POST', data: {word: this.get('word'), action_key: this.get('action')}, dataType: 'json' @@ -10,13 +10,13 @@ const WatchedWord = Discourse.Model.extend({ }, destroy() { - return ajax("/admin/watched_words/" + this.get('id') + ".json", {type: 'DELETE'}); + return ajax("/admin/logs/watched_words/" + this.get('id') + ".json", {type: 'DELETE'}); } }); WatchedWord.reopenClass({ findAll() { - return ajax("/admin/watched_words").then(function (list) { + return ajax("/admin/logs/watched_words").then(function (list) { const actions = {}; list.words.forEach(s => { if (!actions[s.action]) { actions[s.action] = []; } diff --git a/app/assets/javascripts/admin/routes/admin-route-map.js.es6 b/app/assets/javascripts/admin/routes/admin-route-map.js.es6 index 86d624bab79..34e55914ada 100644 --- a/app/assets/javascripts/admin/routes/admin-route-map.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-route-map.js.es6 @@ -62,6 +62,10 @@ export default function() { this.route('screenedEmails', { path: '/screened_emails' }); this.route('screenedIpAddresses', { path: '/screened_ip_addresses' }); this.route('screenedUrls', { path: '/screened_urls' }); + this.route('adminWatchedWords', { path: '/watched_words', resetNamespace: true}, function() { + this.route('index', { path: '/' } ); + this.route('action', { path: '/action/:action_id' } ); + }); }); this.route('adminGroups', { path: '/groups', resetNamespace: true }, function() { @@ -90,10 +94,5 @@ export default function() { this.route('adminPlugins', { path: '/plugins', resetNamespace: true }, function() { this.route('index', { path: '/' }); }); - - this.route('adminWatchedWords', { path: '/watched_words', resetNamespace: true}, function() { - this.route('index', { path: '/' } ); - this.route('action', { path: '/action/:action_id' } ); - }); }); }; diff --git a/app/assets/javascripts/admin/templates/admin.hbs b/app/assets/javascripts/admin/templates/admin.hbs index 525a62626e6..780aad41fcf 100644 --- a/app/assets/javascripts/admin/templates/admin.hbs +++ b/app/assets/javascripts/admin/templates/admin.hbs @@ -22,7 +22,6 @@ {{nav-item route='adminApi' label='admin.api.title'}} {{nav-item route='admin.backups' label='admin.backups.title'}} {{/if}} - {{nav-item route='adminWatchedWords' label='admin.watched_words.title'}} {{nav-item route='adminPlugins' label='admin.plugins.title'}} {{plugin-outlet name="admin-menu" connectorTagName="li"}} diff --git a/app/assets/javascripts/admin/templates/logs.hbs b/app/assets/javascripts/admin/templates/logs.hbs index 5c412949fa0..d72e5a92622 100644 --- a/app/assets/javascripts/admin/templates/logs.hbs +++ b/app/assets/javascripts/admin/templates/logs.hbs @@ -3,6 +3,7 @@ {{nav-item route='adminLogs.screenedEmails' label='admin.logs.screened_emails.title'}} {{nav-item route='adminLogs.screenedIpAddresses' label='admin.logs.screened_ips.title'}} {{nav-item route='adminLogs.screenedUrls' label='admin.logs.screened_urls.title'}} + {{nav-item route='adminWatchedWords' label='admin.watched_words.title'}} {{#if currentUser.admin}} {{nav-item path='/logs' label='admin.logs.logster.title'}} {{/if}} diff --git a/config/routes.rb b/config/routes.rb index 1aa2b5fd075..553bbc9e5b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -168,6 +168,12 @@ Discourse::Application.routes.draw do end end resources :screened_urls, only: [:index] + resources :watched_words, only: [:index, :create, :update, :destroy] do + collection do + get "action/:id" => "watched_words#index" + end + end + post "watched_words/upload" => "watched_words#upload" end get "/logs" => "staff_action_logs#index" @@ -268,13 +274,6 @@ Discourse::Application.routes.draw do get "memory_stats" => "diagnostics#memory_stats", constraints: AdminConstraint.new get "dump_heap" => "diagnostics#dump_heap", constraints: AdminConstraint.new get "dump_statement_cache" => "diagnostics#dump_statement_cache", constraints: AdminConstraint.new - - resources :watched_words, only: [:index, :create, :update, :destroy], constraints: AdminConstraint.new do - collection do - get "action/:id" => "watched_words#index" - end - end - post "watched_words/upload" => "watched_words#upload" end # admin namespace get "email_preferences" => "email#preferences_redirect", :as => "email_preferences_redirect" diff --git a/test/javascripts/acceptance/admin-watched-words-test.js.es6 b/test/javascripts/acceptance/admin-watched-words-test.js.es6 index ac24215f56f..308f8f4da51 100644 --- a/test/javascripts/acceptance/admin-watched-words-test.js.es6 +++ b/test/javascripts/acceptance/admin-watched-words-test.js.es6 @@ -2,7 +2,7 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Admin - Watched Words", { loggedIn: true }); QUnit.test("list words in groups", assert => { - visit("/admin/watched_words/action/block"); + visit("/admin/logs/watched_words/action/block"); andThen(() => { assert.ok(exists('.watched-words-list')); assert.ok(!exists('.watched-words-list .watched-word'), "Don't show bad words by default."); @@ -31,7 +31,7 @@ QUnit.test("list words in groups", assert => { }); QUnit.test("add words", assert => { - visit("/admin/watched_words/action/block"); + visit("/admin/logs/watched_words/action/block"); andThen(() => { click('.show-words-checkbox'); fillIn('.watched-word-form input', 'poutine'); @@ -49,7 +49,7 @@ QUnit.test("add words", assert => { }); QUnit.test("remove words", assert => { - visit("/admin/watched_words/action/block"); + visit("/admin/logs/watched_words/action/block"); click('.show-words-checkbox'); let word = null; diff --git a/test/javascripts/fixtures/watched-words-fixtures.js.es6 b/test/javascripts/fixtures/watched-words-fixtures.js.es6 index e73505f1851..5555923385e 100644 --- a/test/javascripts/fixtures/watched-words-fixtures.js.es6 +++ b/test/javascripts/fixtures/watched-words-fixtures.js.es6 @@ -1,5 +1,5 @@ export default { - "/admin/watched_words.json": { + "/admin/logs/watched_words.json": { "actions": ["block", "censor", "require_approval", "flag"], "words": [ {id: 1, word: "liquorice", action: "block"}, diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6 index 2b5141ce9ed..6cb2f8464bd 100644 --- a/test/javascripts/helpers/create-pretender.js.es6 +++ b/test/javascripts/helpers/create-pretender.js.es6 @@ -334,12 +334,12 @@ export default function() { this.post('/admin/badges', success); this.delete('/admin/badges/:id', success); - this.get('/admin/watched_words', () => { - return response(200, fixturesByUrl['/admin/watched_words.json']); + this.get('/admin/logs/watched_words', () => { + return response(200, fixturesByUrl['/admin/logs/watched_words.json']); }); - this.delete('/admin/watched_words/:id.json', success); + this.delete('/admin/logs/watched_words/:id.json', success); - this.post('/admin/watched_words.json', request => { + this.post('/admin/logs/watched_words.json', request => { const result = parsePostData(request.requestBody); result.id = new Date().getTime(); return response(200, result);