FilterAfterPersist() public method

Filters the comment. Throws an exception should the comment not be allowed. Otherwise returns true. This interface may be changed.

The first filter examines whether comments are coming in too quickly from the same SourceUrl. Looks at the BlogInfo.CommentDelayInMinutes.

The second filter checks for duplicate comments. It only looks at the body of the comment.

public FilterAfterPersist ( FeedbackItem feedbackItem ) : void
feedbackItem Subtext.Framework.Components.FeedbackItem Entry.
return void
コード例 #1
0
        public void FilterAfterPersistWithCommentModerationDisabledCausesNewCommentsToBeActive()
        {
            //arrange
            var subtextContext = new Mock<ISubtextContext>();
            var cache = new TestCache();
            subtextContext.Setup(c => c.Cache).Returns(cache);
            subtextContext.Setup(c => c.User.IsInRole("Admins")).Returns(false);
            subtextContext.Setup(c => c.Blog).Returns(new Blog { ModerationEnabled = false });
            FeedbackItem savedFeedback = null;
            subtextContext.Setup(c => c.Repository.UpdateInternal(It.IsAny<FeedbackItem>())).Callback<FeedbackItem>(
                f => savedFeedback = f);

            var commentSpamFilter = new Mock<ICommentSpamService>();
            var commentFilter = new CommentFilter(subtextContext.Object, commentSpamFilter.Object);
            var feedback = new FeedbackItem(FeedbackType.Comment) { };
            Assert.IsFalse(feedback.Approved);

            //act
            commentFilter.FilterAfterPersist(feedback);

            //assert
            Assert.IsTrue(savedFeedback.Approved);
        }
コード例 #2
0
        protected void lkbPost_Click(object sender, EventArgs e)
        {
            try
            {
                var entry = new Trackback(EntryId, txbTitle.Text, txbUrl.Text.EnsureUrl(), string.Empty,
                                          txbBody.Text.Trim().Length > 0 ? txbBody.Text.Trim() : txbTitle.Text,
                                          Config.CurrentBlog.TimeZone.Now);
                var commentService = new CommentService(SubtextContext, null);

                if(commentService.Create(entry, true/*runFilters*/) > 0)
                {
                    ICommentSpamService feedbackService = null;
                    if(Config.CurrentBlog.FeedbackSpamServiceEnabled)
                    {
                        feedbackService = new AkismetSpamService(Config.CurrentBlog.FeedbackSpamServiceKey,
                                                                 Config.CurrentBlog, null, Url);
                    }
                    var filter = new CommentFilter(SubtextContext, feedbackService);
                    filter.FilterAfterPersist(entry);
                    Messages.ShowMessage(Constants.RES_SUCCESSNEW);
                    Edit.Visible = false;
                    Results.Visible = true;
                }
                else
                {
                    Messages.ShowError(Constants.RES_FAILUREEDIT
                                       + " There was a baseline problem posting your Trackback.");
                }
            }
            catch(Exception ex)
            {
                Log.Error(ex.Message, ex);
                Messages.ShowError(String.Format(Constants.RES_EXCEPTION,
                                                 Constants.RES_FAILUREEDIT, ex.Message));
            }
        }
コード例 #3
0
ファイル: Referrers.aspx.cs プロジェクト: ayende/Subtext
        protected void lkbPost_Click(object sender, EventArgs e)
        {
            try
            {
                Trackback entry = new Trackback(EntryID, txbTitle.Text, HtmlHelper.CheckForUrl(txbUrl.Text), string.Empty, txbBody.Text.Trim().Length > 0 ? txbBody.Text.Trim() : txbTitle.Text, Config.CurrentBlog.TimeZone.Now);

                if(FeedbackItem.Create(entry, null) > 0)
                {
                    CommentFilter filter = new CommentFilter(HttpContext.Current.Cache);
                    filter.FilterAfterPersist(entry);
                    this.Messages.ShowMessage(Constants.RES_SUCCESSNEW);
                    this.Edit.Visible = false;
                    this.Results.Visible = true;
                }
                else
                {
                    this.Messages.ShowError(Constants.RES_FAILUREEDIT
                        + " There was a baseline problem posting your Trackback.");
                }
            }
            catch(Exception ex)
            {
                log.Error(ex.Message, ex);
                this.Messages.ShowError(String.Format(Constants.RES_EXCEPTION,
                    Constants.RES_FAILUREEDIT, ex.Message));
            }
        }