예제 #1
0
        private static async Task FillUserDataForStateAsync(FindUserData data, AdminFindUserState stateToFillDataFor, string actionButtonText, string actionToPostTo,
                                                            int roleIDWhichUsersToExclude = 0)
        {
            data.Roles = await SecurityGuiHelper.GetAllRolesAsync();

            switch (stateToFillDataFor)
            {
            case AdminFindUserState.Start:
                // no-op
                break;

            case AdminFindUserState.UsersFound:
                data.FoundUsers = await UserGuiHelper.FindUsers(data.FilterOnRole, data.SelectedRoleID, data.FilterOnNickName, data.SpecifiedNickName,
                                                                data.FilterOnEmailAddress, data.SpecifiedEmailAddress, roleIDWhichUsersToExclude);

                break;

            case AdminFindUserState.FinalAction:
            case AdminFindUserState.PostAction:
                data.SelectedUsers = await UserGuiHelper.GetAllUsersInRangeAsync(data.SelectedUserIDs);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(stateToFillDataFor), stateToFillDataFor, null);
            }

            data.FindUserState    = stateToFillDataFor;
            data.ActionButtonText = actionButtonText;
            data.ActionToPostTo   = actionToPostTo;
        }
예제 #2
0
        private async Task <AddUsersToRoleData> CreateFilledAddUsersToRoleDataAsync(FindUserData userData, int roleID)
        {
            var selectedRole = await SecurityGuiHelper.GetRoleAsync(roleID);

            return(new AddUsersToRoleData(userData)
            {
                SelectedRoleDescription = selectedRole?.RoleDescription ?? string.Empty, SelectedRoleID = selectedRole?.RoleID ?? 0
            });
        }
예제 #3
0
        private void FilterFoundUsers(FindUserData toFilter)
        {
            if (toFilter?.FoundUsers == null)
            {
                return;
            }

            // filter out the currently logged in user, admin (1) and anonymous (0)
            var loggedInUserId = this.HttpContext.Session.GetUserID();
            var toRemove       = new List <UserEntity>();

            foreach (var e in toFilter.FoundUsers)
            {
                if (e.UserID < 2 || e.UserID == loggedInUserId)
                {
                    toRemove.Add(e);
                }
            }

            foreach (var e in toRemove)
            {
                toFilter.FoundUsers.Remove(e);
            }
        }
예제 #4
0
 public AddUsersToRoleData(FindUserData data) : base(data ?? new FindUserData())
 {
 }
예제 #5
0
 public ActionWithUserSearchData(FindUserData data)
 {
     this.FindUserData      = data;
     this.FinalActionResult = string.Empty;
 }
예제 #6
0
        private async Task <ActionResult> ActionWithUserSearch_UserSelectedAsync(Func <FindUserData, Task <ActionWithUserSearchData> > dataCreatorFunc, FindUserData data,
                                                                                 string submitAction, Func <Task <ActionResult> > actionSearchAgainFunc,
                                                                                 Func <FindUserData, Task <ActionResult> > actionNoneSelectedFunc, string nextActionName,
                                                                                 string viewName)
        {
            if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.UserManagement))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (submitAction == "SearchAgain")
            {
                return(await actionSearchAgainFunc());
            }

            if (submitAction != "PerformAction")
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (data.SelectedUserIDs == null || data.SelectedUserIDs.Count <= 0)
            {
                return(await actionNoneSelectedFunc(data));
            }

            await FillUserDataForStateAsync(data, AdminFindUserState.FinalAction, string.Empty, nextActionName);

            return(View(viewName, await dataCreatorFunc(data)));
        }
예제 #7
0
        private async Task <ActionResult> ActionWithUserSearch_FindAsync(Func <FindUserData, Task <ActionWithUserSearchData> > dataCreatorFunc, FindUserData data,
                                                                         string actionButtonText, string nextActionNameValidSearchData,
                                                                         string nextActionNameInvalidSearchData, string viewName, bool filterOutFixedUsers,
                                                                         int roleIDWhichUsersToExclude = 0)
        {
            if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.SystemManagement))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (data.IsAnythingChecked)
            {
                await FillUserDataForStateAsync(data, AdminFindUserState.UsersFound, actionButtonText, nextActionNameValidSearchData,
                                                roleIDWhichUsersToExclude);

                if (filterOutFixedUsers)
                {
                    // filter out the currently logged in user, Anonymous (0) and Admin (1)
                    FilterFoundUsers(data);
                }
            }
            else
            {
                await FillUserDataForStateAsync(data, AdminFindUserState.Start, string.Empty, nextActionNameInvalidSearchData);
            }

            return(View(viewName, await dataCreatorFunc(data)));
        }