mirror of
https://github.com/ansible/awx.git
synced 2026-03-04 10:11:05 -03:30
Merge pull request #1509 from marshmalien/fix/1380-org-admin-ig-access
Show instance groups tab if user is an Org Admin
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const templateUrl = require('~components/layout/layout.partial.html');
|
const templateUrl = require('~components/layout/layout.partial.html');
|
||||||
|
|
||||||
function AtLayoutController ($scope, strings, $transitions) {
|
function AtLayoutController ($scope, $http, strings, ProcessErrors, $transitions) {
|
||||||
const vm = this || {};
|
const vm = this || {};
|
||||||
|
|
||||||
$transitions.onSuccess({}, (transition) => {
|
$transitions.onSuccess({}, (transition) => {
|
||||||
@@ -9,10 +9,14 @@ function AtLayoutController ($scope, strings, $transitions) {
|
|||||||
|
|
||||||
$scope.$watch('$root.current_user', (val) => {
|
$scope.$watch('$root.current_user', (val) => {
|
||||||
vm.isLoggedIn = val && val.username;
|
vm.isLoggedIn = val && val.username;
|
||||||
if (val) {
|
if (!_.isEmpty(val)) {
|
||||||
vm.isSuperUser = $scope.$root.user_is_superuser || $scope.$root.user_is_system_auditor;
|
vm.isSuperUser = $scope.$root.user_is_superuser || $scope.$root.user_is_system_auditor;
|
||||||
vm.currentUsername = val.username;
|
vm.currentUsername = val.username;
|
||||||
vm.currentUserId = val.id;
|
vm.currentUserId = val.id;
|
||||||
|
|
||||||
|
if (!vm.isSuperUser) {
|
||||||
|
checkOrgAdmin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,9 +36,27 @@ function AtLayoutController ($scope, strings, $transitions) {
|
|||||||
return strings.get(string);
|
return strings.get(string);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function checkOrgAdmin () {
|
||||||
|
const usersPath = `/api/v2/users/${vm.currentUserId}/admin_of_organizations/`;
|
||||||
|
$http.get(usersPath)
|
||||||
|
.then(({ data }) => {
|
||||||
|
if (data.count > 0) {
|
||||||
|
vm.isOrgAdmin = true;
|
||||||
|
} else {
|
||||||
|
vm.isOrgAdmin = 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', 'ComponentsStrings', '$transitions'];
|
AtLayoutController.$inject = ['$scope', '$http', 'ComponentsStrings', 'ProcessErrors', '$transitions'];
|
||||||
|
|
||||||
function atLayout () {
|
function atLayout () {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@
|
|||||||
system-admin-only="true">
|
system-admin-only="true">
|
||||||
</at-side-nav-item>
|
</at-side-nav-item>
|
||||||
<at-side-nav-item icon-class="fa-server" route="instanceGroups" name="INSTANCE_GROUPS"
|
<at-side-nav-item icon-class="fa-server" route="instanceGroups" name="INSTANCE_GROUPS"
|
||||||
system-admin-only="true">
|
ng-show="$parent.layoutVm.isSuperUser || $parent.layoutVm.isOrgAdmin">
|
||||||
</at-side-nav-item>
|
</at-side-nav-item>
|
||||||
<at-side-nav-item icon-class="fa-cubes" route="applications" name="APPLICATIONS"
|
<at-side-nav-item icon-class="fa-cubes" route="applications" name="APPLICATIONS"
|
||||||
system-admin-only="true">
|
system-admin-only="true">
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
describe('Components | Layout', () => {
|
describe('Components | Layout', () => {
|
||||||
let $compile;
|
let $compile;
|
||||||
let $rootScope;
|
let $rootScope;
|
||||||
|
let $httpBackend;
|
||||||
let element;
|
let element;
|
||||||
let scope;
|
let scope;
|
||||||
|
|
||||||
@@ -10,11 +11,14 @@ describe('Components | Layout', () => {
|
|||||||
angular.mock.module('ui.router');
|
angular.mock.module('ui.router');
|
||||||
angular.mock.module('at.lib.services');
|
angular.mock.module('at.lib.services');
|
||||||
angular.mock.module('at.lib.components');
|
angular.mock.module('at.lib.components');
|
||||||
|
angular.mock.module('Utilities');
|
||||||
|
angular.mock.module('ngCookies');
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(angular.mock.inject((_$compile_, _$rootScope_) => {
|
beforeEach(angular.mock.inject((_$compile_, _$rootScope_, _$httpBackend_) => {
|
||||||
$compile = _$compile_;
|
$compile = _$compile_;
|
||||||
$rootScope = _$rootScope_;
|
$rootScope = _$rootScope_;
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
scope = $rootScope.$new();
|
scope = $rootScope.$new();
|
||||||
|
|
||||||
element = angular.element('<at-layout></at-layout>');
|
element = angular.element('<at-layout></at-layout>');
|
||||||
@@ -26,7 +30,15 @@ describe('Components | Layout', () => {
|
|||||||
let controller;
|
let controller;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
const mockResponse = {
|
||||||
|
data: {
|
||||||
|
count: 3
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
controller = element.controller('atLayout');
|
controller = element.controller('atLayout');
|
||||||
|
$httpBackend.when('GET', /admin_of_organizations/)
|
||||||
|
.respond(mockResponse);
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('$scope.$on($stateChangeSuccess) should assign toState name to currentState', () => {
|
xit('$scope.$on($stateChangeSuccess) should assign toState name to currentState', () => {
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ describe('Components | Side Nav Item', () => {
|
|||||||
angular.mock.module('ui.router');
|
angular.mock.module('ui.router');
|
||||||
angular.mock.module('at.lib.services');
|
angular.mock.module('at.lib.services');
|
||||||
angular.mock.module('at.lib.components');
|
angular.mock.module('at.lib.components');
|
||||||
|
angular.mock.module('Utilities');
|
||||||
|
angular.mock.module('ngCookies');
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(angular.mock.inject((_$compile_, _$rootScope_) => {
|
beforeEach(angular.mock.inject((_$compile_, _$rootScope_) => {
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ describe('Components | Side Nav', () => {
|
|||||||
angular.mock.module('at.lib.components', ($provide) => {
|
angular.mock.module('at.lib.components', ($provide) => {
|
||||||
$provide.value('$window', windowMock);
|
$provide.value('$window', windowMock);
|
||||||
});
|
});
|
||||||
|
angular.mock.module('Utilities');
|
||||||
|
angular.mock.module('ngCookies');
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(angular.mock.inject((_$compile_, _$rootScope_) => {
|
beforeEach(angular.mock.inject((_$compile_, _$rootScope_) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user