예제 #1
0
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            string content = context.PropertyBag.CommentContent;

            if (String.IsNullOrWhiteSpace(content))
            {
                return(base.CreateOutcome(RuleResult.Denied, "Empty comments not allowed"));
            }

            //Was being triggered for edits with only case changes
            if (Scope == RuleScope.PostComment)
            {
                // check for copypasta
                using (var repo = new Repository())
                {
                    var copyPasta = repo.SimilarCommentSubmittedRecently(context.UserName, content.TrimWhiteSpace(), TimeSpan.FromHours(24));
                    if (copyPasta)
                    {
                        return(base.CreateOutcome(RuleResult.Denied, "You have recently submitted a similar comment. Please try to not use copy/paste so often."));
                    }
                }
            }

            return(Allowed);
        }
예제 #2
0
 protected override RuleOutcome EvaluateRule(VoatRuleContext context)
 {
     if (context.UserData.Information.CommentPoints.Sum < MinimumCommentPoints)
     {
         return(CreateOutcome(RuleResult.Denied, (String.Format("CCP of {0} is below minimum of {1} required for action {2}", context.UserData.Information.CommentPoints.Sum, MinimumCommentPoints, Scope.ToString()))));
     }
     return(base.EvaluateRule(context));
 }
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            string name = context.PropertyBag.SubverseName;

            if (String.IsNullOrWhiteSpace(name))
            {
                return(base.CreateOutcome(RuleResult.Denied, "Subverses must have a valid name"));
            }

            if (!Regex.IsMatch(name, String.Concat("^", CONSTANTS.SUBVERSE_REGEX, "$")))
            {
                return(base.CreateOutcome(RuleResult.Denied, "Subverse name does not conform to naming requirements"));
            }
            if (VoatSettings.Instance.ReservedSubverseNames.Contains(name.ToLower()))
            {
                return(base.CreateOutcome(RuleResult.Denied, "Subverse name is reserved and can not be used"));
            }
            using (var repo = new Repository())
            {
                name = repo.ToCorrectSubverseCasing(name);
                if (!String.IsNullOrEmpty(name))
                {
                    return(base.CreateOutcome(RuleResult.Denied, "Sorry, The subverse you are trying to create already exists, but you can try to claim it by submitting a takeover request to /v/subverserequest"));
                }
                var subs = repo.GetSubversesUserModerates(context.UserName);
                if (subs.Count(x => x.Power <= 2) >= VoatSettings.Instance.MaximumOwnedSubs)
                {
                    return(base.CreateOutcome(RuleResult.Denied, "Sorry, you can not moderate more than " + VoatSettings.Instance.MaximumOwnedSubs + " subverses."));
                }
            }

            //Age
            var registrationDate = context.UserData.Information.RegistrationDate;
            int accountAgeInDays = Repository.CurrentDate.Subtract(registrationDate).Days;

            if (accountAgeInDays < VoatSettings.Instance.MinimumAccountAgeInDaysForSubverseCreation)
            {
                return(base.CreateOutcome(RuleResult.Denied, $"Sorry, subverse creation requires an account age of {VoatSettings.Instance.MinimumAccountAgeInDaysForSubverseCreation} days"));
            }
            //CCP
            if (context.UserData.Information.CommentPoints.Sum < VoatSettings.Instance.MinimumCommentPointsForSubverseCreation)
            {
                return(base.CreateOutcome(RuleResult.Denied, $"Sorry, subverse creation requires a minimum of {VoatSettings.Instance.MinimumCommentPointsForSubverseCreation} comment (CCP) points"));
            }
            //SCP
            if (context.UserData.Information.SubmissionPoints.Sum < VoatSettings.Instance.MinimumSubmissionPointsForSubverseCreation)
            {
                return(base.CreateOutcome(RuleResult.Denied, $"Sorry, subverse creation requires a minimum of {VoatSettings.Instance.MinimumSubmissionPointsForSubverseCreation} submission (SCP) points"));
            }

            //rules checkd in base class
            return(base.EvaluateRule(context));
        }
