diff --git a/apps/systemtags/appinfo/app.php b/apps/systemtags/appinfo/app.php
index d07902f777..d3886993f8 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 b1820bfcd9..2e808f9a84 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 971ad8fc17..0fb4e7b22c 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 = $('');
+ 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();
diff --git a/core/css/systemtags.css b/core/css/systemtags.css
index 5c667e5454..d847baa680 100644
--- a/core/css/systemtags.css
+++ b/core/css/systemtags.css
@@ -69,6 +69,11 @@
margin: 0;
line-height: 20px;
}
+
+.systemtags-select2-container .select2-choices .select2-search-choice.select2-locked .label {
+ font-style: italic;
+}
+
.systemtags-select2-container .select2-choices .select2-search-choice-close {
display: none;
}
diff --git a/core/js/systemtags/systemtagmodel.js b/core/js/systemtags/systemtagmodel.js
index e6014977d2..62bf3a7008 100644
--- a/core/js/systemtags/systemtagmodel.js
+++ b/core/js/systemtags/systemtagmodel.js
@@ -37,8 +37,8 @@
return {
id: data.id,
name: data.name,
- userVisible: data.userVisible === '1',
- userAssignable: data.userAssignable === '1'
+ userVisible: data.userVisible === true || data.userVisible === '1',
+ userAssignable: data.userAssignable === true || data.userAssignable === '1'
};
}
});
diff --git a/core/js/systemtags/systemtagsinputfield.js b/core/js/systemtags/systemtagsinputfield.js
index facacc50e2..b90ecbe426 100644
--- a/core/js/systemtags/systemtagsinputfield.js
+++ b/core/js/systemtags/systemtagsinputfield.js
@@ -17,7 +17,11 @@
var RESULT_TEMPLATE =
'' +
' ' +
+ '{{#if isAdmin}}' +
+ ' {{{tagMarkup}}}' +
+ '{{else}}' +
' {{name}}' +
+ '{{/if}}' +
'{{#allowActions}}' +
' ' +
' ' +
@@ -25,6 +29,14 @@
'{{/allowActions}}' +
'';
+ var SELECTION_TEMPLATE =
+ '{{#if isAdmin}}' +
+ ' {{{tagMarkup}}}' +
+ '{{else}}' +
+ ' {{name}}' +
+ '{{/if}}' +
+ ', ';
+
var RENAME_FORM_TEMPLATE =
'