public async Task Test_LogActivityCommand_Serialization() { var user = TestHelper.SetPrincipal(USERNAMES.Unit); var cmd = new LogVisitCommand("_all", 799, "111.111.111.111").SetUserContext(user); var deserialized = EnsureCommandIsSerialziable(cmd); //Won't pass Assert.AreEqual(cmd.Subverse, deserialized.Subverse); Assert.AreEqual(cmd.SubmissionID, deserialized.SubmissionID); Assert.AreEqual(cmd.ClientIPAddress, deserialized.ClientIPAddress); }
//// POST: votecomment/{commentId}/{typeOfVote} //[HttpPost] //[Authorize] //[VoatValidateAntiForgeryToken] //public async Task<JsonResult> VoteComment(int commentId, int typeOfVote) //{ // var cmd = new CommentVoteCommand(commentId, typeOfVote, IpHash.CreateHash(UserHelper.UserIpAddress(this.Request))); // var result = await cmd.Execute(); // return Json(result); //} // GET: Renders Primary Submission Comments Page public async Task <ActionResult> Comments(int?submissionID, string subverseName, int?commentID, string sort, int?context) { #region Validation if (submissionID == null) { return(ErrorView(new ErrorViewModel() { Description = "Can not find what was requested because input is not valid" })); } var q = new QuerySubmission(submissionID.Value, true).SetUserContext(User); var submission = await q.ExecuteAsync().ConfigureAwait(false); if (submission == null) { return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound))); } // make sure that the combination of selected subverse and submission subverse are linked if (!submission.Subverse.IsEqual(subverseName)) { return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound))); } var subverse = DataCache.Subverse.Retrieve(subverseName); 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 if (commentID != null) { ViewBag.StartingCommentId = commentID; ViewBag.CommentToHighLight = commentID; } #region Set ViewBag ViewBag.Subverse = subverse; ViewBag.Submission = submission; //This is a required view bag property in _Layout.cshtml - Update: hmmm, don't think so but too lazy to look ViewBag.SelectedSubverse = subverse.Name; var sortingMode = GetSortMode(sort); ViewBag.SortingMode = sortingMode; #endregion var cmd = new LogVisitCommand(null, submissionID.Value, Request.RemoteAddress()).SetUserContext(User); cmd.Execute(); CommentSegment model = null; if (commentID != null) { ViewBag.CommentToHighLight = commentID.Value; model = await GetCommentContext(submission.ID, commentID.Value, context, sortingMode); } else { model = await GetCommentSegment(submission.ID, null, 0, sortingMode); } var q2 = new QuerySubverseModerators(subverseName).SetUserContext(User); ViewBag.ModeratorList = await q2.ExecuteAsync(); ViewBag.NavigationViewModel = new NavigationViewModel() { Description = "Subverse", Name = subverseName, MenuType = MenuType.Subverse, BasePath = VoatUrlFormatter.BasePath(new DomainReference(DomainType.Subverse, subverseName)), Sort = null }; return(View("~/Views/Home/Comments.cshtml", model)); }
// GET: show a subverse index public async Task <ActionResult> SubverseIndex(string subverse, string sort = "hot", bool?previewMode = null) { const string cookieName = "NSFWEnabled"; var viewProperties = new ListViewModel <Domain.Models.Submission>(); viewProperties.PreviewMode = previewMode ?? false; ViewBag.PreviewMode = viewProperties.PreviewMode; //Set to DEFAULT if querystring is present if (Request.Query["frontpage"] == "guest") { subverse = AGGREGATE_SUBVERSE.DEFAULT; } if (String.IsNullOrEmpty(subverse)) { subverse = AGGREGATE_SUBVERSE.FRONT; } SetFirstTimeCookie(); var logVisit = new LogVisitCommand(subverse, null, IpHash.CreateHash(Request.RemoteAddress())).SetUserContext(User); await logVisit.Execute(); //Parse query var options = new SearchOptions(Request.QueryString.Value); //Set sort because it is part of path if (!String.IsNullOrEmpty(sort)) { options.Sort = (Domain.Models.SortAlgorithm)Enum.Parse(typeof(Domain.Models.SortAlgorithm), sort, true); } //set span to day if not specified explicitly if (options.Sort == Domain.Models.SortAlgorithm.Top && !Request.Query.ContainsKey("span")) { options.Span = Domain.Models.SortSpan.Day; } //reset count incase they try to change it with querystrings those sneaky snakes options.Count = 25; viewProperties.Sort = options.Sort; viewProperties.Span = options.Span; var routeName = ROUTE_NAMES.SUBVERSE_INDEX; try { PaginatedList <Domain.Models.Submission> pageList = null; if (AGGREGATE_SUBVERSE.IsAggregate(subverse)) { if (AGGREGATE_SUBVERSE.FRONT.IsEqual(subverse)) { //Check if user is logged in and has subscriptions, if not we convert to default query if (!User.Identity.IsAuthenticated || (User.Identity.IsAuthenticated && !UserData.HasSubscriptions())) { subverse = AGGREGATE_SUBVERSE.DEFAULT; } else { subverse = AGGREGATE_SUBVERSE.FRONT; } //viewProperties.Title = "Front"; //ViewBag.SelectedSubverse = "frontpage"; } else if (AGGREGATE_SUBVERSE.DEFAULT.IsEqual(subverse)) { //viewProperties.Title = "Front"; //ViewBag.SelectedSubverse = "frontpage"; } else { // selected subverse is ALL, show submissions from all subverses, sorted by rank viewProperties.Title = "all subverses"; if (AGGREGATE_SUBVERSE.ANY.IsEqual(subverse)) { viewProperties.Context = new Domain.Models.DomainReference(Domain.Models.DomainType.Subverse, AGGREGATE_SUBVERSE.ANY); subverse = AGGREGATE_SUBVERSE.ANY; } else { viewProperties.Context = new Domain.Models.DomainReference(Domain.Models.DomainType.Subverse, "all"); subverse = AGGREGATE_SUBVERSE.ALL; } } } else { // check if subverse exists, if not, send to a page not found error //Can't use cached, view using to query db var subverseObject = _db.Subverse.FirstOrDefault(x => x.Name.ToLower() == subverse.ToLower()); if (subverseObject == null) { ViewBag.SelectedSubverse = "404"; return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound))); } //Set to proper cased name subverse = subverseObject.Name; //HACK: Disable subverse if (subverseObject.IsAdminDisabled.HasValue && subverseObject.IsAdminDisabled.Value) { //viewProperties.Subverse = subverseObject.Name; ViewBag.Subverse = subverseObject.Name; return(ErrorView(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseDisabled))); } //Check NSFW Settings if (subverseObject.IsAdult) { if (User.Identity.IsAuthenticated) { if (!UserData.Preferences.EnableAdultContent) { // display a view explaining that account preference is set to NO NSFW and why this subverse can not be shown return(RedirectToAction("AdultContentFiltered", "Subverses", new { destination = subverseObject.Name })); } } // check if user wants to see NSFW content by reading NSFW cookie else if (!ControllerContext.HttpContext.Request.Cookies.ContainsKey(cookieName)) { return(RedirectToAction("AdultContentWarning", "Subverses", new { destination = subverseObject.Name, nsfwok = false })); } } viewProperties.Context = new Domain.Models.DomainReference(Domain.Models.DomainType.Subverse, subverseObject.Name); viewProperties.Title = subverseObject.Title; routeName = ROUTE_NAMES.SUBVERSE_INDEX; } //what to query var domainReference = new Domain.Models.DomainReference(Domain.Models.DomainType.Subverse, subverse); var q = new QuerySubmissions(domainReference, options).SetUserContext(User); var results = await q.ExecuteAsync().ConfigureAwait(false); viewProperties.Context = domainReference; pageList = new PaginatedList <Domain.Models.Submission>(results, options.Page, options.Count, -1); pageList.RouteName = routeName; viewProperties.Items = pageList; var navModel = new NavigationViewModel() { Description = "Subverse", Name = subverse, MenuType = MenuType.Subverse, BasePath = "/v/" + subverse, Sort = null }; //Backwards compat with Views if (subverse == AGGREGATE_SUBVERSE.FRONT || subverse == AGGREGATE_SUBVERSE.DEFAULT) { navModel.BasePath = ""; navModel.Name = ""; //ViewBag.SelectedSubverse = "frontpage"; viewProperties.Context.Name = ""; pageList.RouteName = Models.ROUTE_NAMES.FRONT_INDEX; } else if (subverse == AGGREGATE_SUBVERSE.ALL || subverse == AGGREGATE_SUBVERSE.ANY) { navModel.BasePath = "/v/all"; navModel.Name = "All"; ViewBag.SelectedSubverse = "all"; viewProperties.Context.Name = "all"; } else { ViewBag.SelectedSubverse = subverse; } ViewBag.SortingMode = sort; ViewBag.NavigationViewModel = navModel; var viewPath = ViewPath(domainReference); return(View(viewPath, viewProperties)); } catch (Exception ex) { throw ex; } }