public ActionResult Type(ErrorType type)
        {
            var viewName   = "Index";
            var errorModel = ErrorViewModel.GetErrorViewModel(type);

            return(View(viewName, errorModel));
        }
Esempio n. 2
0
        public async Task <ActionResult> Banned(string subverse)
        {
            ViewBag.SelectedSubverse = subverse;

            var subverseObject = DataCache.Subverse.Retrieve(subverse);

            if (subverseObject != null)
            {
                //HACK: Disable subverse
                if (subverseObject.IsAdminDisabled.HasValue && subverseObject.IsAdminDisabled.Value)
                {
                    ViewBag.Subverse = subverseObject.Name;
                    return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseDisabled)));
                }
            }

            var options = new SearchOptions(Request.QueryString.Value);
            var q       = new QueryModLogBannedUsers(subverse, options);
            var results = await q.ExecuteAsync();

            //CORE_PORT: This is bad mmkay
            ViewBag.TotalBannedUsersInSubverse = results.Item1;
            //using (var db = new voatEntities(CONSTANTS.CONNECTION_READONLY))
            //{
            //    ViewBag.TotalBannedUsersInSubverse = db.SubverseBans.Where(rl => rl.Subverse.Equals(subverse, StringComparison.OrdinalIgnoreCase)).Count();
            //}

            var list = new PaginatedList <Domain.Models.SubverseBan>(results.Item2, options.Page, options.Count);

            return(View(list));
        }