예제 #4
0
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            var subverse = context.Subverse;

            int?subMinCCP = subverse.MinCCPForDownvote;

            if (subMinCCP.HasValue && subMinCCP.Value > 0)
            {
                var q     = new QueryUserContributionPoints(Domain.Models.ContentType.Comment, subverse.Name);
                var score = q.Execute();

                if (score.Sum < subMinCCP.Value)
                {
                    return(CreateOutcome(RuleResult.Denied, String.Format("Subverse '{0}' requires {1}CCP to downvote", subverse.Name, subMinCCP.Value.ToString())));
                }
            }

            return(base.EvaluateRule(context));
        }
예제 #5
0
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            Domain.Models.Set set = context.PropertyBag.Set;

            if (String.IsNullOrWhiteSpace(set.Name))
            {
                return(base.CreateOutcome(RuleResult.Denied, "Sets must have a valid name"));
            }

            if (!Regex.IsMatch(set.Name, String.Concat("^", CONSTANTS.SUBVERSE_REGEX, "$")))
            {
                return(base.CreateOutcome(RuleResult.Denied, "Set name does not conform to naming requirements"));
            }
            //Ensure Name is not used for system sets
            var systemSets = Enum.GetNames(typeof(SetType)).Concat(Enum.GetNames(typeof(SortAlgorithm)));

            if (systemSets.Any(x => x.IsEqual(set.Name)))
            {
                return(base.CreateOutcome(RuleResult.Denied, "Set name is in a restricted list - please choose a different name"));
            }

            ////Age
            //var registrationDate = context.UserData.Information.RegistrationDate;
            //int accountAgeInDays = Repository.CurrentDate.Subtract(registrationDate).Days;
            //if (accountAgeInDays < VoatSettings.Instance.MinimumAccountAgeInDaysForSubverseCreation)
            //{
            //    return base.CreateOutcome(RuleResult.Denied, $"Sorry, subverse creation requires an account age of {VoatSettings.Instance.MinimumAccountAgeInDaysForSubverseCreation} days");
            //}
            ////CCP
            //if (context.UserData.Information.CommentPoints.Sum < VoatSettings.Instance.MinimumCommentPointsForSubverseCreation)
            //{
            //    return base.CreateOutcome(RuleResult.Denied, $"Sorry, subverse creation requires a minimum of {VoatSettings.Instance.MinimumCommentPointsForSubverseCreation} comment (CCP) points");
            //}
            ////SCP
            //if (context.UserData.Information.SubmissionPoints.Sum < VoatSettings.Instance.MinimumSubmissionPointsForSubverseCreation)
            //{
            //    return base.CreateOutcome(RuleResult.Denied, $"Sorry, subverse creation requires a minimum of {VoatSettings.Instance.MinimumSubmissionPointsForSubverseCreation} submission (SCP) points");
            //}

            //rules checkd in base class
            return(base.EvaluateRule(context));
        }
예제 #6
0
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            string content = context.PropertyBag.CommentContent;

            if (String.IsNullOrWhiteSpace(content))
            {
                return(base.CreateOutcome(RuleResult.Denied, "Empty comments not allowed"));
            }

            // check for copypasta
            // TODO: use Levenshtein distance algo or similar for better results
            var copyPasta = UserHelper.SimilarCommentSubmittedRecently(context.UserName, content);

            if (copyPasta)
            {
                return(base.CreateOutcome(RuleResult.Denied, "You have recently submitted a similar comment. Please try to not use copy/paste so often."));
            }

            return(Allowed);
        }
예제 #7
0
        protected override RuleOutcome EvaluateRule(VoatRuleContext context)
        {
            DemandContext(context);

            Subverse subverse = context.PropertyBag.Subverse;

            if (((int)base.Scope & (int)RuleAction.Create) > 0)
            {
                if (subverse.IsAdminDisabled.HasValue && subverse.IsAdminDisabled.Value)
                {
                    return(CreateOutcome(RuleResult.Denied, "Subverse is disabled"));
                }
            }
            if (UserHelper.IsUserBannedFromSubverse(context.UserName, subverse.Name))
            {
                return(CreateOutcome(RuleResult.Denied, "User is banned from v/{0}", subverse.Name));
            }

            return(base.EvaluateRule(context));
        }