Get detailed app information if user can manage apps
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
/* global angular */
|
||||
/* global EventSource */
|
||||
/* global asyncForEach */
|
||||
|
||||
angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'Notification', function ($http, $interval, md5, Notification) {
|
||||
var client = null;
|
||||
@@ -269,7 +270,12 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
|
||||
};
|
||||
|
||||
Client.prototype.hasScope = function (scope) {
|
||||
return this.getUserInfo().tokenScopes.indexOf(scope) !== -1;
|
||||
var parts = scope.split(':');
|
||||
|
||||
if (this.getUserInfo().tokenScopes.indexOf(scope) !== -1) return true;
|
||||
if (this.getUserInfo().tokenScopes.indexOf(parts[0]) !== -1) return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -627,13 +633,6 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
|
||||
}).error(defaultErrorHandler(callback));
|
||||
};
|
||||
|
||||
Client.prototype.getAppsByUser = function (callback) {
|
||||
get('/api/v1/user/apps').success(function (data, status) {
|
||||
if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data));
|
||||
callback(null, data.apps);
|
||||
}).error(defaultErrorHandler(callback));
|
||||
};
|
||||
|
||||
Client.prototype.getAppLogs = function (appId, follow, lines, callback) {
|
||||
if (follow) {
|
||||
var eventSource = new EventSource(client.apiOrigin + '/api/v1/apps/' + appId + '/logstream?lines=' + lines + '&access_token=' + token);
|
||||
@@ -1140,8 +1139,6 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
|
||||
|
||||
that._updateAppCache(app);
|
||||
|
||||
that._installedApps = that._installedApps.sort(function (app1, app2) { return app1.fqdn.localeCompare(app2.fqdn); });
|
||||
|
||||
callback(null, app);
|
||||
});
|
||||
};
|
||||
@@ -1151,22 +1148,28 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
|
||||
|
||||
callback = typeof callback === 'function' ? callback : function () {};
|
||||
|
||||
var getAppsFunc = this.hasScope('apps') ? this.getApps : this.getAppsByUser;
|
||||
|
||||
getAppsFunc(function (error, apps) {
|
||||
this.getApps(function (error, apps) {
|
||||
if (error) return callback(error);
|
||||
|
||||
// insert or update new apps
|
||||
apps.forEach(that._updateAppCache.bind(that));
|
||||
asyncForEach(apps, function (app, iteratorDone) {
|
||||
var canManageApp = that.hasScope('apps:manage'); // this can become per app level later
|
||||
|
||||
// filter out old entries, going backwards to allow splicing
|
||||
for(var i = that._installedApps.length - 1; i >= 0; --i) {
|
||||
if (!apps.some(function (elem) { return (elem.id === that._installedApps[i].id); })) {
|
||||
that._installedApps.splice(i, 1);
|
||||
if (!canManageApp) {
|
||||
that._updateAppCache(app);
|
||||
return iteratorDone();
|
||||
}
|
||||
}
|
||||
|
||||
callback(null);
|
||||
that.refreshAppCache(app.id, callback);
|
||||
}, function (error) {
|
||||
// filter out old apps, going backwards to allow splicing
|
||||
for(var i = that._installedApps.length - 1; i >= 0; --i) {
|
||||
if (!apps.some(function (elem) { return (elem.id === that._installedApps[i].id); })) {
|
||||
that._installedApps.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
callback(null);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user