diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-01-21 15:23:49 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-01-25 10:45:02 +0100 |
commit | 0a1350d5ac306b4e8c2183b17d562319d69c4ac3 (patch) | |
tree | de943b8959c7a0cd20216a5011c441e85cbcda53 /apps | |
parent | d4198607ec0b54be22781c2f48037cd449ee2fea (diff) | |
download | nextcloud-server-0a1350d5ac306b4e8c2183b17d562319d69c4ac3.tar.gz nextcloud-server-0a1350d5ac306b4e8c2183b17d562319d69c4ac3.zip |
System tags sidebar selector now respects permissions
For admins: display the namespace behind the tag name.
For users: no namespace, don't display non-assignable tags in the
dropdown, display already assigned non-assignable tags with a different
style
Diffstat (limited to 'apps')
-rw-r--r-- | apps/systemtags/appinfo/app.php | 1 | ||||
-rw-r--r-- | apps/systemtags/js/systemtagsinfoview.js | 14 | ||||
-rw-r--r-- | apps/systemtags/tests/js/systemtagsinfoviewSpec.js | 31 |
3 files changed, 42 insertions, 4 deletions
diff --git a/apps/systemtags/appinfo/app.php b/apps/systemtags/appinfo/app.php index d07902f777f..d3886993f8f 100644 --- a/apps/systemtags/appinfo/app.php +++ b/apps/systemtags/appinfo/app.php @@ -28,6 +28,7 @@ $eventDispatcher->addListener( \OC_Util::addVendorStyle('select2/select2'); \OCP\Util::addScript('select2-toggleselect'); \OCP\Util::addScript('oc-backbone-webdav'); + \OCP\Util::addScript('systemtags/systemtags'); \OCP\Util::addScript('systemtags/systemtagmodel'); \OCP\Util::addScript('systemtags/systemtagsmappingcollection'); \OCP\Util::addScript('systemtags/systemtagscollection'); diff --git a/apps/systemtags/js/systemtagsinfoview.js b/apps/systemtags/js/systemtagsinfoview.js index b1820bfcd91..2e808f9a84f 100644 --- a/apps/systemtags/js/systemtagsinfoview.js +++ b/apps/systemtags/js/systemtagsinfoview.js @@ -9,6 +9,15 @@ */ (function(OCA) { + + function modelToSelection(model) { + var data = model.toJSON(); + if (!OC.isUserAdmin() && !data.userAssignable) { + data.locked = true; + } + return data; + } + /** * @class OCA.SystemTags.SystemTagsInfoView * @classdesc @@ -36,8 +45,9 @@ multiple: true, allowActions: true, allowCreate: true, + isAdmin: OC.isUserAdmin(), initSelection: function(element, callback) { - callback(self.selectedTagsCollection.toJSON()); + callback(self.selectedTagsCollection.map(modelToSelection)); } }); @@ -108,7 +118,7 @@ this.selectedTagsCollection.fetch({ success: function(collection) { collection.fetched = true; - self._inputView.setData(collection.toJSON()); + self._inputView.setData(collection.map(modelToSelection)); self.$el.removeClass('hidden'); } }); diff --git a/apps/systemtags/tests/js/systemtagsinfoviewSpec.js b/apps/systemtags/tests/js/systemtagsinfoviewSpec.js index 971ad8fc17e..0fb4e7b22c2 100644 --- a/apps/systemtags/tests/js/systemtagsinfoviewSpec.js +++ b/apps/systemtags/tests/js/systemtagsinfoviewSpec.js @@ -20,13 +20,16 @@ */ describe('OCA.SystemTags.SystemTagsInfoView tests', function() { + var isAdminStub; var view; beforeEach(function() { view = new OCA.SystemTags.SystemTagsInfoView(); $('#testArea').append(view.$el); + isAdminStub = sinon.stub(OC, 'isUserAdmin').returns(true); }); afterEach(function() { + isAdminStub.restore(); view.remove(); view = undefined; }); @@ -73,7 +76,7 @@ describe('OCA.SystemTags.SystemTagsInfoView tests', function() { view = new OCA.SystemTags.SystemTagsInfoView(); view.selectedTagsCollection.add([ {id: '1', name: 'test1'}, - {id: '3', name: 'test3'} + {id: '3', name: 'test3', userVisible: false, userAssignable: false} ]); var callback = sinon.stub(); @@ -83,7 +86,31 @@ describe('OCA.SystemTags.SystemTagsInfoView tests', function() { expect(callback.getCall(0).args[0]).toEqual([{ id: '1', name: 'test1', userVisible: true, userAssignable: true }, { - id: '3', name: 'test3', userVisible: true, userAssignable: true + id: '3', name: 'test3', userVisible: false, userAssignable: false + }]); + + inputViewSpy.restore(); + }); + it('sets locked flag on non-assignable tags when user is not an admin', function() { + isAdminStub.returns(false); + + var inputViewSpy = sinon.spy(OC.SystemTags, 'SystemTagsInputField'); + var element = $('<input type="hidden" val="1,3"/>'); + view.remove(); + view = new OCA.SystemTags.SystemTagsInfoView(); + view.selectedTagsCollection.add([ + {id: '1', name: 'test1'}, + {id: '3', name: 'test3', userAssignable: false} + ]); + + var callback = sinon.stub(); + inputViewSpy.getCall(0).args[0].initSelection(element, callback); + + expect(callback.calledOnce).toEqual(true); + expect(callback.getCall(0).args[0]).toEqual([{ + id: '1', name: 'test1', userVisible: true, userAssignable: true + }, { + id: '3', name: 'test3', userVisible: true, userAssignable: false, locked: true }]); inputViewSpy.restore(); |