Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        private bool NotifyNullRole(LedgerIdentityRole role)
        {
            if (role == null)
            {
                AddNotification("Role inválida", "Não existe uma role com esse nome.");
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetByName(string name)
        {
            LedgerIdentityRole role = await _roleApplicationService.GetByName(name);

            return(CreateResponse(role));
        }
Ejemplo n.º 6
0
 public bool IsInRole(LedgerIdentityRole role)
 {
     return(_claims.Any(r => r.Type == ClaimTypes.Role && r.Value == role.Name));
 }
Ejemplo n.º 7
0
        public async Task <LedgerIdentityRole> GetByName(string name)
        {
            LedgerIdentityRole role = await _roleManager.FindByNameAsync(name);

            return(role);
        }
Ejemplo n.º 8
0
 private async Task <bool> CanDeleteRole(LedgerIdentityRole role)
 {
     return(!(await _userManager.GetUsersInRoleAsync(role.Name)).Any());
 }