Merge pull request #2939 from mabashian/2930-notif-admin

Handle notification admin user type in the UI
This commit is contained in:
Michael Abashian 2018-08-28 11:22:46 -04:00 committed by GitHub
commit 2949efd6ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 52 additions and 12 deletions

View File

@ -16,6 +16,7 @@ function AtLayoutController ($scope, $http, strings, ProcessErrors, $transitions
if (!vm.isSuperUser) {
checkOrgAdmin();
checkNotificationAdmin();
}
}
});
@ -54,6 +55,24 @@ function AtLayoutController ($scope, $http, strings, ProcessErrors, $transitions
});
});
}
function checkNotificationAdmin () {
const usersPath = `/api/v2/users/${vm.currentUserId}/roles/?role_field=notification_admin_role`;
$http.get(usersPath)
.then(({ data }) => {
if (data.count > 0) {
vm.isNotificationAdmin = true;
} else {
vm.isNotificationAdmin = false;
}
})
.catch(({ data, status }) => {
ProcessErrors(null, data, status, null, {
hdr: strings.get('error.HEADER'),
msg: strings.get('error.CALL', { path: usersPath, action: 'GET', status })
});
});
}
}
AtLayoutController.$inject = ['$scope', '$http', 'ComponentsStrings', 'ProcessErrors', '$transitions'];

View File

@ -81,10 +81,10 @@
<span>
</div>
<at-side-nav-item icon-class="fa-list-alt" route="credentialTypes" name="CREDENTIAL_TYPES"
system-admin-only="true">
system-admin-only="true">
</at-side-nav-item>
<at-side-nav-item icon-class="fa-bell" route="notifications" name="NOTIFICATIONS"
system-admin-only="true">
ng-show="$parent.layoutVm.isSuperUser || $parent.layoutVm.isOrgAdmin || $parent.layoutVm.isNotificationAdmin">
</at-side-nav-item>
<at-side-nav-item icon-class="fa-briefcase" route="managementJobsList" name="MANAGEMENT_JOBS"
system-admin-only="true">

View File

@ -88,7 +88,7 @@ export default ['$rootScope', '$scope', 'GetBasePath', 'Rest', '$q', 'Wait', 'Pr
};
scope.hasSelectedRows = function(){
return _.any(scope.allSelected, (type) => Object.keys(type).length > 0);
return _.some(scope.allSelected, (type) => Object.keys(type).length > 0);
};
scope.selectTab = function(selected){

View File

@ -94,7 +94,7 @@ function(scope, $state, i18n, CreateSelect2, Rest, $q, Wait, ProcessErrors) {
};
scope.showSection2Container = function(){
return _.any(scope.allSelected, (type) => Object.keys(type).length > 0);
return _.some(scope.allSelected, (type) => Object.keys(type).length > 0);
};
scope.showSection2Tab = function(tab){

View File

@ -22,7 +22,7 @@ export default ['Rest', 'Wait', 'NotificationsFormObject',
init();
function init() {
Rest.setUrl(GetBasePath('projects'));
Rest.setUrl(GetBasePath('notification_templates'));
Rest.options()
.then(({data}) => {
if (!data.actions.POST) {

View File

@ -275,7 +275,7 @@ export default ['Rest', 'Wait',
return $scope[i];
}
params.notification_configuration = _.object(Object.keys(form.fields)
params.notification_configuration = _.fromPairs(Object.keys(form.fields)
.filter(i => (form.fields[i].ngShow && form.fields[i].ngShow.indexOf(v) > -1))
.map(i => [i, processValue($scope[i], i, form.fields[i])]));

View File

@ -670,6 +670,8 @@ function(ConfigurationUtils, i18n, $rootScope) {
query += '&role_level=workflow_admin_role';
} else if ($state.current.name.includes('projects')) {
query += '&role_level=project_admin_role';
} else if ($state.current.name.includes('notifications')) {
query += '&role_level=notification_admin_role';
} else {
query += '&role_level=admin_role';
}

View File

@ -744,10 +744,20 @@ function($injector, $stateExtender, $log, i18n) {
// search will think they need to be set as search tags.
var params;
if(field.sourceModel === "organization"){
params = {
page_size: '5',
role_level: 'admin_role'
};
if (form.name === "notification_template") {
// Users with admin_role role level should also have
// notification_admin_role so this should handle regular admin
// users as well as notification admin users
params = {
page_size: '5',
role_level: 'notification_admin_role'
};
} else {
params = {
page_size: '5',
role_level: 'admin_role'
};
}
}
else if(field.sourceModel === "inventory_script"){
params = {

View File

@ -30,15 +30,24 @@ describe('Components | Layout', () => {
let controller;
beforeEach(() => {
const mockResponse = {
const mockOrgAdminResponse = {
data: {
count: 3
}
};
const mockNotificationAdminResponse = {
data: {
count: 1
}
};
controller = element.controller('atLayout');
$httpBackend.when('GET', /admin_of_organizations/)
.respond(mockResponse);
.respond(mockOrgAdminResponse);
$httpBackend.when('GET', /roles\/\?role_field=notification_admin_role/)
.respond(mockNotificationAdminResponse);
});
xit('$scope.$on($stateChangeSuccess) should assign toState name to currentState', () => {