public RulePartHandler(IRulesManager rulesManager) { OnPublished <ContentPart>( (context, part) => rulesManager.TriggerEvent("Content", "Published", () => new Dictionary <string, object> { { "Content", context.ContentItem } })); OnRemoved <ContentPart>( (context, part) => rulesManager.TriggerEvent("Content", "Removed", () => new Dictionary <string, object> { { "Content", context.ContentItem } })); OnVersioned <ContentPart>( (context, part1, part2) => rulesManager.TriggerEvent("Content", "Versioned", () => new Dictionary <string, object> { { "Content", part1.ContentItem } })); OnCreated <ContentPart>( (context, part) => rulesManager.TriggerEvent("Content", "Created", () => new Dictionary <string, object> { { "Content", context.ContentItem } })); }
public SpamStatus CheckForSpam(SpamFilterPart part) { var settings = part.TypePartDefinition.Settings.GetModel <SpamFilterPartSettings>(); // evaluate the text to submit to the spam filters var text = _tokenizer.Replace(settings.Pattern, new Dictionary <string, object> { { "Content", part.ContentItem } }); var result = CheckForSpam(text, settings.Action); // trigger events and rules switch (result) { case SpamStatus.Spam: _spamEventHandler.SpamReported(part); _rulesManager.TriggerEvent("AntiSpam", "Spam", () => new Dictionary <string, object> { { "Content", part.ContentItem } }); break; case SpamStatus.Ham: _spamEventHandler.HamReported(part); _rulesManager.TriggerEvent("AntiSpam", "Ham", () => new Dictionary <string, object> { { "Content", part.ContentItem } }); break; default: throw new ArgumentOutOfRangeException(); } return(result); }
public SpamStatus CheckForSpam(CommentCheckContext context, SpamFilterAction action, IContent content) { if (string.IsNullOrWhiteSpace(context.CommentContent)) { return(SpamStatus.Ham); } var spamFilters = GetSpamFilters().ToList(); var result = SpamStatus.Ham; switch (action) { case SpamFilterAction.AllOrNothing: if (spamFilters.All(x => x.CheckForSpam(context) == SpamStatus.Spam)) { result = SpamStatus.Spam; } break; case SpamFilterAction.One: if (spamFilters.Any(x => x.CheckForSpam(context) == SpamStatus.Spam)) { result = SpamStatus.Spam; } break; default: throw new ArgumentOutOfRangeException(); } // trigger events and rules switch (result) { case SpamStatus.Spam: _spamEventHandler.SpamReported(content); _rulesManager.TriggerEvent("AntiSpam", "Spam", () => new Dictionary <string, object> { { "Content", content } }); break; case SpamStatus.Ham: _spamEventHandler.HamReported(content); _rulesManager.TriggerEvent("AntiSpam", "Ham", () => new Dictionary <string, object> { { "Content", content } }); break; default: throw new ArgumentOutOfRangeException(); } return(result); }
public RulePartHandler(IRulesManager rulesManager) { OnPublished<ContentPart>( (context, part) => rulesManager.TriggerEvent("Content", "Published", () => new Dictionary<string, object> { { "Content", context.ContentItem } })); OnRemoved<ContentPart>( (context, part) => rulesManager.TriggerEvent("Content", "Removed", () => new Dictionary<string, object> { { "Content", context.ContentItem } })); OnVersioned<ContentPart>( (context, part1, part2) => rulesManager.TriggerEvent("Content", "Versioned", () => new Dictionary<string, object> { { "Content", part1.ContentItem } })); OnCreated<ContentPart>( (context, part) => rulesManager.TriggerEvent("Content", "Created", () => new Dictionary<string, object> { { "Content", context.ContentItem } })); }
private ActionResult CreatePOST(int id, string returnUrl, Action <ContentItem> conditionallyPublish) { var form = _contentManager.Get(id); if (form == null || !form.Has <CustomFormPart>()) { return(HttpNotFound()); } var customForm = form.As <CustomFormPart>(); var contentItem = _contentManager.New(customForm.ContentType); if (!Services.Authorizer.Authorize(Permissions.CreateSubmitPermission(customForm.ContentType), contentItem, T("Couldn't create content"))) { return(new HttpUnauthorizedResult()); } if (customForm.SaveContentItem) { _contentManager.Create(contentItem, VersionOptions.Draft); } var model = _contentManager.UpdateEditor(contentItem, this); if (!ModelState.IsValid) { _transactionManager.Cancel(); // if custom form is inside a widget, we display the form itself if (form.ContentType == "CustomFormWidget") { foreach (var error in ModelState.Values.SelectMany(m => m.Errors).Select(e => e.ErrorMessage)) { Services.Notifier.Error(T(error)); } // save the updated editor shape into TempData to survive a redirection and keep the edited values TempData["CustomFormWidget.InvalidCustomFormState"] = model; if (returnUrl != null) { return(this.RedirectLocal(returnUrl)); } } model.ContentItem(form); return(View(model)); } contentItem.As <ICommonPart>().Container = customForm.ContentItem; // triggers any event _rulesManager.TriggerEvent("CustomForm", "Submitted", () => new Dictionary <string, object> { { "Content", contentItem } }); // trigger any workflow _workflowManager.TriggerEvent(FormSubmittedActivity.EventName, contentItem, () => new Dictionary <string, object> { { "Content", contentItem }, { "CustomForm", customForm.ContentItem } }); if (customForm.Redirect) { returnUrl = _tokenizer.Replace(customForm.RedirectUrl, new Dictionary <string, object> { { "Content", contentItem } }); } // save the submitted form if (customForm.SaveContentItem) { conditionallyPublish(contentItem); } // writes a confirmation message if (customForm.CustomMessage) { if (!String.IsNullOrWhiteSpace(customForm.Message)) { Services.Notifier.Information(T(customForm.Message)); } } var referrer = Request.UrlReferrer != null?Request.UrlReferrer.ToString() : null; return(this.RedirectLocal(returnUrl, () => this.RedirectLocal(referrer, () => Redirect(Request.RawUrl)))); }
private ActionResult CreatePOST(int id, string returnUrl, Action <ContentItem> conditionallyPublish) { var form = _contentManager.Get(id); if (form == null || !form.Has <CustomFormPart>()) { return(HttpNotFound()); } var customForm = form.As <CustomFormPart>(); var contentItem = _contentManager.New(customForm.ContentType); if (!Services.Authorizer.Authorize(Permissions.CreateSubmitPermission(customForm.ContentType), contentItem, T("Couldn't create content"))) { return(new HttpUnauthorizedResult()); } _contentManager.Create(contentItem, VersionOptions.Draft); dynamic model = _contentManager.UpdateEditor(contentItem, this); if (!ModelState.IsValid) { _transactionManager.Cancel(); // if custom form is inside a widget, we display the form itself if (form.ContentType == "CustomFormWidget") { } // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)model)); } contentItem.As <ICommonPart>().Container = customForm.ContentItem; // triggers any event _rulesManager.TriggerEvent("CustomForm", "Submitted", () => new Dictionary <string, object> { { "Content", contentItem } }); if (customForm.Redirect) { returnUrl = _tokenizer.Replace(customForm.RedirectUrl, new Dictionary <string, object> { { "Content", contentItem } }); } // save the submitted form if (!customForm.SaveContentItem) { Services.ContentManager.Remove(contentItem); } else { conditionallyPublish(contentItem); } // writes a confirmation message if (customForm.CustomMessage) { if (!String.IsNullOrWhiteSpace(customForm.Message)) { Services.Notifier.Information(T(customForm.Message)); } } return(this.RedirectLocal(returnUrl, () => Redirect(Request.RawUrl))); }