Esempio n. 3
0
        public async Task <ActionResult> Comments(string subverse)
        {
            ViewBag.SelectedSubverse = subverse;

            var subverseObject = DataCache.Subverse.Retrieve(subverse);

            if (subverseObject != null)
            {
                ViewBag.SubverseAnonymized = subverseObject.IsAnonymized;

                //HACK: Disable subverse
                if (subverseObject.IsAdminDisabled.HasValue && subverseObject.IsAdminDisabled.Value)
                {
                    ViewBag.Subverse = subverseObject.Name;
                    return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseDisabled)));
                }
            }

            var options = new SearchOptions(Request.QueryString.Value);
            var q       = new QueryModLogRemovedComments(subverse, options);
            var results = await q.ExecuteAsync();

            var list = new PaginatedList <Domain.Models.CommentRemovalLog>(results, options.Page, options.Count);

            return(View(list));
        }
        public async Task <ActionResult> RemoveLinkFlair(int id)
        {
            // get link flair for selected subverse
            var linkFlairToRemove = await _db.SubverseFlair.FindAsync(id);

            if (linkFlairToRemove == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var subverse = DataCache.Subverse.Retrieve(linkFlairToRemove.Subverse);

            if (subverse == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            // check if caller has clearance to remove a link flair
            if (!ModeratorPermission.HasPermission(User, subverse.Name, Domain.Models.ModeratorAction.ModifyFlair))
            {
                return(RedirectToAction("Index", "Home"));
            }

            // execute removal
            var subverseFlairSetting = await _db.SubverseFlair.FindAsync(id);

            _db.SubverseFlair.Remove(subverseFlairSetting);
            await _db.SaveChangesAsync();

            //clear cache
            CacheHandler.Instance.Remove(CachingKey.SubverseFlair(subverse.Name));

            return(RedirectToAction("SubverseFlairSettings"));
        }
        public ActionResult SubverseFlairSettings(string subverse)
        {
            // get model for selected subverse
            var subverseObject = DataCache.Subverse.Retrieve(subverse);

            if (subverseObject == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            // check if caller is authorized for this sub, if not, deny listing
            if (!ModeratorPermission.HasPermission(User, subverse, Domain.Models.ModeratorAction.ModifyFlair))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var subverseFlairsettings = _db.SubverseFlair
                                        .Where(n => n.Subverse == subverse)
                                        .Take(20)
                                        .OrderBy(s => s.ID)
                                        .ToList();

            ViewBag.SubverseModel    = subverseObject;
            ViewBag.SubverseName     = subverse;
            ViewBag.SelectedSubverse = string.Empty;
            SetNavigationViewModel(subverseObject.Name);

            return(View("~/Views/Subverses/Admin/Flair/FlairSettings.cshtml", subverseFlairsettings));
        }
        public ActionResult RecallModeratorInvitation(int?invitationId)
        {
            if (invitationId == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var moderatorInvitation = _db.ModeratorInvitation.Find(invitationId);

            if (moderatorInvitation == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            if (!ModeratorPermission.HasPermission(User, moderatorInvitation.Subverse, Domain.Models.ModeratorAction.InviteMods))
            {
                return(RedirectToAction("SubverseModerators"));
            }
            //make sure mods can't remove invites
            var currentModLevel = ModeratorPermission.Level(User, moderatorInvitation.Subverse);

            if (moderatorInvitation.Power <= (int)currentModLevel && currentModLevel != Domain.Models.ModeratorLevel.Owner)
            {
                return(RedirectToAction("SubverseModerators"));
            }

            ViewBag.SubverseName = moderatorInvitation.Subverse;
            SetNavigationViewModel(moderatorInvitation.Subverse);

            return(View("~/Views/Subverses/Admin/RecallModeratorInvitation.cshtml", moderatorInvitation));
        }
        public ActionResult SubverseStylesheetEditor(string subverse)
        {
            var subverseObject = DataCache.Subverse.Retrieve(subverse);

            if (subverseObject == null)
            {
                ViewBag.SelectedSubverse = "404";
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
            }
            if (!ModeratorPermission.HasPermission(User, subverse, Domain.Models.ModeratorAction.ModifyCSS))
            {
                return(RedirectToAction("Index", "Home"));
            }

            // map existing data to view model for editing and pass it to frontend
            var viewModel = new SubverseStylesheetViewModel
            {
                Name       = subverseObject.Name,
                Stylesheet = subverseObject.Stylesheet
            };

            ViewBag.SelectedSubverse = string.Empty;
            ViewBag.SubverseName     = subverseObject.Name;
            SetNavigationViewModel(subverseObject.Name);

            return(View("~/Views/Subverses/Admin/SubverseStylesheetEditor.cshtml", viewModel));
        }
        public async Task <ActionResult> SubverseLinkFlairs(string subverse, int?id)
        {
            // get model for selected subverse
            var subverseObject = DataCache.Subverse.Retrieve(subverse);

            if (subverseObject == null || id == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
            }

            var submission = DataCache.Submission.Retrieve(id);

            if (submission == null || submission.Subverse != subverse)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            // check if caller is subverse owner or moderator, if not, deny listing
            if (!ModeratorPermission.HasPermission(User, subverse, Domain.Models.ModeratorAction.AssignFlair))
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.Unauthorized)));
            }

            var q      = new QuerySubverseFlair(subverseObject.Name);
            var flairs = await q.ExecuteAsync();

            ViewBag.SubmissionId = id;
            ViewBag.SubverseName = subverse;

            return(PartialView("~/Views/AjaxViews/_LinkFlairSelectDialog.cshtml", flairs));
        }
        public ActionResult ClearLinkFlair(int?submissionID)
        {
            if (submissionID == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            // get model for selected submission
            var submissionModel = _db.Submission.Find(submissionID);

            if (submissionModel == null || submissionModel.IsDeleted)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            // check if caller is subverse moderator, if not, deny posting
            if (!ModeratorPermission.HasPermission(User, submissionModel.Subverse, Domain.Models.ModeratorAction.AssignFlair))
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.Unauthorized)));
            }

            // clear flair and save submission
            submissionModel.FlairCss   = null;
            submissionModel.FlairLabel = null;
            _db.SaveChanges();
            DataCache.Submission.Remove(submissionID.Value);

            return(JsonResult(CommandResponse.FromStatus(Status.Success)));
            //return new HttpStatusCodeResult(HttpStatusCode.OK);
        }
        public ActionResult SubverseBans(string subverse, int?page)
        {
            const int pageSize   = 25;
            int       pageNumber = (page ?? 0);

            if (pageNumber < 0)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            // get model for selected subverse
            var subverseObject = DataCache.Subverse.Retrieve(subverse);

            if (subverseObject == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            if (!ModeratorPermission.HasPermission(User, subverse, Domain.Models.ModeratorAction.Banning))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var subverseBans          = _db.SubverseBan.Where(n => n.Subverse == subverse).OrderByDescending(s => s.CreationDate);
            var paginatedSubverseBans = new PaginatedList <SubverseBan>(subverseBans, page ?? 0, pageSize);

            ViewBag.SubverseModel    = subverseObject;
            ViewBag.SubverseName     = subverse;
            ViewBag.SelectedSubverse = string.Empty;
            SetNavigationViewModel(subverseObject.Name);

            return(View("~/Views/Subverses/Admin/SubverseBans.cshtml", paginatedSubverseBans));
        }
        public async Task <ActionResult> ModeratorDelete(string subverse, int submissionID)
        {
            if (!ModeratorPermission.HasPermission(User, subverse, Domain.Models.ModeratorAction.DeletePosts))
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.Unauthorized)));
            }

            //New Domain Submission
            //var q = new QuerySubmission(submissionID);
            //var s = await q.ExecuteAsync();

            //Legacy Data Submission (Since views expect this type, we use it for now)
            var s = DataCache.Submission.Retrieve(submissionID);

            ViewBag.Submission = s;

            if (s == null)
            {
                ModelState.AddModelError("", "Can not find submission. Is it hiding?");
                return(View(new ModeratorDeleteContentViewModel()));
            }
            if (s.IsDeleted)
            {
                ModelState.AddModelError("", "Can not delete a deleted post. Do you have no standards?");
            }

            return(View(new ModeratorDeleteContentViewModel()
            {
                ID = s.ID
            }));
        }
        public ActionResult RemoveBan(string subverse, int?id)
        {
            if (id == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            // check if caller is subverse owner, if not, deny listing
            if (!ModeratorPermission.HasPermission(User, subverse, Domain.Models.ModeratorAction.Banning))
            {
                return(RedirectToAction("Index", "Home"));
            }
            var subverseBan = _db.SubverseBan.Find(id);

            if (subverseBan == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }

            ViewBag.SelectedSubverse = string.Empty;
            ViewBag.SubverseName     = subverseBan.Subverse;
            SetNavigationViewModel(subverseBan.Subverse);

            return(View("~/Views/Subverses/Admin/RemoveBan.cshtml", subverseBan));
        }
        public async Task <ActionResult> RemoveBan(int id)
        {
            // get ban name for selected subverse
            var banToBeRemoved = await _db.SubverseBan.FindAsync(id);

            if (banToBeRemoved == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            else
            {
                var cmd      = new SubverseBanCommand(banToBeRemoved.UserName, banToBeRemoved.Subverse, null, false).SetUserContext(User);
                var response = await cmd.Execute();

                if (response.Success)
                {
                    return(RedirectToAction("SubverseBans"));
                }
                else
                {
                    ModelState.AddModelError(String.Empty, response.Message);
                    ViewBag.SelectedSubverse = string.Empty;
                    ViewBag.SubverseName     = banToBeRemoved.Subverse;
                    SetNavigationViewModel(banToBeRemoved.Subverse);

                    return(View("~/Views/Subverses/Admin/RemoveBan.cshtml", banToBeRemoved));
                }
            }
        }
Esempio n. 14
0
        public async Task <ActionResult> ModeratorDelete(string subverse, int submissionID, int commentID)
        {
            if (!ModeratorPermission.HasPermission(User, subverse, Domain.Models.ModeratorAction.DeleteComments))
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.Unauthorized)));
            }
            var q       = new QueryComment(commentID);
            var comment = await q.ExecuteAsync();

            if (comment == null || comment.SubmissionID != submissionID)
            {
                ModelState.AddModelError("", "Can not find comment. Who did this?");
                return(View(new ModeratorDeleteContentViewModel()));
            }
            if (!comment.Subverse.IsEqual(subverse))
            {
                ModelState.AddModelError("", "Data mismatch detected");
                return(View(new ModeratorDeleteContentViewModel()));
            }

            ViewBag.Comment = comment;
            return(View(new ModeratorDeleteContentViewModel()
            {
                ID = commentID
            }));
        }
        public ActionResult RemoveModerator(int?id)
        {
            if (id == null)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var subModerator = _db.SubverseModerator.Find(id);

            if (subModerator == null)
            {
                return(RedirectToAction("NotFound", "Error"));
            }

            if (!ModeratorPermission.HasPermission(User, subModerator.Subverse, Domain.Models.ModeratorAction.RemoveMods))
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.SelectedSubverse = string.Empty;
            ViewBag.SubverseName     = subModerator.Subverse;
            SetNavigationViewModel(subModerator.Subverse);

            return(View("~/Views/Subverses/Admin/RemoveModerator.cshtml", subModerator));
        }
        public async Task <ActionResult> ResignAsModeratorPost(string subverse)
        {
            // get moderator name for selected subverse
            var subModerator = _db.SubverseModerator.FirstOrDefault(s => s.Subverse == subverse && s.UserName == User.Identity.Name);

            if (subModerator == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var subverseObject = DataCache.Subverse.Retrieve(subModerator.Subverse);

            if (subverseObject == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            // execute removal
            _db.SubverseModerator.Remove(subModerator);
            await _db.SaveChangesAsync();

            //clear mod cache
            CacheHandler.Instance.Remove(CachingKey.SubverseModerators(subverseObject.Name));

            return(RedirectToRoute(Models.ROUTE_NAMES.SUBVERSE_INDEX, new { subverse = subverse }));
        }
Esempio n. 17
0
        //TODO: Rewrite this
        public ActionResult Saved(string userName, int?page = null)
        {
            if (page.HasValue && page.Value < 0)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            var originalUserName = UserHelper.OriginalUsername(userName);

            if (String.IsNullOrEmpty(originalUserName))
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }
            if (!User.Identity.IsAuthenticated || (User.Identity.IsAuthenticated && !User.Identity.Name.IsEqual(originalUserName)))
            {
                return(RedirectToAction("Overview"));
            }
            ViewBag.UserName = originalUserName;



            IQueryable <SavedItem> savedSubmissions = (from m in _db.Submission
                                                       join s in _db.SubmissionSaveTracker on m.ID equals s.SubmissionID
                                                       where !m.IsDeleted && s.UserName == User.Identity.Name
                                                       select new SavedItem()
            {
                SaveDateTime = s.CreationDate,
                SavedSubmission = m,
                SavedComment = null,
                Subverse = m.Subverse
            });

            IQueryable <SavedItem> savedComments = (from c in _db.Comment
                                                    join sub in _db.Submission on c.SubmissionID equals sub.ID
                                                    join s in _db.CommentSaveTracker on c.ID equals s.CommentID
                                                    where !c.IsDeleted && s.UserName == User.Identity.Name
                                                    select new SavedItem()
            {
                SaveDateTime = s.CreationDate,
                SavedSubmission = null,
                SavedComment = c,
                Subverse = sub.Subverse
            });

            // merge submissions and comments into one list sorted by date
            var mergedSubmissionsAndComments = savedSubmissions.Concat(savedComments).OrderByDescending(s => s.SaveDateTime).AsQueryable();

            var paginatedUserSubmissionsAndComments = new PaginatedList <SavedItem>(mergedSubmissionsAndComments, page ?? 0, PAGE_SIZE);

            ViewBag.NavigationViewModel = new NavigationViewModel()
            {
                MenuType    = MenuType.UserProfile,
                Name        = originalUserName,
                BasePath    = "/user/" + originalUserName,
                Description = originalUserName + "'s Saved",
            };

            return(View(paginatedUserSubmissionsAndComments));
        }
Esempio n. 18
0
        public async Task <ActionResult> Save([FromBody] CreateVote model)
        {
            //This needs fixed
            if (!VotesEnabled)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.Unauthorized)));
            }

            try
            {
                ModelState.Clear();

                //Map to Domain Model
                var domainModel = model.Map();

                ////Reinsert Cache
                //cache.Replace($"VoteCreate:{User.Identity.Name}", domainModel);


                var valResult = Voat.Validation.ValidationHandler.Validate(domainModel);
                if (valResult != null)
                {
                    valResult.ForEach(x => ModelState.AddModelError(x.MemberNames.FirstOrDefault(), x.ErrorMessage));
                }
                CommandResponse <SaveVoteResponse> response = new CommandResponse <SaveVoteResponse>(new SaveVoteResponse(), Status.Success, "");

                if (ModelState.IsValid)
                {
                    //Save Vote
                    var cmd    = new PersistVoteCommand(domainModel).SetUserContext(User);
                    var result = await cmd.Execute();

                    if (result.Success)
                    {
                        response.Response.ID   = result.Response.ID;
                        response.Response.Html = await _viewRenderService.RenderToStringAsync("_View", await VoteAggregate.Load(result.Response));

                        return(JsonResult(response));
                        //return PartialView("_View", result.Response);
                    }
                    else
                    {
                        ModelState.AddModelError("", result.Message);
                    }
                }

                response.Status        = Status.Error;
                response.Response.Html = await _viewRenderService.RenderToStringAsync("_Edit", domainModel, ModelState);

                return(JsonResult(response));
                //return PartialView("_Edit", domainModel);
            }
            catch (Exception ex)
            {
                var x = ex;
                throw ex;
            }
        }
 public ActionResult RenderSubmission(MarkdownPreviewModel submissionModel)
 {
     if (submissionModel != null)
     {
         submissionModel.MessageContent = Formatting.FormatMessage(submissionModel.MessageContent, true);
         return(PartialView("~/Views/AjaxViews/_MessageContent.cshtml", submissionModel));
     }
     return(HybridError(ErrorViewModel.GetErrorViewModel(HttpStatusCode.BadRequest)));
     //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
 }
        public static ViewResult ErrorView(ErrorType type, ErrorViewModel model = null)
        {
            var viewData = new ViewDataDictionary <ErrorViewModel>(new EmptyModelMetadataProvider(), new ModelStateDictionary());

            viewData.Model = model == null?ErrorViewModel.GetErrorViewModel(type) : model;

            return(new ViewResult()
            {
                ViewName = "~/Views/Error/Index.cshtml",
                ViewData = viewData
            });
        }
