Exemplo n.º 1
0
        private ActionList GetActions(ApplicationUser user)
        {
            var result  = new ActionList();
            var isAdmin = user.Roles.Any(t => t.Role.Name == UserManagementRoles.UserAdmin.Name);

            if (this.permissionManager.CanAccess <EditUser>())
            {
                result.Actions.Add(EditUser.Button(user.Id, UiFormConstants.EditLabel)
                                   .WithCustomUi(LinkStyle.PrimarySmall));

                result.Actions.Add(new FormLink
                {
                    Form             = "start-impersonation",
                    Label            = UiFormConstants.ImpersonationLabel,
                    InputFieldValues = new Dictionary <string, object>
                    {
                        { nameof(Request.Id), user.Id }
                    }
                }.WithAction(FormLinkActions.Run).WithCustomUi(LinkStyle.Small));
            }

            if (!user.HasLoggedIn && this.permissionManager.CanAccess <DeleteUser>())
            {
                result.Actions.Add(DeleteUser.Button(user.Id, UiFormConstants.DeleteLabel)
                                   .WithCustomUi(LinkStyle.DangerSmall));
            }

            var hasPassword = this.userManager.HasPasswordAsync(user).Result;

            if (!hasPassword && !user.EmailConfirmed && this.permissionManager.CanAccess <ResendAccountConfirmationEmail>())
            {
                result.Actions.Add(ResendAccountConfirmationEmail
                                   .Button(user.Id).WithCustomUi(LinkStyle.PrimarySmall));
            }

            if (!isAdmin &&
                this.permissionManager.CanAccess <ActivateUser>() &&
                !user.Active)
            {
                result.Actions.Add(ActivateUser.Button(user.Id).WithCustomUi(LinkStyle.SuccessSmall));
            }

            if (!isAdmin &&
                this.permissionManager.CanAccess <DeactivateUser>() &&
                user.Active)
            {
                result.Actions.Add(DeactivateUser.Button(user.Id).WithCustomUi(LinkStyle.DangerSmall));
            }

            return(result);
        }
Exemplo n.º 2
0
        private ActionList GetActions(ApplicationUser user)
        {
            var result  = new ActionList();
            var isAdmin = user.Roles.Any(t => t.Role.Name == UserManagementRoles.UserAdmin.Name);

            if (this.permissionManager.CanAccess <EditUser>())
            {
                result.Actions.Add(EditUser.Button(user.Id, UiFormConstants.EditLabel).WithCustomUi("btn-primary btn-sm"));
            }

            if (this.permissionManager.CanAccess <StartImpersonation>())
            {
                result.Actions.Add(StartImpersonation.Button(user.Id));
            }

            if (!user.HasLoggedIn && this.permissionManager.CanAccess <DeleteUser>())
            {
                result.Actions.Add(DeleteUser.Button(user.Id, UiFormConstants.DeleteLabel).WithCustomUi("btn-danger btn-sm"));
            }

            var hasPassword = this.userManager.HasPasswordAsync(user).Result;

            if (!hasPassword && !user.EmailConfirmed && this.permissionManager.CanAccess <ResendAccountConfirmationEmail>())
            {
                result.Actions.Add(ResendAccountConfirmationEmail.Button(user.Id).WithCustomUi("btn-primary btn-sm"));
            }

            if (!isAdmin &&
                this.permissionManager.CanAccess <ActivateUser>() &&
                !user.Active)
            {
                result.Actions.Add(ActivateUser.Button(user.Id).WithCustomUi("btn-success btn-sm"));
            }

            if (!isAdmin &&
                this.permissionManager.CanAccess <DeactivateUser>() &&
                user.Active)
            {
                result.Actions.Add(DeactivateUser.Button(user.Id).WithCustomUi("btn-danger btn-sm"));
            }

            return(result);
        }