Repository: couchdb-fauxton Updated Branches: refs/heads/master 69d098bf5 -> 4b3b73f44
Detect system databases on _ All system databases are now prefixed by `_`, so we can remove a lot of detection logic. Additionally colored the warning in red. closes COUCHDB-2607 Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/4b3b73f4 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/4b3b73f4 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/4b3b73f4 Branch: refs/heads/master Commit: 4b3b73f44349230ea8ae3a877f4c2e2a87258d9d Parents: 69d098b Author: Robert Kowalski <[email protected]> Authored: Mon Mar 2 18:43:00 2015 +0100 Committer: Robert Kowalski <[email protected]> Committed: Tue Mar 3 14:24:04 2015 +0100 ---------------------------------------------------------------------- app/addons/databases/resources.js | 43 ++---------------- app/addons/databases/tests/resourcesSpec.js | 17 -------- app/addons/documents/assets/less/documents.less | 6 +++ app/addons/documents/shared-routes.js | 3 +- app/addons/documents/shared-views.js | 11 ++--- .../templates/delete_database_modal.html | 2 +- .../tests/nightwatch/deleteDatabaseModal.js | 46 ++++++++++++++++++++ test/nightwatch_tests/helpers/helpers.js | 6 ++- 8 files changed, 66 insertions(+), 68 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b3b73f4/app/addons/databases/resources.js ---------------------------------------------------------------------- diff --git a/app/addons/databases/resources.js b/app/addons/databases/resources.js index 2066368..ba883b6 100644 --- a/app/addons/databases/resources.js +++ b/app/addons/databases/resources.js @@ -49,6 +49,10 @@ function(app, FauxtonAPI, Documents) { return false; }, + isSystemDatabase: function () { + return (/^_/).test(this.id); + }, + url: function(context) { if (context === "index") { return "/database/" + this.safeID() + "/_all_docs"; @@ -82,45 +86,6 @@ function(app, FauxtonAPI, Documents) { } }); - Databases.IsSystemDatabaseModel = FauxtonAPI.Model.extend({ - - initialize: function (options) { - this.name = options.name; - }, - - url: function () { - return app.host + '/_stats'; - }, - - sync: function (method, model, options) { - options.url = this.url(); - return $.ajax(options); - }, - - parse: function (data) { - var isOnFrontendNode, - isSystemDatabase = false, - systemDatabases = [ - '_replicator', - '_users', - 'nodes', - 'dbs', - 'cassim' - ]; - try { - JSON.parse(data); - isOnFrontendNode = false; - - } catch (e) { - isOnFrontendNode = true; - } - if (systemDatabases.indexOf(this.name) !== -1 && !isOnFrontendNode) { - isSystemDatabase = true; - } - this.set('isSystemDatabase', isSystemDatabase); - } - }); - Databases.Changes = FauxtonAPI.Collection.extend({ initialize: function(options) { http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b3b73f4/app/addons/databases/tests/resourcesSpec.js ---------------------------------------------------------------------- diff --git a/app/addons/databases/tests/resourcesSpec.js b/app/addons/databases/tests/resourcesSpec.js index b5d01a8..2980dd2 100644 --- a/app/addons/databases/tests/resourcesSpec.js +++ b/app/addons/databases/tests/resourcesSpec.js @@ -50,22 +50,5 @@ define([ assert.equal(databaseNames[1], 'rocko'); }); }); - describe('Is system Database', function () { - it('checks if the current database is a systemDatabase if /_stats returns json', function () { - var isSystemDatabase = new Resources.IsSystemDatabaseModel({name: '_users'}); - isSystemDatabase.parse('{"couch_replicator":{}}'); - assert.ok(isSystemDatabase.get('isSystemDatabase')); - }); - it('checks if the current database is a systemDatabase if /_stats returns no json', function () { - var isSystemDatabase = new Resources.IsSystemDatabaseModel({name: '_users'}); - isSystemDatabase.parse('<html></html>'); - assert.notOk(isSystemDatabase.get('isSystemDatabase')); - }); - it('checks if the "cassim" internal database is a system database', function () { - var isSystemDatabase = new Resources.IsSystemDatabaseModel({name: 'cassim'}); - isSystemDatabase.parse('{"couch_replicator":{}}'); - assert.ok(isSystemDatabase.get('isSystemDatabase')); - }); - }); }); }); http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b3b73f4/app/addons/documents/assets/less/documents.less ---------------------------------------------------------------------- diff --git a/app/addons/documents/assets/less/documents.less b/app/addons/documents/assets/less/documents.less index f7fcb20..baae4d7 100644 --- a/app/addons/documents/assets/less/documents.less +++ b/app/addons/documents/assets/less/documents.less @@ -90,6 +90,12 @@ button.string-edit[disabled] { display: none; } +#delete-db-check { + .warning { + color: #d14; + } +} + #string-edit-modal { div.modal { overflow-x: visible; http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b3b73f4/app/addons/documents/shared-routes.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/shared-routes.js b/app/addons/documents/shared-routes.js index e1a84a1..8167d8f 100644 --- a/app/addons/documents/shared-routes.js +++ b/app/addons/documents/shared-routes.js @@ -65,8 +65,7 @@ define([ addSidebar: function (selectedTab) { var params = { collection: this.designDocs, - database: this.database, - isSystemDatabaseModel: new Databases.IsSystemDatabaseModel({name: this.database.get('id')}) + database: this.database }; if (selectedTab) { params.selectedTab = selectedTab; http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b3b73f4/app/addons/documents/shared-views.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/shared-views.js b/app/addons/documents/shared-views.js index fa9ae37..31eaf62 100644 --- a/app/addons/documents/shared-views.js +++ b/app/addons/documents/shared-views.js @@ -30,7 +30,6 @@ function(app, FauxtonAPI, Components, Documents, Databases) { initialize: function(options) { this.database = options.database; - this.isSystemDatabaseModel = options.isSystemDatabaseModel; if (options.ddocInfo) { this.ddocID = options.ddocInfo.id; @@ -93,15 +92,13 @@ function(app, FauxtonAPI, Components, Documents, Databases) { }]); }, - establish: function () { - return [this.isSystemDatabaseModel.fetch({reset: true})]; - - }, - beforeRender: function(manage) { this.deleteDBModal = this.setView( '#delete-db-modal', - new Views.DeleteDBModal({database: this.database, isSystemDatabase: this.isSystemDatabaseModel.get('isSystemDatabase')}) + new Views.DeleteDBModal({ + database: this.database, + isSystemDatabase: this.database.isSystemDatabase() + }) ); var newLinks = [{ http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b3b73f4/app/addons/documents/templates/delete_database_modal.html ---------------------------------------------------------------------- diff --git a/app/addons/documents/templates/delete_database_modal.html b/app/addons/documents/templates/delete_database_modal.html index 6c493d7..f1f8325 100644 --- a/app/addons/documents/templates/delete_database_modal.html +++ b/app/addons/documents/templates/delete_database_modal.html @@ -20,7 +20,7 @@ the License. <div class="modal-body"> <form id="delete-db-check" class="form" method="post"> <% if (isSystemDatabase) { %> - <p>You are about to delete a system database, be careful!</p> + <p class="warning"><b>You are about to delete a system database, be careful!</b></p> <% } %> <p> You've asked to <b>permanently delete</b> <code><%- database.id %></code>. http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b3b73f4/app/addons/documents/tests/nightwatch/deleteDatabaseModal.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/tests/nightwatch/deleteDatabaseModal.js b/app/addons/documents/tests/nightwatch/deleteDatabaseModal.js new file mode 100644 index 0000000..d222ee7 --- /dev/null +++ b/app/addons/documents/tests/nightwatch/deleteDatabaseModal.js @@ -0,0 +1,46 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +module.exports = { + 'Shows a warning for system databases (prefixed with _)': function (client) { + var waitTime = 8000, + baseUrl = client.globals.test_settings.launch_url; + + client + .loginToGUI() + .url(baseUrl + '/#/database/_replicator/_all_docs') + .waitForElementPresent('#header-dropdown-menu a.dropdown-toggle.icon.fonticon-cog', waitTime, false) + .click("#header-dropdown-menu a.dropdown-toggle.icon.fonticon-cog") + .waitForElementPresent('#header-dropdown-menu .fonticon-trash', waitTime, false) + .click('#header-dropdown-menu .fonticon-trash') + .waitForElementVisible('#db_name', waitTime, false) + .assert.elementPresent('.warning') + .end(); + }, + + 'Shows no warning for non system databases': function (client) { + var waitTime = 8000, + newDatabaseName = client.globals.testDatabaseName, + baseUrl = client.globals.test_settings.launch_url; + + client + .loginToGUI() + .url(baseUrl + '/#/database/' + newDatabaseName + '/_all_docs') + .waitForElementPresent('#header-dropdown-menu a.dropdown-toggle.icon.fonticon-cog', waitTime, false) + .click("#header-dropdown-menu a.dropdown-toggle.icon.fonticon-cog") + .waitForElementPresent('#header-dropdown-menu .fonticon-trash', waitTime, false) + .click('#header-dropdown-menu .fonticon-trash') + .waitForElementVisible('#db_name', waitTime, false) + .assert.elementNotPresent('.warning') + .end(); + } +}; http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b3b73f4/test/nightwatch_tests/helpers/helpers.js ---------------------------------------------------------------------- diff --git a/test/nightwatch_tests/helpers/helpers.js b/test/nightwatch_tests/helpers/helpers.js index 555a747..5db5c60 100644 --- a/test/nightwatch_tests/helpers/helpers.js +++ b/test/nightwatch_tests/helpers/helpers.js @@ -22,9 +22,11 @@ module.exports = { // create a new database nano.db.create(database, function (err, body, header) { if (err) { - console.log('Error in setting up '+database, err.message); + console.log('Error in setting up ' + database, err.message); } - done(); + nano.db.create('_replicator', function (err, body, header) { + done(); + }); }); }); },