Esempio n. 21
0
        //CORE_PORT: No direct access
        //private readonly voatEntities _db = new VoatUIDataContextAccessor();

        // GET: CommentReplyForm
        public ActionResult CommentReplyForm(int?parentCommentId, int?messageId)
        {
            if (parentCommentId == null || messageId == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            ViewBag.MessageId       = messageId;
            ViewBag.ParentCommentId = parentCommentId;

            return(PartialView("~/Views/AjaxViews/_CommentReplyForm.cshtml"));
        }
Esempio n. 22
0
        // GET: PrivateMessageReplyForm
        public ActionResult PrivateMessageReplyForm(int?parentPrivateMessageId, string recipient, string subject)
        {
            if (parentPrivateMessageId == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            ViewBag.ParentPrivateMessageId = parentPrivateMessageId;
            ViewBag.Recipient = recipient;
            ViewBag.Subject   = subject;

            return(PartialView("~/Views/AjaxViews/_PrivateMessageReplyForm.cshtml"));
        }
Esempio n. 23
0
        // url: "/comments/" + submission + "/" + parentId + "/" + command + "/" + startingIndex + "/" + count + "/" + nestingLevel + "/" + sort + "/",
        // GET: Renders a Section of Comments within the already existing tree
        //Leaving (string command) in for backwards compat with mobile html clients. this is no longer used
        public async Task <ActionResult> CommentSegment(int submissionID, int?parentID, string command, int startingIndex, string sort)
        {
            #region Validation

            if (submissionID <= 0)
            {
                return(ErrorView(new ErrorViewModel()
                {
                    Description = "Can not find what was requested because input is not valid"
                }));
            }

            var q          = new QuerySubmission(submissionID, false);
            var submission = await q.ExecuteAsync().ConfigureAwait(false);

            if (submission == null)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            var subverse = DataCache.Subverse.Retrieve(submission.Subverse);

            if (subverse == null)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            if (subverse.IsAdminDisabled.HasValue && subverse.IsAdminDisabled.Value)
            {
                ViewBag.Subverse = subverse.Name;
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseDisabled)));
            }

            #endregion

            #region Set ViewBag
            ViewBag.Subverse   = subverse;
            ViewBag.Submission = submission;

            var sortingMode = GetSortMode(sort);
            ViewBag.SortingMode = sortingMode;

            #endregion

            var q2 = new QuerySubverseModerators(subverse.Name);
            ViewBag.ModeratorList = await q2.ExecuteAsync();

            var results = await GetCommentSegment(submissionID, parentID, startingIndex, sortingMode);

            return(PartialView("~/Views/Shared/Comments/_CommentSegment.cshtml", results));
        }
        public async Task <ActionResult> SubverseIndex(string subverse, MessageTypeFlag type, MessageState?state = null, int?page = null)
        {
            if (!(type == MessageTypeFlag.Private || type == MessageTypeFlag.Sent))
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (string.IsNullOrEmpty(subverse))
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (!ModeratorPermission.HasPermission(User, subverse, ModeratorAction.ReadMail))
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.Context = new MessageContextViewModel()
            {
                ViewerContext = new UserDefinition()
                {
                    Name = subverse, Type = IdentityType.Subverse
                }
            };

            var qSub = new QuerySubverse(subverse);
            var sub  = await qSub.ExecuteAsync();

            if (sub == null)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
            }
            //ViewBag.PmView = "mod";
            //ViewBag.Title = string.Format("v/{0} {1}", sub.Name, (type == MessageTypeFlag.Sent ? "Sent" : "Inbox"));

            var q = new QueryMessages(sub.Name, IdentityType.Subverse, type, MessageState.All, false).SetUserContext(User);

            q.PageNumber = SetPage(page);
            var result = await q.ExecuteAsync();

            var pagedList = new PaginatedList <Message>(result, q.PageNumber, q.PageCount);

            //TODO: This needs to be the Smail Menu, right now it shows user menu
            var name = type == MessageTypeFlag.Sent ? "Sent" : "Inbox";

            ViewBag.Title = name;
            SetMenuNavigationModel(name, MenuType.Smail, subverse);

            return(View("Index", pagedList));
        }
