mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
Merge branch '4272-add-team-user' of https://github.com/mabashian/ansible-tower into mabashian-4272-add-team-user
# Conflicts: # awx/ui/client/src/shared/stateDefinitions.factory.js
This commit is contained in:
commit
80fd0bd2e8
@ -84,7 +84,7 @@ export default ['$rootScope', '$scope', 'GetBasePath', 'Rest', '$q', 'Wait', 'Pr
|
||||
.map(function(role) {
|
||||
return {
|
||||
url: url,
|
||||
id: role.value
|
||||
id: role.value || role.id
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
@ -15,6 +15,7 @@ export default ['templateUrl', '$state',
|
||||
usersDataset: '=',
|
||||
teamsDataset: '=',
|
||||
resourceData: '=',
|
||||
withoutTeamPermissions: '@'
|
||||
},
|
||||
controller: controller,
|
||||
templateUrl: templateUrl('access/add-rbac-resource/rbac-resource'),
|
||||
|
||||
@ -39,16 +39,15 @@
|
||||
</div>
|
||||
<div id="teams_tab" class="Form-tab"
|
||||
ng-click="toggleFormTabs('teams')"
|
||||
ng-class="{'is-selected': teamsSelected }"
|
||||
>
|
||||
ng-class="{'is-selected': teamsSelected }">
|
||||
Teams
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="AddPermissions-users" class="AddPermissions-list" ng-show="usersSelected">
|
||||
<div id="AddPermissions-users" class="AddPermissions-list" ng-if="usersSelected">
|
||||
<rbac-multiselect-list view="Users" all-selected="allSelected" dataset="usersDataset"></rbac-multiselect-list>
|
||||
</div>
|
||||
<div id="AddPermissions-teams" class="AddPermissions-list" ng-show="teamsSelected">
|
||||
<div id="AddPermissions-teams" class="AddPermissions-list" ng-if="teamsSelected">
|
||||
<rbac-multiselect-list view="Teams" all-selected="allSelected" dataset="teamsDataset"></rbac-multiselect-list>
|
||||
</div>
|
||||
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
/* jshint unused: vars */
|
||||
export default
|
||||
[ 'templateUrl',
|
||||
function(templateUrl) {
|
||||
[ 'templateUrl', 'Wait', 'GetBasePath', 'Rest', '$state', 'ProcessErrors', 'Prompt', '$filter', '$rootScope',
|
||||
function(templateUrl, Wait, GetBasePath, Rest, $state, ProcessErrors, Prompt, $filter, $rootScope) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: true,
|
||||
scope: {
|
||||
'deleteTarget': '='
|
||||
},
|
||||
templateUrl: templateUrl('access/rbac-role-column/roleList'),
|
||||
link: function(scope, element, attrs) {
|
||||
// given a list of roles (things like "project
|
||||
@ -12,12 +14,12 @@ export default
|
||||
// places in summary fields, and creates a
|
||||
// concatenated/sorted list
|
||||
scope.access_list = []
|
||||
.concat(scope.permission.summary_fields
|
||||
.concat(scope.deleteTarget.summary_fields
|
||||
.direct_access.map((i) => {
|
||||
i.role.explicit = true;
|
||||
return i.role;
|
||||
}))
|
||||
.concat(scope.permission.summary_fields
|
||||
.concat(scope.deleteTarget.summary_fields
|
||||
.indirect_access.map((i) => {
|
||||
i.role.explicit = false;
|
||||
return i.role;
|
||||
@ -34,6 +36,51 @@ export default
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
|
||||
scope.deletePermission = function(user, accessListEntry) {
|
||||
let entry = accessListEntry;
|
||||
|
||||
let action = function() {
|
||||
$('#prompt-modal').modal('hide');
|
||||
Wait('start');
|
||||
|
||||
let url;
|
||||
if (entry.team_id) {
|
||||
url = GetBasePath("teams") + entry.team_id + "/roles/";
|
||||
} else {
|
||||
url = GetBasePath("users") + user.id + "/roles/";
|
||||
}
|
||||
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ "disassociate": true, "id": entry.id })
|
||||
.success(function() {
|
||||
Wait('stop');
|
||||
$state.go('.', null, { reload: true });
|
||||
})
|
||||
.error(function(data, status) {
|
||||
ProcessErrors($rootScope, data, status, null, {
|
||||
hdr: 'Error!',
|
||||
msg: 'Failed to remove access. Call to ' + url + ' failed. DELETE returned status: ' + status
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (accessListEntry.team_id) {
|
||||
Prompt({
|
||||
hdr: `Team access removal`,
|
||||
body: `<div class="Prompt-bodyQuery">Please confirm that you would like to remove <span class="Prompt-emphasis">${entry.name}</span> access from the team <span class="Prompt-emphasis">${$filter('sanitize')(entry.team_name)}</span>. This will affect all members of the team. If you would like to only remove access for this particular user, please remove them from the team.</div>`,
|
||||
action: action,
|
||||
actionText: 'REMOVE TEAM ACCESS'
|
||||
});
|
||||
} else {
|
||||
Prompt({
|
||||
hdr: `User access removal`,
|
||||
body: `<div class="Prompt-bodyQuery">Please confirm that you would like to remove <span class="Prompt-emphasis">${entry.name}</span> access from <span class="Prompt-emphasis">${user.username}</span>.</div>`,
|
||||
action: action,
|
||||
actionText: 'REMOVE'
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
ng-repeat="entry in access_list">
|
||||
<div class="RoleList-deleteContainer"
|
||||
ng-if="entry.explicit && entry.user_capabilities.unattach"
|
||||
ng-click="deletePermission(permission, entry)">
|
||||
ng-click="deletePermission(deleteTarget, entry)">
|
||||
<i ng-if="entry.explicit && entry.user_capabilities.unattach"
|
||||
class="fa fa-times RoleList-tagDelete"></i>
|
||||
</div>
|
||||
|
||||
@ -468,21 +468,6 @@ var tower = angular.module('Tower', [
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$stateExtender.addState({
|
||||
name: 'teamUsers',
|
||||
url: '/teams/:team_id/users',
|
||||
templateUrl: urlPrefix + 'partials/teams.html',
|
||||
controller: UsersList,
|
||||
resolve: {
|
||||
Users: ['UsersList', 'QuerySet', '$stateParams', 'GetBasePath', (list, qs, $stateParams, GetBasePath) => {
|
||||
let path = GetBasePath(list.basePath) || GetBasePath(list.name);
|
||||
return qs.search(path, $stateParams[`${list.iterator}_search`]);
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$stateExtender.addState({
|
||||
name: 'userCredentials',
|
||||
url: '/users/:user_id/credentials',
|
||||
@ -514,58 +499,6 @@ var tower = angular.module('Tower', [
|
||||
}
|
||||
});
|
||||
|
||||
$rootScope.addPermission = function(scope) {
|
||||
$compile("<add-permissions class='AddPermissions'></add-permissions>")(scope);
|
||||
};
|
||||
$rootScope.addPermissionWithoutTeamTab = function(scope) {
|
||||
$compile("<add-permissions class='AddPermissions' without-team-permissions='true'></add-permissions>")(scope);
|
||||
};
|
||||
|
||||
$rootScope.deletePermission = function(user, accessListEntry) {
|
||||
let entry = accessListEntry;
|
||||
|
||||
let action = function() {
|
||||
$('#prompt-modal').modal('hide');
|
||||
Wait('start');
|
||||
|
||||
let url;
|
||||
if (entry.team_id) {
|
||||
url = GetBasePath("teams") + entry.team_id + "/roles/";
|
||||
} else {
|
||||
url = GetBasePath("users") + user.id + "/roles/";
|
||||
}
|
||||
|
||||
Rest.setUrl(url);
|
||||
Rest.post({ "disassociate": true, "id": entry.id })
|
||||
.success(function() {
|
||||
Wait('stop');
|
||||
$state.go('.', null, { reload: true });
|
||||
})
|
||||
.error(function(data, status) {
|
||||
ProcessErrors($rootScope, data, status, null, {
|
||||
hdr: 'Error!',
|
||||
msg: 'Failed to remove access. Call to ' + url + ' failed. DELETE returned status: ' + status
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (accessListEntry.team_id) {
|
||||
Prompt({
|
||||
hdr: `Team access removal`,
|
||||
body: `<div class="Prompt-bodyQuery">Please confirm that you would like to remove <span class="Prompt-emphasis">${entry.name}</span> access from the team <span class="Prompt-emphasis">${$filter('sanitize')(entry.team_name)}</span>. This will affect all members of the team. If you would like to only remove access for this particular user, please remove them from the team.</div>`,
|
||||
action: action,
|
||||
actionText: 'REMOVE TEAM ACCESS'
|
||||
});
|
||||
} else {
|
||||
Prompt({
|
||||
hdr: `User access removal`,
|
||||
body: `<div class="Prompt-bodyQuery">Please confirm that you would like to remove <span class="Prompt-emphasis">${entry.name}</span> access from <span class="Prompt-emphasis">${user.username}</span>.</div>`,
|
||||
action: action,
|
||||
actionText: 'REMOVE'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$rootScope.deletePermissionFromUser = function(userId, userName, roleName, roleType, url) {
|
||||
var action = function() {
|
||||
$('#prompt-modal').modal('hide');
|
||||
|
||||
@ -467,7 +467,7 @@ angular.module('GeneratorHelpers', [systemStatus.name])
|
||||
Attr(field, 'columnClass') : "";
|
||||
html += `
|
||||
<td ${classList}>
|
||||
<role-list class=\"RoleList\">
|
||||
<role-list delete-target=\"${list.iterator}\" class=\"RoleList\">
|
||||
</role-list>
|
||||
</td>
|
||||
`;
|
||||
@ -476,7 +476,7 @@ angular.module('GeneratorHelpers', [systemStatus.name])
|
||||
Attr(field, 'columnClass') : "";
|
||||
html += `
|
||||
<td ${classList}>
|
||||
<role-list class=\"RoleList\" team-role-list="true">
|
||||
<role-list delete-target=\"${list.iterator}\" class=\"RoleList\" team-role-list="true">
|
||||
</role-list>
|
||||
</td>
|
||||
`;
|
||||
|
||||
@ -489,18 +489,18 @@ export default ['$location', '$compile', '$rootScope', 'Attr', 'Icon',
|
||||
|
||||
if (options.mode !== 'lookup'){
|
||||
for (fld in list.fields) {
|
||||
let customClass = list.fields[fld].columnClass || '';
|
||||
html += `<th
|
||||
base-path="${list.basePath || list.name}"
|
||||
collection="${list.name}"
|
||||
dataset="${list.iterator}_dataset"
|
||||
column-sort
|
||||
column-field="${fld}"
|
||||
column-iterator="${list.iterator}"
|
||||
column-no-sort="${list.fields[fld].nosort}"
|
||||
column-label="${list.fields[fld].label}"
|
||||
column-custom-class="${customClass}">
|
||||
</th>`;
|
||||
let customClass = list.fields[fld].columnClass || '';
|
||||
html += `<th
|
||||
base-path="${list.basePath || list.name}"
|
||||
collection="${list.name}"
|
||||
dataset="${list.iterator}_dataset"
|
||||
column-sort
|
||||
column-field="${fld}"
|
||||
column-iterator="${list.iterator}"
|
||||
column-no-sort="${list.fields[fld].nosort}"
|
||||
column-label="${list.fields[fld].label}"
|
||||
column-custom-class="${customClass}">
|
||||
</th>`;
|
||||
}
|
||||
}
|
||||
if (options.mode === 'lookup') {
|
||||
|
||||
@ -485,6 +485,44 @@ export default ['$injector', '$stateExtender', '$log', function($injector, $stat
|
||||
// }
|
||||
return state;
|
||||
}
|
||||
|
||||
function buildRbacUserDirective() {
|
||||
let states = [];
|
||||
|
||||
states.push($stateExtender.buildDefinition({
|
||||
name: `${formStateDefinition.name}.users.add`,
|
||||
squashSearchUrl: true,
|
||||
url: '/add-user',
|
||||
params: {
|
||||
user_search: {
|
||||
value: { order_by: 'username', page_size: '5' },
|
||||
dynamic: true,
|
||||
}
|
||||
},
|
||||
views: {
|
||||
[`modal@${formStateDefinition.name}`]: {
|
||||
template: `<add-rbac-resource users-dataset="$resolve.usersDataset" selected="allSelected" resource-data="$resolve.resourceData" without-team-permissions="true"></add-rbac-resource>`
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
usersDataset: ['addPermissionsUsersList', 'QuerySet', '$stateParams', 'GetBasePath',
|
||||
function(list, qs, $stateParams, GetBasePath) {
|
||||
let path = GetBasePath(list.basePath) || GetBasePath(list.name);
|
||||
return qs.search(path, $stateParams.user_search);
|
||||
|
||||
}
|
||||
]
|
||||
},
|
||||
onExit: function($state) {
|
||||
if ($state.transition) {
|
||||
$('#add-permissions-modal').modal('hide');
|
||||
$('.modal-backdrop').remove();
|
||||
$('body').removeClass('modal-open');
|
||||
}
|
||||
},
|
||||
}));
|
||||
return states;
|
||||
}
|
||||
|
||||
function buildListNodes(field) {
|
||||
let states = [];
|
||||
@ -497,14 +535,18 @@ export default ['$injector', '$stateExtender', '$log', function($injector, $stat
|
||||
if (field.iterator === 'permission' && field.actions && field.actions.add) {
|
||||
if (form.name === 'user' || form.name === 'team'){
|
||||
states.push(buildRbacUserTeamDirective());
|
||||
|
||||
}
|
||||
else {
|
||||
states.push(buildRbacResourceDirective());
|
||||
}
|
||||
states = _.flatten(states);
|
||||
}
|
||||
else if (field.iterator === 'user' && field.actions && field.actions.add) {
|
||||
if(form.name === 'team') {
|
||||
states.push(buildRbacUserDirective());
|
||||
}
|
||||
}
|
||||
}
|
||||
states = _.flatten(states);
|
||||
return states;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user