Use the scope to determine what the user has access to

This commit is contained in:
Girish Ramakrishnan
2018-05-01 11:44:47 -07:00
parent d9ec1be9b6
commit 72bbb4ec68
10 changed files with 23 additions and 8 deletions
+11 -2
View File
@@ -222,6 +222,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
this._userInfo.displayName = userInfo.displayName;
this._userInfo.admin = !!userInfo.admin;
this._userInfo.twoFactorAuthenticationEnabled = userInfo.twoFactorAuthenticationEnabled;
this._userInfo.scope = userInfo.scope;
this._userInfo.gravatar = 'https://www.gravatar.com/avatar/' + md5.createHash(userInfo.email) + '.jpg?s=24&d=mm';
this._userInfo.gravatarHuge = 'https://www.gravatar.com/avatar/' + md5.createHash(userInfo.email) + '.jpg?s=128&d=mm';
};
@@ -263,11 +264,17 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
return token;
};
Client.prototype.hasScope = function (scope) {
return this.getUserInfo().scope.split(',').indexOf(scope) !== -1;
};
/*
* Rest API wrappers
*/
Client.prototype.config = function (callback) {
get('/api/v1/cloudron/config').success(function(data, status) {
var configRoute = this.hasScope('cloudron') ? '/api/v1/cloudron/config' : '/api/v1/user/cloudron_config';
get(configRoute).success(function(data, status) {
if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data));
callback(null, data);
}).error(defaultErrorHandler(callback));
@@ -1028,7 +1035,9 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
callback = typeof callback === 'function' ? callback : function () {};
this.getAppsByUser(function (error, apps) {
var getAppsFunc = this.hasScope('apps') ? this.getApps : this.getAppsByUser;
getAppsFunc(function (error, apps) {
if (error) return callback(error);
// insert or update new apps
+2
View File
@@ -1,6 +1,8 @@
'use strict';
angular.module('Application').controller('ActivityController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
Client.onReady(function () { if (!Client.hasScope('cloudron')) $location.path('/'); });
$scope.config = Client.getConfig();
$scope.busy = false;
+1 -1
View File
@@ -1,7 +1,7 @@
'use strict';
angular.module('Application').controller('AppStoreController', ['$scope', '$location', '$timeout', '$routeParams', 'Client', 'AppStore', function ($scope, $location, $timeout, $routeParams, Client, AppStore) {
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
Client.onReady(function () { if (!Client.hasScope('apps')) $location.path('/'); });
$scope.HOST_PORT_MIN = 1024;
$scope.HOST_PORT_MAX = 65535;
+1 -1
View File
@@ -1,7 +1,7 @@
'use strict';
angular.module('Application').controller('DomainsController', ['$scope', '$location', 'Client', 'ngTld', function ($scope, $location, Client, ngTld) {
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
Client.onReady(function () { if (!Client.hasScope('domains')) $location.path('/'); });
$scope.config = Client.getConfig();
$scope.dnsConfig = null;
+1 -1
View File
@@ -3,7 +3,7 @@
/* global asyncForEach:false */
angular.module('Application').controller('EmailController', ['$scope', '$location', '$timeout', '$rootScope', 'Client', 'AppStore', function ($scope, $location, $timeout, $rootScope, Client, AppStore) {
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
Client.onReady(function () { if (!Client.hasScope('mail')) $location.path('/'); });
$scope.ready = false;
$scope.refreshBusy = true;
+1 -1
View File
@@ -4,7 +4,7 @@
'use strict';
angular.module('Application').controller('GraphsController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
Client.onReady(function () { if (!Client.hasScope('cloudron')) $location.path('/'); });
$scope.diskUsage = {};
$scope.memoryUsageSystem = [];
+1 -1
View File
@@ -1,7 +1,7 @@
'use strict';
angular.module('Application').controller('SettingsController', ['$scope', '$location', '$rootScope', '$timeout', 'Client', 'AppStore', function ($scope, $location, $rootScope, $timeout, Client, AppStore) {
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
Client.onReady(function () { if (!Client.hasScope('settings')) $location.path('/'); });
$scope.client = Client;
$scope.user = Client.getUserInfo();
+2
View File
@@ -1,6 +1,8 @@
'use strict';
angular.module('Application').controller('SupportController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
Client.onReady(function () { if (!Client.hasScope('settings')) $location.path('/'); });
$scope.config = Client.getConfig();
$scope.user = Client.getUserInfo();
$scope.apps = Client.getInstalledApps();
+2
View File
@@ -1,6 +1,8 @@
'use strict';
angular.module('Application').controller('TokensController', ['$scope', 'Client', function ($scope, Client) {
Client.onReady(function () { if (!Client.hasScope('clients')) $location.path('/'); });
$scope.user = Client.getUserInfo();
$scope.config = Client.getConfig();
+1 -1
View File
@@ -4,7 +4,7 @@
/* global asyncForEach:false */
angular.module('Application').controller('UsersController', ['$scope', '$location', '$timeout', 'Client', function ($scope, $location, $timeout, Client) {
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
Client.onReady(function () { if (!Client.hasScope('users')) $location.path('/'); });
$scope.ready = false;
$scope.users = [];