Esempio n. 25
0
        public async Task <ActionResult> Comments(string userName, int?page = null)
        {
            if (page.HasValue && page.Value < 0)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            var originalUserName = UserHelper.OriginalUsername(userName);

            if (String.IsNullOrEmpty(originalUserName))
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }
            ViewBag.UserName = originalUserName;

            //if user is accesing their own comments, increase max page size to 100, else use default
            int?maxPages = (originalUserName == User.Identity.Name ? 100 : (int?)null);

            var q = new QueryUserComments(userName,
                                          new Data.SearchOptions(maxPages)
            {
                Page = page ?? 0,
                Sort = Domain.Models.SortAlgorithm.New,
            });

            var comments = await q.ExecuteAsync();

            //var userComments = from c in _db.Comments.OrderByDescending(c => c.CreationDate)
            //                    where c.UserName.Equals(originalUserName)
            //                    && !c.IsAnonymized
            //                    && !c.IsDeleted
            //                    //&& !c.Submission.Subverse1.IsAnonymized //Don't think we need this condition
            //                    select c;

            var paged = new PaginatedList <Domain.Models.SubmissionComment>(comments, page ?? 0, PAGE_SIZE, -1);

            ViewBag.NavigationViewModel = new NavigationViewModel()
            {
                MenuType    = MenuType.UserProfile,
                Name        = originalUserName,
                BasePath    = "/user/" + originalUserName,
                Description = originalUserName + "'s Comments",
            };

            ViewBag.RobotIndexing = Domain.Models.RobotIndexing.None;
            return(View(paged));
        }
