public async Task<ActionResult> ManageNewUsers(NewUsersListViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var message = new SetUserApprovals(
                model.Users
                    .Where(u => u.Action.HasValue)
                    .Select(u => new UserApproval(u.UserData.Id, u.Action.Value, u.AssignedRole))
                    .ToList());

            await mediator.SendAsync(message);

            return RedirectToAction("Index", "Home");
        }
Esempio n. 2
0
        public async Task RequestTargetsMissingUser_ReturnsFalseAndDoesNotSave()
        {
            userContext.ReturnsId = InternalUserCollection.ThisUserAdminApprovedUserId;

            var message = new SetUserApprovals(new[]
            {
                new UserApproval(Guid.Empty, ApprovalAction.Approve, UserRole.Administrator),
                new UserApproval(InternalUserCollection.AdminPendingId,
                                 ApprovalAction.Approve, UserRole.Administrator)
            });

            var result = await handler.HandleAsync(message);

            Assert.False(result);
            Assert.Equal(InternalUserStatus.Pending,
                         getUserStatusFromContext(InternalUserCollection.AdminPendingUserId, context));
        }
Esempio n. 3
0
        public async Task <ActionResult> ManageNewUsers(NewUsersListViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var message = new SetUserApprovals(
                model.Users
                .Where(u => u.Action.HasValue)
                .Select(u => new UserApproval(u.UserData.Id, u.Action.Value, u.AssignedRole))
                .ToList());

            await mediator.SendAsync(message);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 4
0
        public SetUserApprovalsHandlerTests()
        {
            userContext = new TestUserContext(Guid.Empty);
            context     = new TestIwsContext(userContext);

            context.InternalUsers.AddRange(new InternalUserCollection().Users);
            var userManager = A.Fake <UserManager <ApplicationUser> >();

            handler = new SetUserApprovalsHandler(context, userContext, userManager);

            approvePendingAdminMessage = new SetUserApprovals(new[]
            {
                new UserApproval(InternalUserCollection.AdminPendingId,
                                 ApprovalAction.Approve, UserRole.Administrator)
            });

            getUserStatusFromContext =
                (id, ctxt) => { return(ctxt.InternalUsers.Single(u => u.UserId == id.ToString()).Status); };
        }
        public SetUserApprovalsHandlerTests()
        {
            userContext = new TestUserContext(Guid.Empty);
            context = new TestIwsContext(userContext);

            context.InternalUsers.AddRange(new InternalUserCollection().Users);
            var userManager = A.Fake<UserManager<ApplicationUser>>();

            handler = new SetUserApprovalsHandler(context, userContext, userManager);

            approvePendingAdminMessage = new SetUserApprovals(new[]
            {
                new UserApproval(InternalUserCollection.AdminPendingId,
                    ApprovalAction.Approve, UserRole.Administrator)
            });

            getUserStatusFromContext =
                (id, ctxt) => { return ctxt.InternalUsers.Single(u => u.UserId == id.ToString()).Status; };
        }
        public async Task RequestTargetsMissingUser_ReturnsFalseAndDoesNotSave()
        {
            userContext.ReturnsId = InternalUserCollection.ThisUserAdminApprovedUserId;

            var message = new SetUserApprovals(new[]
            {
                new UserApproval(Guid.Empty, ApprovalAction.Approve, UserRole.Administrator),
                new UserApproval(InternalUserCollection.AdminPendingId,
                    ApprovalAction.Approve, UserRole.Administrator)
            });

            var result = await handler.HandleAsync(message);

            Assert.False(result);
            Assert.Equal(InternalUserStatus.Pending,
                getUserStatusFromContext(InternalUserCollection.AdminPendingUserId, context));
        }