Merge pull request #1123 from marshmalien/fix/manage_org_auth

Warning banner when Org Admin doesn't have authorization
This commit is contained in:
Marliana Lara
2018-03-29 13:38:37 -04:00
committed by GitHub
13 changed files with 99 additions and 24 deletions

View File

@@ -97,11 +97,19 @@ input#filePickerText {
.Section-messageBar { .Section-messageBar {
width: 120%; width: 120%;
margin-left: -20px; margin-left: -20px;
padding: 10px; padding: 10px 10px 10px 20px;
color: @white; color: @white;
background-color: @default-link; background-color: @default-link;
} }
.Section-messageBar-text {
margin-left: @at-space-2x;
}
.Section-messageBar-warning {
color: @at-color-warning;
}
.Section-messageBar--close { .Section-messageBar--close {
position: absolute; position: absolute;
right: 0; right: 0;

View File

@@ -142,10 +142,10 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
.factory('GenerateForm', ['$rootScope', '$compile', 'generateList', .factory('GenerateForm', ['$rootScope', '$compile', 'generateList',
'Attr', 'Icon', 'Column', 'Attr', 'Icon', 'Column',
'NavigationLink', 'HelpCollapse', 'Empty', 'SelectIcon', 'NavigationLink', 'HelpCollapse', 'Empty', 'SelectIcon',
'ActionButton', '$log', 'i18n', 'ActionButton', 'MessageBar', '$log', 'i18n',
function ($rootScope, $compile, GenerateList, function ($rootScope, $compile, GenerateList,
Attr, Icon, Column, NavigationLink, HelpCollapse, Attr, Icon, Column, NavigationLink, HelpCollapse,
Empty, SelectIcon, ActionButton, $log, i18n) { Empty, SelectIcon, ActionButton, MessageBar, $log, i18n) {
return { return {
setForm: function (form) { this.form = form; }, setForm: function (form) { this.form = form; },
@@ -177,6 +177,7 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
else { else {
return ` return `
<div ui-view="preFormView"></div> <div ui-view="preFormView"></div>
${MessageBar(this.form)}
<div class="Panel"> <div class="Panel">
${html} ${html}
<div ui-view="related"></div> <div ui-view="related"></div>

View File

@@ -766,4 +766,18 @@ angular.module('GeneratorHelpers', [systemStatus.name])
return html; return html;
}; };
})
.factory('MessageBar', function() {
return function(options) {
let html = '';
if (_.has(options, 'messageBar')) {
let { messageBar } = options;
html += `<div class="Section-messageBar" ng-show="${messageBar.ngShow}">
<i class="Section-messageBar-warning fa fa-warning"></i>
<span class="Section-messageBar-text">${messageBar.message}</span>
</div>`;
}
return html;
};
}); });

View File

@@ -5,17 +5,20 @@
*************************************************/ *************************************************/
export default ['$scope', '$rootScope', '$stateParams', 'TeamForm', 'Rest', export default ['$scope', '$rootScope', '$stateParams', 'TeamForm', 'Rest',
'ProcessErrors', 'GetBasePath', 'Wait', '$state', 'OrgAdminLookup', 'ProcessErrors', 'GetBasePath', 'Wait', '$state', 'OrgAdminLookup', 'resolvedModels',
function($scope, $rootScope, $stateParams, TeamForm, Rest, ProcessErrors, function($scope, $rootScope, $stateParams, TeamForm, Rest, ProcessErrors,
GetBasePath, Wait, $state, OrgAdminLookup) { GetBasePath, Wait, $state, OrgAdminLookup, models) {
const { me } = models;
var form = TeamForm, var form = TeamForm,
id = $stateParams.team_id, id = $stateParams.team_id,
defaultUrl = GetBasePath('teams') + id; defaultUrl = GetBasePath('teams') + id;
init(); init();
function init() { function init() {
$scope.canEdit = me.get('summary_fields.user_capabilities.edit');
$scope.isOrgAdmin = me.get('related.admin_of_organizations.count') > 0;
$scope.team_id = id; $scope.team_id = id;
Rest.setUrl(defaultUrl); Rest.setUrl(defaultUrl);
Wait('start'); Wait('start');
@@ -33,9 +36,7 @@ export default ['$scope', '$rootScope', '$stateParams', 'TeamForm', 'Rest',
}); });
$scope.$watch('team_obj.summary_fields.user_capabilities.edit', function(val) { $scope.$watch('team_obj.summary_fields.user_capabilities.edit', function(val) {
if (val === false) { $scope.canAdd = (val === false) ? false : true;
$scope.canAdd = false;
}
}); });

View File

@@ -6,16 +6,18 @@
export default ['$scope', 'Rest', 'TeamList', 'Prompt', export default ['$scope', 'Rest', 'TeamList', 'Prompt',
'ProcessErrors', 'GetBasePath', 'Wait', '$state', '$filter', 'ProcessErrors', 'GetBasePath', 'Wait', '$state', '$filter',
'rbacUiControlService', 'Dataset', 'i18n', 'rbacUiControlService', 'Dataset', 'resolvedModels', 'i18n',
function($scope, Rest, TeamList, Prompt, ProcessErrors, function($scope, Rest, TeamList, Prompt, ProcessErrors,
GetBasePath, Wait, $state, $filter, rbacUiControlService, Dataset, i18n) { GetBasePath, Wait, $state, $filter, rbacUiControlService, Dataset, models, i18n) {
const { me } = models;
var list = TeamList, var list = TeamList,
defaultUrl = GetBasePath('teams'); defaultUrl = GetBasePath('teams');
init(); init();
function init() { function init() {
$scope.canEdit = me.get('summary_fields.user_capabilities.edit');
$scope.canAdd = false; $scope.canAdd = false;
rbacUiControlService.canAdd('teams') rbacUiControlService.canAdd('teams')

View File

@@ -41,6 +41,26 @@ angular.module('Teams', [])
activityStream: true, activityStream: true,
activityStreamTarget: 'team' activityStreamTarget: 'team'
}, },
resolve: {
edit: {
resolvedModels: ['MeModel', '$q', function(Me, $q) {
const promises = {
me: new Me('get').then((me) => me.extend('get', 'admin_of_organizations'))
};
return $q.all(promises);
}]
},
list: {
resolvedModels: ['MeModel', '$q', function(Me, $q) {
const promises = {
me: new Me('get')
};
return $q.all(promises);
}]
}
},
ncyBreadcrumb: { ncyBreadcrumb: {
label: N_('TEAMS') label: N_('TEAMS')
} }

View File

@@ -19,7 +19,10 @@ export default ['i18n', function(i18n) {
// the top-most node of generated state tree // the top-most node of generated state tree
stateTree: 'teams', stateTree: 'teams',
tabs: true, tabs: true,
messageBar: {
ngShow: 'isOrgAdmin && !canEdit',
message: i18n._("Contact your System Administrator to grant you the appropriate permissions to add and edit Users and Teams.")
},
fields: { fields: {
name: { name: {
label: i18n._('Name'), label: i18n._('Name'),

View File

@@ -43,7 +43,7 @@ export default ['i18n', function(i18n) {
awToolTip: i18n._('Create a new team'), awToolTip: i18n._('Create a new team'),
actionClass: 'btn List-buttonSubmit', actionClass: 'btn List-buttonSubmit',
buttonContent: '&#43; ' + i18n._('ADD'), buttonContent: '&#43; ' + i18n._('ADD'),
ngShow: 'canAdd' ngShow: 'canAdd && canEdit'
} }
}, },

View File

@@ -14,14 +14,15 @@ const user_type_options = [
export default ['$scope', '$rootScope', '$stateParams', 'UserForm', 'Rest', export default ['$scope', '$rootScope', '$stateParams', 'UserForm', 'Rest',
'ProcessErrors', 'GetBasePath', 'Wait', 'CreateSelect2', 'ProcessErrors', 'GetBasePath', 'Wait', 'CreateSelect2',
'$state', 'i18n', '$state', 'i18n', 'resolvedModels',
function($scope, $rootScope, $stateParams, UserForm, Rest, ProcessErrors, function($scope, $rootScope, $stateParams, UserForm, Rest, ProcessErrors,
GetBasePath, Wait, CreateSelect2, $state, i18n) { GetBasePath, Wait, CreateSelect2, $state, i18n, models) {
for (var i = 0; i < user_type_options.length; i++) { for (var i = 0; i < user_type_options.length; i++) {
user_type_options[i].label = i18n._(user_type_options[i].label); user_type_options[i].label = i18n._(user_type_options[i].label);
} }
const { me } = models;
var form = UserForm, var form = UserForm,
master = {}, master = {},
id = $stateParams.user_id, id = $stateParams.user_id,
@@ -30,6 +31,8 @@ export default ['$scope', '$rootScope', '$stateParams', 'UserForm', 'Rest',
init(); init();
function init() { function init() {
$scope.canEdit = me.get('summary_fields.user_capabilities.edit');
$scope.isOrgAdmin = me.get('related.admin_of_organizations.count') > 0;
$scope.isCurrentlyLoggedInUser = (parseInt(id) === $rootScope.current_user.id); $scope.isCurrentlyLoggedInUser = (parseInt(id) === $rootScope.current_user.id);
$scope.hidePagination = false; $scope.hidePagination = false;
$scope.hideSmartSearch = false; $scope.hideSmartSearch = false;
@@ -68,9 +71,7 @@ export default ['$scope', '$rootScope', '$stateParams', 'UserForm', 'Rest',
}); });
$scope.$watch('user_obj.summary_fields.user_capabilities.edit', function(val) { $scope.$watch('user_obj.summary_fields.user_capabilities.edit', function(val) {
if (val === false) { $scope.canAdd = (val === false) ? false : true;
$scope.canAdd = false;
}
}); });
setScopeFields(data); setScopeFields(data);

View File

@@ -14,21 +14,23 @@ const user_type_options = [
export default ['$scope', '$rootScope', 'Rest', 'UserList', 'Prompt', export default ['$scope', '$rootScope', 'Rest', 'UserList', 'Prompt',
'ProcessErrors', 'GetBasePath', 'Wait', '$state', '$filter', 'ProcessErrors', 'GetBasePath', 'Wait', '$state', '$filter',
'rbacUiControlService', 'Dataset', 'i18n', 'rbacUiControlService', 'Dataset', 'i18n', 'resolvedModels',
function($scope, $rootScope, Rest, UserList, Prompt, function($scope, $rootScope, Rest, UserList, Prompt,
ProcessErrors, GetBasePath, Wait, $state, $filter, rbacUiControlService, ProcessErrors, GetBasePath, Wait, $state, $filter, rbacUiControlService,
Dataset, i18n) { Dataset, i18n, models) {
for (var i = 0; i < user_type_options.length; i++) { for (var i = 0; i < user_type_options.length; i++) {
user_type_options[i].label = i18n._(user_type_options[i].label); user_type_options[i].label = i18n._(user_type_options[i].label);
} }
const { me } = models;
var list = UserList, var list = UserList,
defaultUrl = GetBasePath('users'); defaultUrl = GetBasePath('users');
init(); init();
function init() { function init() {
$scope.canEdit = me.get('summary_fields.user_capabilities.edit');
$scope.canAdd = false; $scope.canAdd = false;
rbacUiControlService.canAdd('users') rbacUiControlService.canAdd('users')

View File

@@ -43,6 +43,26 @@ angular.module('Users', [])
activityStream: true, activityStream: true,
activityStreamTarget: 'user' activityStreamTarget: 'user'
}, },
resolve: {
edit: {
resolvedModels: ['MeModel', '$q', function(Me, $q) {
const promises= {
me: new Me('get').then((me) => me.extend('get', 'admin_of_organizations'))
};
return $q.all(promises);
}]
},
list: {
resolvedModels: ['MeModel', '$q', function(Me, $q) {
const promises= {
me: new Me('get')
};
return $q.all(promises);
}]
}
},
ncyBreadcrumb: { ncyBreadcrumb: {
label: N_('USERS') label: N_('USERS')
} }

View File

@@ -20,7 +20,10 @@ export default ['i18n', function(i18n) {
stateTree: 'users', stateTree: 'users',
forceListeners: true, forceListeners: true,
tabs: true, tabs: true,
messageBar: {
ngShow: 'isOrgAdmin && !canEdit',
message: i18n._("Contact your System Administrator to grant you the appropriate permissions to add and edit Users and Teams.")
},
fields: { fields: {
first_name: { first_name: {
label: i18n._('First Name'), label: i18n._('First Name'),

View File

@@ -48,7 +48,7 @@ export default ['i18n', function(i18n) {
awToolTip: i18n._('Create a new user'), awToolTip: i18n._('Create a new user'),
actionClass: 'btn List-buttonSubmit', actionClass: 'btn List-buttonSubmit',
buttonContent: '&#43; ' + i18n._('ADD'), buttonContent: '&#43; ' + i18n._('ADD'),
ngShow: 'canAdd' ngShow: 'canAdd && canEdit'
} }
}, },