public async Task Remove(RemoveRoleCommand command) { command.Validate(); if (AddNotifications(command)) { return; } LedgerIdentityRole role = await GetByName(command.RoleName); if (NotifyNullRole(role)) { return; } bool canDelete = await CanDeleteRole(role); if (!canDelete) { AddNotification("Falha ao remover", "Não é possível remover essa role enquanto ouver usuários nela."); return; } IdentityResult result = await _roleManager.DeleteAsync(role); if (result.Succeeded) { await Publish(new RoleRemovedIntegrationEvent(role.Name)); } else { AddNotifications(result); } }
private bool NotifyNullRole(LedgerIdentityRole role) { if (role == null) { AddNotification("Role inválida", "Não existe uma role com esse nome."); return(true); } return(false); }
private bool NotifyCantAccessTicket(Ticket ticket) { LedgerIdentityUser user = _identityResolver.GetUser(); LedgerIdentityRole supportRole = new LedgerIdentityRole(RoleTypes.Support); bool canAccessTicket = ticket.TicketUserId == user.Id || user.IsInRole(supportRole); if (!canAccessTicket) { AddNotification("Usuário inválido", "O usuário não tem autorização para acessar os dados."); return(true); } return(false); }
public async Task Register(RegisterRoleCommand command) { command.Validate(); if (AddNotifications(command)) { return; } LedgerIdentityRole role = new LedgerIdentityRole(command.Name); IdentityResult result = await _roleManager.CreateAsync(role); if (result.Succeeded) { await Publish(new RoleRegisteredIntegrationEvent(role.Id, role.Name)); } else { AddNotifications(result); } }
public async Task <IActionResult> GetByName(string name) { LedgerIdentityRole role = await _roleApplicationService.GetByName(name); return(CreateResponse(role)); }
public bool IsInRole(LedgerIdentityRole role) { return(_claims.Any(r => r.Type == ClaimTypes.Role && r.Value == role.Name)); }
public async Task <LedgerIdentityRole> GetByName(string name) { LedgerIdentityRole role = await _roleManager.FindByNameAsync(name); return(role); }
private async Task <bool> CanDeleteRole(LedgerIdentityRole role) { return(!(await _userManager.GetUsersInRoleAsync(role.Name)).Any()); }