public async Task <IActionResult> DeleteScopeRelationAsync([FromRoute] Guid roleId, [FromRoute] Guid scopeId) { List <Scope> scopes; if (this.UserHasScope(RoleScopes.Admin)) { scopes = await _deleteRoleScopeRelationService.DeleteScopeRelationAsync(roleId, scopeId); } else { scopes = await _deleteRoleScopeRelationService.DeleteScopeRelationAsync(roleId, scopeId, this.GetUserId()); } var remaining = scopes.Select(s => ScopeResponseDto.FromScope(s, false)); return(Ok(remaining)); }
public async Task <IActionResult> GetScopesAsync([FromRoute] Guid roleId) { List <Scope> scopes; if (this.UserHasScope(RoleScopes.Admin)) { scopes = await _getScopesService.GetByRoleIdAsync(roleId); } else { scopes = await _getScopesService.GetByRoleIdAsync(roleId, this.GetUserId()); } var found = scopes.Select(s => ScopeResponseDto.FromScope(s, false)); return(Ok(found)); }
public static RoleResponseDto FromRole(Role role, bool includeChildren) { var dto = new RoleResponseDto { role_id = role.RoleId, name = role.Name, description = role.Description, application_id = role.ApplicationId, created_date = role.CreatedDateTime, modified_date = role.ModifiedDateTime }; if (includeChildren) { dto.scopes = role.Scopes?.Select(s => ScopeResponseDto.FromScope(s, false)).ToList(); } return(dto); }