Esempio n. 26
0
        // GET: Renders a New Comment Tree
        public async Task <ActionResult> CommentTree(int submissionID, string sort)
        {
            #region Validation

            if (submissionID <= 0)
            {
                return(ErrorView(new ErrorViewModel()
                {
                    Description = "Can not find what was requested because input is not valid"
                }));
            }

            var submission = DataCache.Submission.Retrieve(submissionID);

            if (submission == null)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            var subverse = DataCache.Subverse.Retrieve(submission.Subverse);

            if (subverse == null)
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }

            if (subverse.IsAdminDisabled.HasValue && subverse.IsAdminDisabled.Value)
            {
                ViewBag.Subverse = subverse.Name;
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseDisabled)));
            }

            #endregion

            #region Set ViewBag
            ViewBag.Subverse   = subverse;
            ViewBag.Submission = submission;

            var sortingMode = GetSortMode(sort);
            ViewBag.SortingMode = sortingMode;

            #endregion

            var results = await GetCommentSegment(submissionID, null, 0, sortingMode);

            return(PartialView("~/Views/Shared/Comments/_CommentTree.cshtml", results));
        }
        public ActionResult AddLinkFlair(SubverseFlairInput subverseFlairSetting)
        {
            if (!ModelState.IsValid)
            {
                return(View("~/Views/Subverses/Admin/Flair/AddLinkFlair.cshtml", subverseFlairSetting));
            }

            //check perms
            if (!ModeratorPermission.HasPermission(User, subverseFlairSetting.Subverse, Domain.Models.ModeratorAction.ModifyFlair))
            {
                return(RedirectToAction("Index", "Home"));
            }

            // get model for selected subverse
            var subverse = DataCache.Subverse.Retrieve(subverseFlairSetting.Subverse);

            if (subverse == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
            }
            var count = _db.SubverseFlair.Count(x => x.Subverse == subverseFlairSetting.Subverse);

            if (count >= 20)
            {
                ViewBag.SubverseModel    = subverse;
                ViewBag.SubverseName     = subverse.Name;
                ViewBag.SelectedSubverse = string.Empty;
                SetNavigationViewModel(subverse.Name);
                ModelState.AddModelError("", "Subverses are limited to 20 flairs");
                return(View("~/Views/Subverses/Admin/Flair/AddLinkFlair.cshtml", subverseFlairSetting));
            }

            subverseFlairSetting.Subverse = subverse.Name;
            _db.SubverseFlair.Add(new SubverseFlair()
            {
                Label    = subverseFlairSetting.Label,
                CssClass = subverseFlairSetting.CssClass,
                Subverse = subverseFlairSetting.Subverse
            });
            _db.SaveChanges();

            //clear cache
            CacheHandler.Instance.Remove(CachingKey.SubverseFlair(subverse.Name));

            return(RedirectToAction("SubverseFlairSettings"));
        }
