From 0566c2647f3da626a8c153fadd1554cc841f5c2b Mon Sep 17 00:00:00 2001 From: Keith W Date: Tue, 23 Oct 2018 07:17:30 -0500 Subject: [PATCH 1/4] Deactivate rule if disabled The change deactivates the rule if a user has disabled it. --- .../HandleRules/RuleService.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs b/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs index 211c5d380..2873a1ebc 100644 --- a/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs +++ b/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs @@ -56,6 +56,11 @@ namespace Squidex.Domain.Apps.Core.HandleRules Guard.NotNull(rule, nameof(rule)); Guard.NotNull(@event, nameof(@event)); + if (!rule.IsEnabled) + { + return null; + } + if (!(@event.Payload is AppEvent appEvent)) { return null; From 3d49eba9853ec279521aba592f90a3b4dc6525ad Mon Sep 17 00:00:00 2001 From: Keith W Date: Tue, 23 Oct 2018 07:19:22 -0500 Subject: [PATCH 2/4] Added unit test for disabled rules --- .../Operations/HandleRules/RuleServiceTests.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs index b9811bf86..d6f092fbb 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs @@ -253,5 +253,18 @@ namespace Squidex.Domain.Apps.Core.Operations.HandleRules Assert.Equal((ruleError.ToString(), RuleResult.Failed, TimeSpan.Zero), result); } + + [Fact] + public async Task Should_not_create_if_rule_disabled() + { + var ruleConfig = new Rule(new ContentChangedTrigger(), new ValidAction()); + var ruleEnvelope = Envelope.Create(new ContentCreated()); + + ruleConfig = ruleConfig.Disable(); + + var job = await sut.CreateJobAsync(ruleConfig, ruleEnvelope); + + Assert.Null(job); + } } -} \ No newline at end of file +} From dc174f384cb5aea6eaccc2a8fdc0eb36f0769fe3 Mon Sep 17 00:00:00 2001 From: Keith Wyss Date: Tue, 23 Oct 2018 08:52:17 -0500 Subject: [PATCH 3/4] Fixed whitespace issues. --- .../HandleRules/RuleService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs b/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs index 2873a1ebc..18329060a 100644 --- a/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs +++ b/src/Squidex.Domain.Apps.Core.Operations/HandleRules/RuleService.cs @@ -60,7 +60,7 @@ namespace Squidex.Domain.Apps.Core.HandleRules { return null; } - + if (!(@event.Payload is AppEvent appEvent)) { return null; From 663c0b598f760c00c147f2ec566df4b9b8830357 Mon Sep 17 00:00:00 2001 From: Keith Wyss Date: Tue, 23 Oct 2018 08:55:31 -0500 Subject: [PATCH 4/4] Fixed whitespace issue --- .../Operations/HandleRules/RuleServiceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs index d6f092fbb..f21de9c6b 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleServiceTests.cs @@ -253,7 +253,7 @@ namespace Squidex.Domain.Apps.Core.Operations.HandleRules Assert.Equal((ruleError.ToString(), RuleResult.Failed, TimeSpan.Zero), result); } - + [Fact] public async Task Should_not_create_if_rule_disabled() {