You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/09/25 17:42:40 UTC
[11/11] git commit: updated refs/heads/1871-permissions to 1acae25
more tests and error notifications
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/1acae259
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/1acae259
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/1acae259
Branch: refs/heads/1871-permissions
Commit: 1acae2594a084088fbcf685912e87fec8d77fe08
Parents: 481cd4f
Author: Garren Smith <ga...@gmail.com>
Authored: Wed Sep 25 16:35:49 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Wed Sep 25 17:41:36 2013 +0200
----------------------------------------------------------------------
src/fauxton/app/addons/permissions/resources.js | 17 +++-
.../app/addons/permissions/tests/viewsSpec.js | 82 +++++++++++++++++++-
src/fauxton/app/addons/permissions/views.js | 30 ++++---
3 files changed, 114 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/1acae259/src/fauxton/app/addons/permissions/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/permissions/resources.js b/src/fauxton/app/addons/permissions/resources.js
index 5829971..66eaffd 100644
--- a/src/fauxton/app/addons/permissions/resources.js
+++ b/src/fauxton/app/addons/permissions/resources.js
@@ -28,9 +28,8 @@ function (app, FauxtonAPI ) {
names: [],
roles: []
}
-
},
-
+
isNew: function () {
return false;
},
@@ -46,9 +45,19 @@ function (app, FauxtonAPI ) {
addItem: function (value, type, section) {
var sectionValues = this.get(section);
- if (!sectionValues || !sectionValues[type]) { return; }
+ if (!sectionValues || !sectionValues[type]) {
+ return {
+ error: true,
+ msg: 'Section ' + section + 'does not exist'
+ };
+ }
- if (sectionValues[type].indexOf(value) > -1) { return; }
+ if (sectionValues[type].indexOf(value) > -1) {
+ return {
+ error: true,
+ msg: 'Role/Name has already been added'
+ };
+ }
sectionValues[type].push(value);
return this.set(section, sectionValues);
http://git-wip-us.apache.org/repos/asf/couchdb/blob/1acae259/src/fauxton/app/addons/permissions/tests/viewsSpec.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/permissions/tests/viewsSpec.js b/src/fauxton/app/addons/permissions/tests/viewsSpec.js
index 73afec2..e5330c0 100644
--- a/src/fauxton/app/addons/permissions/tests/viewsSpec.js
+++ b/src/fauxton/app/addons/permissions/tests/viewsSpec.js
@@ -18,6 +18,49 @@ define([
var assert = testUtils.assert,
ViewSandbox = testUtils.ViewSandbox;
+ describe('Permission View', function () {
+
+ beforeEach(function () {
+ security = new Models.Security({'admins': {
+ 'names': ['_user'],
+ 'roles': []
+ }
+ }, {database: 'fakedb'});
+
+ section = new Views.Permissions({
+ database: 'fakedb',
+ model: security
+ });
+
+ viewSandbox = new ViewSandbox();
+ viewSandbox.renderView(section);
+ });
+
+ afterEach(function () {
+ viewSandbox.remove();
+ });
+
+ describe('itemRemoved', function () {
+
+ it('Should set model', function () {
+ var saveMock = sinon.spy(security, 'set');
+ Views.events.trigger('itemRemoved');
+
+ assert.ok(saveMock.calledOnce);
+ var args = saveMock.args;
+ assert.deepEqual(args[0][0], {"admins":{"names":["_user"],"roles":[]},"members":{"names":[],"roles":[]}});
+ });
+
+ it('Should save model', function () {
+ var saveMock = sinon.spy(security, 'save');
+ Views.events.trigger('itemRemoved');
+
+ assert.ok(saveMock.calledOnce);
+ });
+ });
+
+ });
+
describe('PermissionsSection', function () {
var section, security;
@@ -29,7 +72,8 @@ define([
}, {database: 'fakedb'});
section = new Views.PermissionSection({
- section: 'admins'
+ section: 'admins',
+ model: security
});
viewSandbox = new ViewSandbox();
@@ -40,6 +84,42 @@ define([
viewSandbox.remove();
});
+ describe('#discardRemovedViews', function () {
+ it('Should not filter out active views', function () {
+ section.discardRemovedViews();
+
+ assert.equal(section.nameViews.length, 1);
+
+ });
+
+ it('Should filter out removed views', function () {
+ section.nameViews[0].removed = true;
+ section.discardRemovedViews();
+
+ assert.equal(section.nameViews.length, 0);
+
+ });
+
+ });
+
+ describe('#getItemFromView', function () {
+
+ it('Should return item list', function () {
+ var items = section.getItemFromView(section.nameViews);
+
+ assert.deepEqual(items, ['_user']);
+ });
+
+ });
+
+ describe('#addItems', function () {
+
+ it('Should add item to model', function () {
+ //todo add a test here
+
+ });
+
+ });
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/1acae259/src/fauxton/app/addons/permissions/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/permissions/views.js b/src/fauxton/app/addons/permissions/views.js
index 3c5d3c2..4c2987b 100644
--- a/src/fauxton/app/addons/permissions/views.js
+++ b/src/fauxton/app/addons/permissions/views.js
@@ -27,13 +27,7 @@ function (app, FauxtonAPI, Permissions ) {
this.listenTo(Permissions.events, 'itemRemoved', this.itemRemoved);
},
- events: {
- "submit .permission-item-form": "addItem",
- 'click .close': "removeItem"
- },
-
itemRemoved: function (event) {
- console.log('item remove');
this.model.set({
admins: this.adminsView.items(),
members: this.membersView.items()
@@ -43,8 +37,14 @@ function (app, FauxtonAPI, Permissions ) {
FauxtonAPI.addNotification({
msg: 'Database permissions has been updated.'
});
+ }, function (xhr) {
+ FauxtonAPI.addNotification({
+ msg: 'Could not update permissions - reason: ' + xhr.responseText,
+ type: 'error'
+ });
});
},
+
beforeRender: function () {
this.adminsView = this.insertView('#sections', new Permissions.PermissionSection({
model: this.model,
@@ -59,12 +59,9 @@ function (app, FauxtonAPI, Permissions ) {
}));
},
-
serialize: function () {
- console.log('s', this.model.toJSON());
return {
databaseName: this.database.id,
- security: this.model.toJSON()
};
}
});
@@ -135,12 +132,25 @@ function (app, FauxtonAPI, Permissions ) {
type = $item.data('type'),
that = this;
- this.model.addItem(value, type, section);
+ var resp = this.model.addItem(value, type, section);
+
+ if (resp && resp.error) {
+ return FauxtonAPI.addNotification({
+ msg: resp.msg,
+ type: 'error'
+ });
+ }
+
this.model.save().then(function () {
that.render();
FauxtonAPI.addNotification({
msg: 'Database permissions has been updated.'
});
+ }, function (xhr) {
+ FauxtonAPI.addNotification({
+ msg: 'Could not update permissions - reason: ' + xhr.responseText,
+ type: 'error'
+ });
});
},