// GET: MessageContent
        public async Task <ActionResult> MessageContent(int?messageId)
        {
            if (messageId.HasValue)
            {
                var q      = new QuerySubmission(messageId.Value);
                var result = await q.ExecuteAsync();

                if (result != null)
                {
                    var mpm = new MarkdownPreviewModel();

                    if (!String.IsNullOrEmpty(result.Content))
                    {
                        mpm.MessageContent = (String.IsNullOrEmpty(result.FormattedContent) ? Formatting.FormatMessage(result.Content) : result.FormattedContent);
                    }
                    else
                    {
                        mpm.MessageContent = "<p>This submission only has a title.</p>"; //"format" this content
                    }

                    return(PartialView("~/Views/AjaxViews/_MessageContent.cshtml", mpm));
                }
            }
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
Beispiel #2
0
        internal static async Task SendUserMentionNotification(Comment comment, IEnumerable <string> users)
        {
            if (comment != null)
            {
                foreach (var user in users)
                {
                    if (UserHelper.UserExists(user))
                    {
                        try
                        {
                            string recipient = UserHelper.OriginalUsername(user);

                            //BlockedUser Implementation - Comment User Mention
                            if (!MesssagingUtility.IsSenderBlocked(comment.UserName, recipient))
                            {
                                if (await UserAllowsAnonMentions(user, comment.IsAnonymized))
                                {
                                    //var submission = DataCache.Submission.Retrieve(comment.SubmissionID);

                                    var q          = new QuerySubmission(comment.SubmissionID.Value);
                                    var submission = await q.ExecuteAsync().ConfigureAwait(CONSTANTS.AWAIT_CAPTURE_CONTEXT);

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

                                    var message = new Domain.Models.Message();

                                    message.IsAnonymized  = comment.IsAnonymized;
                                    message.Recipient     = recipient;
                                    message.RecipientType = Domain.Models.IdentityType.User;
                                    message.Sender        = comment.UserName;
                                    message.SenderType    = Domain.Models.IdentityType.User;
                                    message.Subverse      = submission.Subverse;
                                    message.SubmissionID  = comment.SubmissionID;
                                    message.CommentID     = comment.ID;
                                    message.Type          = Domain.Models.MessageType.CommentMention;
                                    message.CreationDate  = Repository.CurrentDate;

                                    using (var repo = new Repository())
                                    {
                                        var response = await repo.SendMessage(message);

                                        if (response.Success)
                                        {
                                            EventNotification.Instance.SendMentionNotice(recipient, comment.UserName, Domain.Models.ContentType.Comment, comment.ID, comment.Content);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// </summary>
 /// <param name="submissionID">Using Nullable because everything seems to be nullable in this entire project</param>
 /// <returns></returns>
 public static Voat.Domain.Models.Submission Retrieve(int?submissionID)
 {
     if (submissionID.HasValue && submissionID.Value > 0)
     {
         string cacheKey   = CachingKey.Submission(submissionID.Value);
         var    q          = new QuerySubmission(submissionID.Value);
         var    submission = q.Execute();
         return(submission);
     }
     return(null);
 }
Beispiel #4
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));
        }
Beispiel #5
0
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            var q          = new QuerySubmission(context.SubmissionID.Value);
            var submission = q.Execute();

            // do not execute downvoting if comment is older than 7 days
            var      commentPostingDate = submission.CreationDate;
            TimeSpan timeElapsed        = Repository.CurrentDate - commentPostingDate;

            if (timeElapsed.TotalDays > 7)
            {
                return(CreateOutcome(RuleResult.Denied, "Submission downvotes not registered after 7 days"));
            }
            return(base.EvaluateRule(context));
        }
Beispiel #6
0
        public void DownvoteSubmission()
        {
            var submissionUser = "******";
            var newSubmission = TestHelper.ContentCreation.CreateSubmission(submissionUser, new Domain.Models.UserSubmission() { Title = "This is what I think about you guys", Subverse = SUBVERSES.Unit });

            var userName = USERNAMES.User500CCP;
            var user = TestHelper.SetPrincipal(userName);
            bool voteEventReceived = false;

            EventNotification.Instance.OnVoteReceived += (s, e) => {
                voteEventReceived = 
                    e.TargetUserName == submissionUser
                    && e.SendingUserName == userName
                    && e.ChangeValue == -1 
                    && e.ReferenceType == Domain.Models.ContentType.Submission 
                    && e.ReferenceID == newSubmission.ID;
            };
            var cmd = new SubmissionVoteCommand(newSubmission.ID, -1, IpHash.CreateHash("127.0.0.100")).SetUserContext(user);

            var c = cmd.Execute().Result;
            VoatAssert.IsValid(c);

            //verify in db
            using (var db = new Voat.Data.Repository(user))
            {
                var submissionFromRepo = db.GetSubmission(newSubmission.ID);
                Assert.IsNotNull(submissionFromRepo, "Couldn't find comment in db");
                Assert.AreEqual(submissionFromRepo.UpCount, c.Response.UpCount);
                Assert.AreEqual(submissionFromRepo.DownCount, c.Response.DownCount);
            }
            Assert.IsTrue(voteEventReceived, "VoteEvent not have the expected values");

            //Verify Submission pull has correct vote value recorded in output for current user
            var q = new QuerySubmission(newSubmission.ID, true).SetUserContext(user);
            var submission = q.Execute();
            Assert.IsNotNull(submission);
            Assert.AreEqual(c.RecordedValue, submission.Vote);

            //Verify non-logged in user has correct vote value
            TestHelper.SetPrincipal(null);
            q = new QuerySubmission(1, true);
            submission = q.Execute();
            Assert.IsNotNull(submission);
            Assert.AreEqual(null, submission.Vote);
        }
Beispiel #7
0
        public void CreateSubmissionTrapJSMarkdown()
        {
            var user = TestHelper.SetPrincipal("TestUser02");

            var cmd = new CreateSubmissionCommand(new Domain.Models.UserSubmission()
            {
                Subverse = SUBVERSES.Whatever, Title = "This is a title", Content = "[Click here... Please. For research.](javascript:alert('arst');)"
            }).SetUserContext(user);
            var r = cmd.Execute().Result;

            VoatAssert.IsValid(r);
            //Assert.AreEqual(r.Message, "The url you are trying to submit is invalid");
            var q          = new QuerySubmission(r.Response.ID);
            var submission = q.Execute();

            Assert.IsNotNull(submission, "Submission not found");
            Assert.AreEqual(submission.FormattedContent, "<p><a href=\"#\" data-ScriptStrip=\"/* script detected: javascript:alert('arst'); */\">Click here... Please. For research.</a></p>");
        }
        public static async Task <VoteAggregate> Load(Vote vote)
        {
            var aggregate = new VoteAggregate();

            aggregate.Vote = vote;

            if (aggregate.Vote != null)
            {
                var s = new QueryVoteStatistics(aggregate.Vote.ID);
                aggregate.Statistics = await s.ExecuteAsync();

                if (aggregate.Statistics.Raw.Count == 0)
                {
                    //For testing, vote has no stats so lets generate some
                    var generate = new Func <Dictionary <int, int> >(() => {
                        var dict   = new Dictionary <int, int>();
                        var random = new Random();

                        foreach (var o in aggregate.Vote.Options)
                        {
                            dict.Add(o.ID, random.Next(1, 5000));
                        }

                        return(dict);
                    });

                    aggregate.Statistics.Raw.Add(VoteRestrictionStatus.Certified, generate());
                    aggregate.Statistics.Raw.Add(VoteRestrictionStatus.Uncertified, generate());
                    aggregate.Statistics.Friendly = null;
                }



                if (aggregate.Vote.SubmissionID > 0)
                {
                    var sub = new QuerySubmission(aggregate.Vote.SubmissionID);
                    aggregate.Submission = await sub.ExecuteAsync();
                }
            }
            return(aggregate);
        }
Beispiel #9
0
        protected override object GetMissingValue(string name)
        {
            switch (name)
            {
            case "Subverse":
                if (SubmissionID != null)
                {
                    var cmd        = new QuerySubmission(SubmissionID.Value);
                    var submission = cmd.Execute();
                    PropertyBag.Submission = submission;

                    var cmdSubverse = new QuerySubverse(submission.Subverse);
                    var subverse    = cmdSubverse.Execute();

                    return(subverse);
                }
                if (CommentID != null)
                {
                    var cmdComment = new QueryComment(CommentID.Value);
                    var comment    = cmdComment.Execute();
                    PropertyBag.Comment = comment;

                    var cmd        = new QuerySubmission(comment.SubmissionID.Value);
                    var submission = cmd.Execute();
                    PropertyBag.Submission = submission;

                    var cmdSubverse = new QuerySubverse(submission.Subverse);
                    var subverse    = cmdSubverse.Execute();

                    return(subverse);
                }
                break;
            }

            return(base.GetMissingValue(name));
        }
        protected override object GetMissingValue(string name)
        {
            //TODO: This lazy loading needs to be optimized and rewritten. I. Don't. Like. This.
            switch (name)
            {
            case "Comment":
                if (CommentID != null)
                {
                    var cmdComment = new QueryComment(CommentID.Value);
                    var comment    = cmdComment.Execute();
                    PropertyBag.Comment = comment;

                    return(comment);
                }
                break;

            case "Submission":
                if (SubmissionID != null)
                {
                    var cmd        = new QuerySubmission(SubmissionID.Value);
                    var submission = cmd.Execute();
                    return(submission);
                }
                if (CommentID != null)
                {
                    var cmdComment = new QueryComment(CommentID.Value);
                    var comment    = cmdComment.Execute();
                    PropertyBag.Comment = comment;

                    var cmd        = new QuerySubmission(comment.SubmissionID.Value);
                    var submission = cmd.Execute();
                    return(submission);
                }
                break;

            case "Subverse":
                if (SubmissionID != null)
                {
                    var cmd        = new QuerySubmission(SubmissionID.Value);
                    var submission = cmd.Execute();
                    PropertyBag.Submission = submission;

                    var cmdSubverse = new QuerySubverse(submission.Subverse);
                    var subverse    = cmdSubverse.Execute();

                    return(subverse);
                }
                if (CommentID != null)
                {
                    var cmdComment = new QueryComment(CommentID.Value);
                    var comment    = cmdComment.Execute();
                    PropertyBag.Comment = comment;

                    var cmd        = new QuerySubmission(comment.SubmissionID.Value);
                    var submission = cmd.Execute();
                    PropertyBag.Submission = submission;

                    var cmdSubverse = new QuerySubverse(submission.Subverse);
                    var subverse    = cmdSubverse.Execute();

                    return(subverse);
                }
                break;
            }

            return(base.GetMissingValue(name));
        }
Beispiel #11
0
        //// 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));
        }