Esempio n. 28
0
        public ActionResult Overview(string userName)
        {
            var originalUserName = UserHelper.OriginalUsername(userName);

            if (String.IsNullOrEmpty(originalUserName))
            {
                return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
            }
            ViewBag.UserName            = originalUserName;
            ViewBag.NavigationViewModel = new NavigationViewModel()
            {
                MenuType    = MenuType.UserProfile,
                Name        = originalUserName,
                BasePath    = "/user/" + originalUserName,
                Description = originalUserName + "'s Overview",
            };
            return(View());
        }
        public async Task <ActionResult> ModeratorDelete(string subverse, int submissionID, ModeratorDeleteContentViewModel model)
        {
            //New Domain Submission
            //var q = new QuerySubmission(submissionID);
            //var s = await q.ExecuteAsync();

            //Legacy Data Submission (Since views expect this type, we use it for now)
            var s = DataCache.Submission.Retrieve(submissionID);

            ViewBag.Submission = s;
            if (s == null || s.ID != model.ID)
            {
                ModelState.AddModelError("", "Can not find submission. Is it hiding?");
                return(View(model));
            }
            if (s.IsDeleted)
            {
                ModelState.AddModelError("", "Can not delete a deleted post. Do you have no standards?");
                return(View(model));
            }

            if (!ModeratorPermission.HasPermission(User, s.Subverse, Domain.Models.ModeratorAction.DeletePosts))
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.Unauthorized)));
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var cmd = new DeleteSubmissionCommand(model.ID, model.Reason).SetUserContext(User);
            var r   = await cmd.Execute();

            if (r.Success)
            {
                return(RedirectToRoute(Models.ROUTE_NAMES.SUBVERSE_INDEX, new { subverse = s.Subverse }));
            }
            else
            {
                ModelState.AddModelError("", r.Message);
                return(View(model));
            }
        }
