Repository: couchdb-fauxton Updated Branches: refs/heads/master 133eda4a2 -> a014c0b64
add a warning for deletion of a systemdatabase on a cluster. Add a warning if the current database is an internal cluster database and _stats is available on that note. _stats is only available if it is a cluster internal node. The warning is only shown for databases with the name: - _replicator - _users - dbs - nodes Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/a014c0b6 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/a014c0b6 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/a014c0b6 Branch: refs/heads/master Commit: a014c0b6436ebfc1063efe5017ff45d6dfcb954f Parents: 133eda4 Author: Poltergeist <[email protected]> Authored: Sun Feb 8 16:49:19 2015 +0100 Committer: Garren Smith <[email protected]> Committed: Thu Feb 19 14:42:32 2015 +0200 ---------------------------------------------------------------------- app/addons/databases/resources.js | 48 ++++++++++++++++++-- app/addons/databases/tests/resourcesSpec.js | 12 +++++ app/addons/documents/shared-routes.js | 3 +- app/addons/documents/shared-views.js | 10 +++- .../templates/delete_database_modal.html | 3 ++ app/addons/documents/views.js | 8 ++++ 6 files changed, 76 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a014c0b6/app/addons/databases/resources.js ---------------------------------------------------------------------- diff --git a/app/addons/databases/resources.js b/app/addons/databases/resources.js index f248e9b..829f8e5 100644 --- a/app/addons/databases/resources.js +++ b/app/addons/databases/resources.js @@ -34,7 +34,7 @@ function(app, FauxtonAPI, Documents) { documentation: function () { return FauxtonAPI.constants.DOC_URLS.ALL_DBS; }, - + buildAllDocs: function(params) { this.allDocs = new Documents.AllDocs(null, { database: this, @@ -54,11 +54,11 @@ function(app, FauxtonAPI, Documents) { return "/database/" + this.safeID() + "/_all_docs"; } else if (context === "web-index") { return "#/database/"+ this.safeID() + "/_all_docs?limit=" + Databases.DocLimit; - } else if (context === "apiurl") { + } else if (context === "apiurl") { return window.location.origin + "/database/" + this.safeID() + "/_all_docs"; } else if (context === "changes") { return FauxtonAPI.urls('changes', 'app', this.safeID(), '?descending=true&limit=100&include_docs=true'); - } else if (context === "changes-apiurl") { + } else if (context === "changes-apiurl") { return FauxtonAPI.urls('changes', 'apiurl' , this.safeID(), '?descending=true&limit=100&include_docs=true'); } else if (context === "app") { return "/database/" + this.safeID(); @@ -82,6 +82,44 @@ 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' + ]; + 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) { @@ -149,7 +187,7 @@ function(app, FauxtonAPI, Documents) { return this.get('disk_size'); } else { return 0; - } + } } }); @@ -171,7 +209,7 @@ function(app, FauxtonAPI, Documents) { }, url: function(context) { - if (context === "apiurl") { + if (context === "apiurl") { return window.location.origin + "/_all_dbs"; } else { return app.host + "/_all_dbs"; http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a014c0b6/app/addons/databases/tests/resourcesSpec.js ---------------------------------------------------------------------- diff --git a/app/addons/databases/tests/resourcesSpec.js b/app/addons/databases/tests/resourcesSpec.js index 2980dd2..91d76ab 100644 --- a/app/addons/databases/tests/resourcesSpec.js +++ b/app/addons/databases/tests/resourcesSpec.js @@ -50,5 +50,17 @@ 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')); + }); + }); }); }); http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a014c0b6/app/addons/documents/shared-routes.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/shared-routes.js b/app/addons/documents/shared-routes.js index 167e4bc..9564530 100644 --- a/app/addons/documents/shared-routes.js +++ b/app/addons/documents/shared-routes.js @@ -45,7 +45,8 @@ define([ addSidebar: function (selectedTab) { var params = { collection: this.designDocs, - database: this.database + database: this.database, + isSystemDatabaseModel: new Databases.IsSystemDatabaseModel({name: this.database.get('id')}) }; if (selectedTab) { params.selectedTab = selectedTab; http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a014c0b6/app/addons/documents/shared-views.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/shared-views.js b/app/addons/documents/shared-views.js index 8042d92..fa9ae37 100644 --- a/app/addons/documents/shared-views.js +++ b/app/addons/documents/shared-views.js @@ -30,6 +30,8 @@ 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; this.currView = options.ddocInfo.currView; @@ -79,7 +81,7 @@ function(app, FauxtonAPI, Components, Documents, Databases) { icon: 'fonticon-plus-circled' }); - return menuLinks; + return menuLinks; }, [{ title: 'New Doc', url: newUrlPrefix + '/new', @@ -91,11 +93,15 @@ 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}) + new Views.DeleteDBModal({database: this.database, isSystemDatabase: this.isSystemDatabaseModel.get('isSystemDatabase')}) ); var newLinks = [{ http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a014c0b6/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 e116a4e..6c493d7 100644 --- a/app/addons/documents/templates/delete_database_modal.html +++ b/app/addons/documents/templates/delete_database_modal.html @@ -19,6 +19,9 @@ the License. </div> <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> You've asked to <b>permanently delete</b> <code><%- database.id %></code>. Please enter the database name below to confirm the deletion of the http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a014c0b6/app/addons/documents/views.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/views.js b/app/addons/documents/views.js index cdef0d1..15e7763 100644 --- a/app/addons/documents/views.js +++ b/app/addons/documents/views.js @@ -145,9 +145,17 @@ function (app, FauxtonAPI, Components, Documents, template: "addons/documents/templates/delete_database_modal", initialize: function (options) { this.database = options.database; + this.isSystemDatabase = options.isSystemDatabase; FauxtonAPI.Events.on('database:delete', this.showDeleteDatabase, this); }, + serialize: function () { + return { + isSystemDatabase: this.isSystemDatabase, + database: this.database + }; + }, + showDeleteDatabase: function () { this.showModal(); },
