Merge pull request #1931 from anoek/1919

Implemented team role removal
This commit is contained in:
Akita Noek 2016-05-16 16:25:45 -04:00
commit a532e63539
4 changed files with 54 additions and 39 deletions

View File

@ -26,6 +26,10 @@
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
.fa-users {
margin-left: 0.5em;
}
}
.RoleList-tag--deletable {

View File

@ -11,23 +11,16 @@ export default
// auditor") which are pulled from two different
// places in summary fields, and creates a
// concatenated/sorted list
scope.roles = []
scope.access_list = []
.concat(scope.permission.summary_fields
.direct_access.map(function(i) {
return {
name: i.role.name,
roleId: i.role.id,
resourceName: i.role.resource_name,
explicit: true
};
i.role.explicit = true;
return i.role;
}))
.concat(scope.permission.summary_fields
.indirect_access.map(function(i) {
return {
name: i.role.name,
roleId: i.role.id,
explicit: false
};
i.role.explicit = false;
return i.role;
}))
.sort(function(a, b) {
if (a.name

View File

@ -1,13 +1,14 @@
<div class="RoleList-tagContainer"
ng-repeat="role in roles">
ng-repeat="entry in access_list">
<div class="RoleList-deleteContainer"
ng-if="role.explicit"
ng-click="deletePermission(permission.id, role.roleId, permission.username, role.name, role.resourceName)">
<i ng-if="role.explicit"
ng-if="entry.explicit"
ng-click="deletePermission(permission, entry)">
<i ng-if="entry.explicit"
class="fa fa-times RoleList-tagDelete"></i>
</div>
<div class="RoleList-tag"
ng-class="{'RoleList-tag--deletable': role.explicit}">
<span class="RoleList-name">{{ role.name }}</span>
ng-class="{'RoleList-tag--deletable': entry.explicit}">
<span class="RoleList-name">{{ entry.name }}</span>
<i ng-show='entry.team_id' class="fa fa-users" ng-attr-title='{{entry.team_name}}'></i>
</div>
</div>

View File

@ -513,31 +513,48 @@ var tower = angular.module('Tower', [
$compile("<add-permissions class='AddPermissions'></add-permissions>")(scope);
};
$rootScope.deletePermission = function (user, role, userName,
roleName, resourceName) {
var action = function () {
$('#prompt-modal').modal('hide');
Wait('start');
var url = GetBasePath("users") + user + "/roles/";
Rest.setUrl(url);
Rest.post({"disassociate": true, "id": role})
.success(function () {
Wait('stop');
$rootScope.$broadcast("refreshList", "permission");
})
.error(function (data, status) {
ProcessErrors($rootScope, data, status, null, { hdr: 'Error!',
msg: 'Could not disacssociate user from role. Call to ' + url + ' failed. DELETE returned status: ' + status });
});
};
$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');
$rootScope.$broadcast("refreshList", "permission");
})
.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: 'Remove Role from ' + resourceName,
body: '<div class="Prompt-bodyQuery">Confirm the removal of the <span class="Prompt-emphasis">' + roleName + '</span> role associated with ' + userName + '.</div>',
action: action,
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">${entry.team_name}</span>. This will affect all members of 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 () {