Esempio n. 30
0
        public async Task <ActionResult> Reports(string subverse, Domain.Models.ContentType?type = null, int days = 1, Domain.Models.ReviewStatus status = Domain.Models.ReviewStatus.Unreviewed, int[] ruleid = null)
        {
            days = days.EnsureRange(1, 7);

            if (subverse.IsEqual("all"))
            {
                subverse = null;
            }
            else
            {
                //check perms
                if (!ModeratorPermission.HasPermission(User, subverse, Domain.Models.ModeratorAction.AccessReports))
                {
                    return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.Unauthorized)));
                }
            }
            //TODO: Implement Command/Query - Remove direct Repository access
            using (var repo = new Repository(User))
            {
                var data = await repo.GetRuleReports(subverse, type, days * 24, status, ruleid);

                ViewBag.Days         = days;
                ViewBag.RuleID       = ruleid;
                ViewBag.ReviewStatus = status;

                //Add Mod Menu
                if (!subverse.IsEqual("all"))
                {
                    ViewBag.NavigationViewModel = new Models.ViewModels.NavigationViewModel()
                    {
                        Description = "Moderation",
                        Name        = subverse,
                        MenuType    = Models.ViewModels.MenuType.Moderator,
                        BasePath    = String.Format("/v/{0}/about", subverse),
                        Sort        = null
                    };
                }

                return(View(data));
            }
        }