Skip to content

Commit

Permalink
Merge pull request #30043 from owncloud/stable10-fix-app-author
Browse files Browse the repository at this point in the history
[stable10] fix app author
  • Loading branch information
phil-davis authored Jan 23, 2018
2 parents aff739d + ada0a65 commit 6f9190c
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 9 deletions.
39 changes: 32 additions & 7 deletions settings/js/admin-apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Handlebars.registerHelper('score', function() {
return new Handlebars.SafeString('');
});
Handlebars.registerHelper('level', function() {
if(typeof this.level !== 'undefined') {
if(!_.isUndefined(this.level)) {
if(this.level === 200) {
return new Handlebars.SafeString('<span class="official icon-checkmark">' + t('settings', 'Official') + '</span>');
} else if(this.level === 100) {
Expand Down Expand Up @@ -147,7 +147,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
var source = $("#app-template").html();
template = Handlebars.compile(source);
}
if (typeof app === 'string') {
if (_.isString(app)) {
app = OC.Settings.Apps.State.apps[app];
}
app.firstExperimental = firstExperimental;
Expand All @@ -157,6 +157,8 @@ OC.Settings.Apps = OC.Settings.Apps || {
app.previewAsIcon = true;
}

app.author = this._parseAppAuthor(app.author);

var html = template(app);
if (selector) {
selector.html(html);
Expand Down Expand Up @@ -200,7 +202,33 @@ OC.Settings.Apps = OC.Settings.Apps || {
}
},

isType: function(app, type){
/**
* Parses the author(s) from the app info response.
*
* @param {(string|string[]|Object|Object[])} author - A string or an array of Objects or strings or both representing the author info from apps info.xml.
* @return {string}
*/
_parseAppAuthor: function (author) {
if (_.isObject(author) && !_.isUndefined(author['@value'])) {
return author['@value'];
}

if (_.isArray(author)) {
var authorNames = [];
for (var i = 0; i < author.length; i++) {
if (_.isObject(author[i]) && !_.isUndefined(author[i]['@value'])) {
authorNames.push(author[i]['@value']);
} else {
authorNames.push(author[i]);
}
}
return authorNames.join(', ');
}

return author;
},

isType: function(app, type) {
return app.types && app.types.indexOf(type) !== -1;
},

Expand Down Expand Up @@ -484,10 +512,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
if (_.isUndefined(app.author)) {
return false;
}
if (_.isArray(app.author)) {
return app.author.join(' ').toLowerCase().indexOf(query) !== -1;
}
return app.author.toLowerCase().indexOf(query) !== -1;
return self._parseAppAuthor(app.author).toLowerCase().indexOf(query) !== -1;
}));

// App status
Expand Down
63 changes: 63 additions & 0 deletions settings/tests/js/apps/appSettingsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* ownCloud
*
* @author Kai Schröer
* @copyright 2018 Kai Schröer <git@schroeer.co>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

describe('App Settings tests', function() {
var apps = [
{
"author": "Author 1, Author 2",
"types": [
"logging",
"dav"
]
},
{
"author": [
"Author 1",
"Author 2",
{
"@attributes": {
"email": "author3@owncloud.org"
},
"@value": "Author 3"
}
],
"types": [
"filesystem"
]
}
];

it('should parse the author info', function() {
var author = OC.Settings.Apps._parseAppAuthor(apps[0].author);
expect(author).toEqual('Author 1, Author 2');

author = OC.Settings.Apps._parseAppAuthor(apps[1].author);
expect(author).toEqual('Author 1, Author 2, Author 3');
});

it('should check the app type', function() {
var isFilesystem = OC.Settings.Apps.isType(apps[0], 'filesystem');
expect(isFilesystem).toEqual(false);

isFilesystem = OC.Settings.Apps.isType(apps[1], 'filesystem');
expect(isFilesystem).toEqual(true);
});
});
6 changes: 4 additions & 2 deletions tests/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ module.exports = function(config) {
{
name: 'settings',
srcFiles: [
'settings/js/users/deleteHandler.js'
'settings/js/users/deleteHandler.js',
'settings/js/admin-apps.js'
],
testFiles: [
'settings/tests/js/users/deleteHandlerSpec.js'
'settings/tests/js/users/deleteHandlerSpec.js',
'settings/tests/js/apps/appSettingsSpec.js'
]
}
];
Expand Down

0 comments on commit 6f9190c

Please sign in to comment.