Change in custom moderation

Topics: Business Logic Layer
Nov 18, 2009 at 7:48 AM

I have the last version in the source control and I think that the method of custom moderation is not the better. I have introduced a few changes in the RunCustomModerators method and I will want open this discussion about this. 

My changes started because, in the last version ( if the fisrt filter (akismet) set that the comment is spam, and the second (stopforumspam) set that is not spam, finally the comment are set with IsApproved = true.
In my opinion if one filter set that the comment are spam, the comment must have IsApproved = false.

I have changed the code in this mode:

static void RunCustomModerators(Comment comment)
    DataTable dt = _customFilters.GetDataTable();
    dt.DefaultView.Sort = "Priority";

    foreach (DataRowView row in dt.DefaultView)
        string fileterName = row[0].ToString();

        ICustomFilter customFilter = GetCustomFilter(fileterName);             

        if (customFilter != null && customFilter.Initialize())
            bool isSpam = customFilter.Check(comment);
            comment.IsApproved = !isSpam;
            comment.ModeratedBy = isSpam ? fileterName : string.Empty;
            UpdateCustomFilter(fileterName, comment.IsApproved);

            if (isSpam)

            // the custom filter tells no further
            // validation needed. don't call others
            if (!customFilter.FallThrough) break;

I have write "comment.ModeratedBy = isSpam ? fileterName : string.Empty;" because (in my opinion) is not ok that if comment is not spam, that have the moderatedBy set with the name of last custom filter.
And "if (isSpam) return;" becuase I dont like that other custom filter can set IsApproved = true in a spam comment.

Have you other opinion?

Nov 18, 2009 at 6:25 PM

There are few things in custom filter that handle situation you described. You can set priority to determine order in which filters will be executed and you can set fall through property that tells BE if you want filter's decision to be the final. So, you would set stop forum filter run first and, only if it found that comment is spam, set fall through to false so that Akismet would not run. But you still want it to run if comment IP not found in stop forum spam database. This way you, when developing custom filter, have more flexibility.

Nov 19, 2009 at 7:15 AM

Ah, ok. When I have see the property FallThrough, I have thinked that have a fixed value.

In this case, I change the code in the filters for change the FallThrough when the comment is spam.

Thanks for the clarification. ;-)