You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2014/09/08 15:29:33 UTC
[2/4] fauxton commit: updated refs/heads/master to 36957d0
Enable access on replication for non-admins
COUCHDB-2244
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/be420542
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/be420542
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/be420542
Branch: refs/heads/master
Commit: be420542b01eaaacfe83455bbdbcc9f962eefbfb
Parents: 00b8fd0
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Mon Sep 1 00:12:32 2014 +0200
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Mon Sep 8 15:30:29 2014 +0200
----------------------------------------------------------------------
app/addons/replication/route.js | 17 ++++++--
app/addons/replication/tests/replicationSpec.js | 31 ++++++++++-----
app/addons/replication/views.js | 42 ++++++++++++++------
app/core/couchdbSession.js | 7 +++-
4 files changed, 72 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/be420542/app/addons/replication/route.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/route.js b/app/addons/replication/route.js
index 8495fa2..1b9ba91 100644
--- a/app/addons/replication/route.js
+++ b/app/addons/replication/route.js
@@ -19,7 +19,6 @@ define([
function(app, FauxtonAPI, Replication, Views) {
var RepRouteObject = FauxtonAPI.RouteObject.extend({
layout: "one_pane",
- roles: ["_admin"],
routes: {
"replication": "defaultView",
"replication/:dbname": "defaultView"
@@ -32,13 +31,25 @@ function(app, FauxtonAPI, Replication, Views) {
{"name": "Replicate changes from: ", "link": "replication"}
],
defaultView: function(dbname){
+ var isAdmin = FauxtonAPI.session.isAdmin();
+
+ this.tasks = [];
this.databases = new Replication.DBList({});
- this.tasks = new Replication.Tasks({id: "ReplicationTasks"});
this.replication = new Replication.Replicate({});
+
+ if (isAdmin) {
+ this.tasks = new Replication.Tasks({id: "ReplicationTasks"});
+ this.setView("#dashboard-content", new Views.ReplicationFormForAdmins({
+ selectedDB: dbname ||"",
+ collection: this.databases,
+ status: this.tasks
+ }));
+ return;
+ }
this.setView("#dashboard-content", new Views.ReplicationForm({
selectedDB: dbname ||"",
collection: this.databases,
- status: this.tasks
+ status: this.tasks
}));
}
});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/be420542/app/addons/replication/tests/replicationSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/tests/replicationSpec.js b/app/addons/replication/tests/replicationSpec.js
index 788b082..55fe1c8 100644
--- a/app/addons/replication/tests/replicationSpec.js
+++ b/app/addons/replication/tests/replicationSpec.js
@@ -10,18 +10,31 @@
// License for the specific language governing permissions and limitations under
// the License.
define([
- 'addons/replication/base',
- 'chai'
-], function (Replication, chai) {
- var expect = chai.expect;
+ 'addons/replication/base',
+ 'addons/replication/views',
+ 'addons/replication/resources',
+ 'testUtils'
+], function (Replication, Views, Resources, testUtils) {
+ var assert = testUtils.assert,
+ ViewSandbox = testUtils.ViewSandbox,
+ viewSandbox;
- describe('Replication Addon', function(){
+ describe('Replication Addon', function () {
+ describe('Replication View', function () {
+ var view = new Views.ReplicationForm({
+ collection: new Replication.DBList()
+ });
+ beforeEach(function (done) {
+ viewSandbox = new ViewSandbox();
+ viewSandbox.renderView(view, done);
+ });
- describe('Replication DBList Collection', function () {
- var rep;
+ afterEach(function () {
+ viewSandbox.remove();
+ });
- beforeEach(function () {
- rep = new rep.DBList(["foo","bar","baz","bo"]);
+ it("should render", function () {
+ assert.ok(view.$el.length > 0);
});
});
});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/be420542/app/addons/replication/views.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/views.js b/app/addons/replication/views.js
index 1184878..a138beb 100644
--- a/app/addons/replication/views.js
+++ b/app/addons/replication/views.js
@@ -16,7 +16,7 @@ define([
"addons/fauxton/components",
"addons/replication/resources"
],
-function(app, FauxtonAPI, Components, replication) {
+function(app, FauxtonAPI, Components, Replication) {
var View = {},
Events ={},
pollingInfo ={
@@ -42,7 +42,7 @@ function(app, FauxtonAPI, Components, replication) {
// swapFields: change to and from target
// toggleAdvancedOptions: toggle advanced
- View.ReplicationForm = FauxtonAPI.View.extend({
+ View.ReplicationFormForAdmins = FauxtonAPI.View.extend({
template: "addons/replication/templates/form",
events: {
"submit #replication": "validate",
@@ -53,7 +53,7 @@ function(app, FauxtonAPI, Components, replication) {
initialize: function(options){
this.status = options.status;
this.selectedDB = options.selectedDB;
- this.newRepModel = new replication.Replicate({});
+ this.newRepModel = new Replication.Replicate({});
},
afterRender: function(){
this.dbSearchTypeahead = new Components.DbSearchTypeahead({
@@ -66,7 +66,7 @@ function(app, FauxtonAPI, Components, replication) {
},
beforeRender: function(){
- this.insertView("#replicationStatus", new View.ReplicationList({
+ this.insertView("#replicationStatus", new View.ReplicationListForAdmins({
collection: this.status
}));
},
@@ -90,7 +90,7 @@ function(app, FauxtonAPI, Components, replication) {
}
},
establish: function(){
- return [ this.collection.fetch(), this.status.fetch()];
+ return [this.collection.fetch(), this.status.fetch()];
},
validate: function(e){
e.preventDefault();
@@ -196,8 +196,29 @@ function(app, FauxtonAPI, Components, replication) {
}
});
+ View.ReplicationForm = View.ReplicationFormForAdmins.extend({
+ template: "addons/replication/templates/form",
- View.ReplicationList = FauxtonAPI.View.extend({
+ events: {
+ "submit #replication": "validate",
+ "click .btn-group .btn": "showFields",
+ "click .swap": "swapFields",
+ "click .options": "toggleAdvancedOptions"
+ },
+
+ initialize: function (options) {
+ this.selectedDB = options.selectedDB;
+ this.newRepModel = new Replication.Replicate({});
+ },
+
+ beforeRender: function () {},
+
+ establish: function () {
+ return [this.collection.fetch()];
+ },
+ });
+
+ View.ReplicationListForAdmins = FauxtonAPI.View.extend({
tagName: "ul",
initialize: function(){
Events.bind('update:tasks', this.establish, this);
@@ -225,11 +246,8 @@ function(app, FauxtonAPI, Components, replication) {
}, this);
},
showHeader: function(){
- if (this.collection.length > 0){
- this.$el.parent().addClass('showHeader');
- } else {
- this.$el.parent().removeClass('showHeader');
- }
+ this.$el.parent()
+ .toggleClass('showHeader', this.collection.length > 0);
},
afterRender: function(){
this.showHeader();
@@ -246,7 +264,7 @@ function(app, FauxtonAPI, Components, replication) {
"click .cancel": "cancelReplication"
},
initialize: function(){
- this.newRepModel = new replication.Replicate({});
+ this.newRepModel = new Replication.Replicate({});
},
establish: function(){
return [this.model.fetch()];
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/be420542/app/core/couchdbSession.js
----------------------------------------------------------------------
diff --git a/app/core/couchdbSession.js b/app/core/couchdbSession.js
index 7482db9..7ee28d9 100644
--- a/app/core/couchdbSession.js
+++ b/app/core/couchdbSession.js
@@ -27,6 +27,11 @@ function (FauxtonAPI) {
};
},
+ isAdmin: function () {
+ var userCtx = this.get('userCtx');
+ return userCtx.roles.indexOf('_admin') !== -1;
+ },
+
fetchUser: function (opt) {
var that = this,
options = opt || {},
@@ -50,7 +55,7 @@ function (FauxtonAPI) {
// this will return the user as a value to all function that calls done on this
// eg. session.fetchUser().done(user) { .. do something with user ..}
- return user;
+ return user;
});
}
})