示例#1
0
        public ActionResult Moderators(string subName)
        {
            if (string.IsNullOrEmpty(subName))
            {
                throw new NotFoundException();
            }

            var sub = _subDao.GetSubByName(subName);

            if (sub == null)
            {
                throw new NotFoundException();
            }

            var model = new ModeratorsViewModel();

            model.Sub        = sub;
            model.Moderators = _moderatorWrapper.Wrap(_moderationDao.GetAllModsForSub(sub.Id), _userContext.CurrentUser);
            if (_userContext.CurrentUser != null)
            {
                if (_permissionDao.GetUserPermissionsForSub(_userContext.CurrentUser, sub.Id).HasPermission(ModeratorPermissions.All))
                {
                    // super mods can see all pending invites
                    model.Invites   = _moderatorInviteWrapper.Wrap(_moderationInviteDao.GetModeratorInvitesForSub(sub.Id));
                    model.CanInvite = true;
                }
                else
                {
                    // let's see if the current user has a pending invite
                    model.CurrentUserInvite = _moderationInviteDao.GetModeratorInviteInfo(_userContext.CurrentUser.Id, sub.Id);
                }
            }

            return(View(model));
        }
示例#2
0
        public IViewComponentResult Invoke(string subName, Guid?subId, bool showSearch, bool showCreateSub, bool showSubmit)
        {
            var model = new SidebarViewModel();

            model.ShowSearch    = showSearch;
            model.ShowCreateSub = showCreateSub;
            model.ShowSubmit    = showSubmit;

            var currentUser = _userContext.CurrentUser;

            if (subId.HasValue)
            {
                model.CurrentSub = _subWrapper.Wrap(_subDao.GetSubById(subId.Value), _userContext.CurrentUser);
            }
            else if (!string.IsNullOrEmpty(subName))
            {
                model.CurrentSub = _subWrapper.Wrap(_subDao.GetSubByName(subName), _userContext.CurrentUser);
            }

            if (model.CurrentSub != null)
            {
                if (_userContext.CurrentUser != null)
                {
                    model.Permissions = _moderationDao.GetUserPermissionsForSub(_userContext.CurrentUser, model.CurrentSub.Sub.Id);
                }

                if (!model.IsModerator)
                {
                    // we only show list of mods if the requesting user is not a mod of this sub
                    model.Moderators = _membershipDao.GetUsersByIds(_moderationDao.GetAllModsForSub(model.CurrentSub.Sub.Id).Select(x => x.UserId).ToList());
                }

                // get the number of active users currently viewing this sub.
                // for normal users, this number may be fuzzed (if low enough) for privacy reasons.
                if (_userContext.CurrentUser != null && _userContext.CurrentUser.IsAdmin)
                {
                    model.NumberOfActiveUsers = _subActivityDao.GetActiveNumberOfUsersForSub(model.CurrentSub.Sub.Id);
                }
                else
                {
                    bool wasFuzzed;
                    model.NumberOfActiveUsers         = _subActivityDao.GetActiveNumberOfUsersForSubFuzzed(model.CurrentSub.Sub.Id, out wasFuzzed);
                    model.IsNumberOfActiveUsersFuzzed = wasFuzzed;
                }
            }

            if (model.ShowCreateSub)
            {
                if (currentUser != null)
                {
                    var age = Common.CurrentTime() - currentUser.CreatedDate;
                    if (currentUser.IsAdmin || age.TotalDays >= _subSettings.Settings.MinUserAgeCreateSub)
                    {
                        model.CanCreateSub = true;
                    }
                }
            }

            return(View(model));
        }