Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/spe script rule #1059

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
<targetDataStore physicalRootPath="$(speSourceFolder)\Data\serialization\Rules" useDataCache="false" singleInstance="true" />
<predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true">
<include name="Tags" database="master" path="/sitecore/system/Settings/Rules/Definitions/Tags/PowerShell" />
<include name="Editor Rules Tags" database="master" path="/sitecore/system/Settings/Rules/Definitions/Tags/PowerShell Editor Rules" />
<include name="Experience Button Tags" database="master" path="/sitecore/system/Settings/Rules/Definitions/Tags/PowerShell Experience Buttons" />
<include name="ISE Tags" database="master" path="/sitecore/system/Settings/Rules/Definitions/Tags/PowerShell ISE" />
<include name="Rules" database="master" path="/sitecore/system/Settings/Rules/Definitions/Elements/PowerShell" />
<include name="Editor Rules" database="master" path="/sitecore/system/Settings/Rules/Definitions/Elements/PowerShell Editor Rules" />
<include name="Experience Button Rules" database="master" path="/sitecore/system/Settings/Rules/Definitions/Elements/PowerShell Experience Buttons" />
<include name="ISE Rules" database="master" path="/sitecore/system/Settings/Rules/Definitions/Elements/PowerShell ISE" />
<include name="Security Rules" database="master" path="/sitecore/system/Settings/Rules/Definitions/Elements/PowerShell Security" />
Expand Down
1 change: 1 addition & 0 deletions Cognifide.PowerShell/Cognifide.PowerShell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@
<Compile Include="Integrations\Processors\ScriptedRenderingDataSourceRoots.cs" />
<Compile Include="Integrations\Processors\ScriptedRenderRendering.cs" />
<Compile Include="Integrations\Processors\SkipPowerShellScriptItems.cs" />
<Compile Include="Core\Rules\PowerShellBooleanScriptRule.cs" />
<Compile Include="Integrations\Tasks\ExecuteScriptTask.cs" />
<Compile Include="Integrations\Tasks\ScriptedItemEventHandler.cs" />
<Compile Include="Integrations\Workflows\ScriptAction.cs" />
Expand Down
54 changes: 54 additions & 0 deletions Cognifide.PowerShell/Core/Rules/PowerShellBooleanScriptRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Linq;
using Cognifide.PowerShell.Core.Extensions;
using Cognifide.PowerShell.Core.Host;
using Sitecore.Data;
using Sitecore.Diagnostics;
using Sitecore.Rules;
using Sitecore.Rules.Conditions;

namespace Cognifide.PowerShell.Core.Rules
{
public class PowerShellBooleanScriptRule<T> : StringOperatorCondition<T> where T : RuleContext
{
public ID ScriptId { get; set; }
protected override bool Execute(T ruleContext)
{
var ruleResponse = false;
Assert.IsNotNull(ruleContext, "RuleContext is null");
try
{
var scriptItem = Sitecore.Context.Database.GetItem(ScriptId);
if (scriptItem.InheritsFrom(Templates.Script.Id))
{
var scriptItemField = scriptItem.Fields[Templates.Script.Fields.ScriptBody];
using (ScriptSession scriptSession = ScriptSessionManager.NewSession("Default", true))
{
string script = scriptItemField.GetValue(false);
if (!string.IsNullOrEmpty(script))
{
var results = scriptSession.ExecuteScriptPart(script, false);
//if anything in results is a non-false value, return true
ruleResponse = results.Any(r => bool.Parse(r.ToString()));
}
else
{
Log.Warn("Selected Script Item is empty", this);
}
}
}
else
{
Log.Warn("Selected Item is not a Script", this);
}

}
catch (Exception ex)
{
Log.Error("Error in Boolean Script Rule", ex, this);
throw;
}
return ruleResponse;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
ID: "f9ce8201-c7fd-4217-ac4a-45205ca80faf"
Parent: "dadb4f93-477f-491f-a905-c4005c452e67"
Template: "1a9b6300-4652-477c-a4b5-b2a64e86b29f"
Path: /sitecore/system/Settings/Rules/Definitions/Tags/PowerShell Editor Rules
DB: master
SharedFields:
- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e"
Hint: __Sortorder
Value: 2400
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20131231T141935
- ID: "5dd74568-4d4b-44c1-b513-0af5f4cda34f"
Hint: __Created by
Value: |
sitecore\admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
ID: "ebb33f36-07c6-4268-9382-fe432e70f1ad"
Parent: "f9ce8201-c7fd-4217-ac4a-45205ca80faf"
Template: "aa91a868-02f2-41d3-8b78-1cad91b4dcae"
Path: /sitecore/system/Settings/Rules/Definitions/Tags/PowerShell Editor Rules/Visibility
DB: master
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20131231T141936
- ID: "5dd74568-4d4b-44c1-b513-0af5f4cda34f"
Hint: __Created by
Value: |
sitecore\admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
ID: "d555657d-f954-497c-a293-65d5e695ab61"
Parent: "e7cbefe8-9112-4b95-a978-4e470d94c54a"
Template: "54dae7cd-bfd8-4e69-9679-75f2ae9f9034"
Path: /sitecore/system/Settings/Rules/Definitions/Elements/PowerShell Editor Rules
DB: master
BranchID: "9a72c539-dbf8-4dad-96d3-a298fc04add6"
SharedFields:
- ID: "f6d8a61c-2f84-4401-bd24-52d2068172bc"
Hint: __Originator
Value: "{8D1DB71C-9ACF-4192-8384-5F9B6D533F95}"
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20181020T161858Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
ID: "7477d094-b434-4ceb-bccc-45c02ceb6a5d"
Parent: "d555657d-f954-497c-a293-65d5e695ab61"
Template: "f0d16eee-3a05-4e43-a082-795a32b873c0"
Path: /sitecore/system/Settings/Rules/Definitions/Elements/PowerShell Editor Rules/Script Returns True Value
DB: master
SharedFields:
- ID: "ab51c8b2-f0e1-4471-9aae-cc080d774923"
Hint: Type
Value: Cognifide.PowerShell.Core.Rules.PowerShellBooleanScriptRule,Cognifide.PowerShell
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20181020T152609Z
- ID: "5dd74568-4d4b-44c1-b513-0af5f4cda34f"
Hint: __Created by
Value: |
sitecore\admin
- ID: "af321234-4eb9-4ef5-9197-65903351939c"
Hint: Text
Value: |
where [ScriptId,tree,root=/sitecore/system/Modules/PowerShell/Script Library,specific PowerShell script] returns a "true" value
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
ID: "a96b0241-65f0-494f-89f6-c5a769cbda48"
Parent: "d555657d-f954-497c-a293-65d5e695ab61"
Template: "96c8e5dd-63c3-496b-a97c-a3e37e1dacba"
Path: /sitecore/system/Settings/Rules/Definitions/Elements/PowerShell Editor Rules/Tags
DB: master
BranchID: "9a72c539-dbf8-4dad-96d3-a298fc04add6"
SharedFields:
- ID: "f6d8a61c-2f84-4401-bd24-52d2068172bc"
Hint: __Originator
Value: "{FD4268C6-E588-4C19-B141-B1AAD488887D}"
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20181020T161858Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
ID: "53d8bfe8-6a0e-45d2-a6e4-ea0ba47d27b9"
Parent: "a96b0241-65f0-494f-89f6-c5a769cbda48"
Template: "854ba861-63ea-4a0c-8c7b-541e9a7ec4c1"
Path: /sitecore/system/Settings/Rules/Definitions/Elements/PowerShell Editor Rules/Tags/Default
DB: master
BranchID: "9a72c539-dbf8-4dad-96d3-a298fc04add6"
SharedFields:
- ID: "42f77151-098f-496a-94cf-590b7edeeabe"
Hint: Tags
Type: Multilist
Value: "{F9CE8201-C7FD-4217-AC4A-45205CA80FAF}"
- ID: "f6d8a61c-2f84-4401-bd24-52d2068172bc"
Hint: __Originator
Value: "{6F0688E4-7B16-482F-845B-35836FD15D14}"
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20181020T161858Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
ID: "bc88bbf4-ea57-41ff-bf37-bfd353dd5c3e"
Parent: "d555657d-f954-497c-a293-65d5e695ab61"
Template: "aa91a868-02f2-41d3-8b78-1cad91b4dcae"
Path: /sitecore/system/Settings/Rules/Definitions/Elements/PowerShell Editor Rules/Visibility
DB: master
BranchID: "9a72c539-dbf8-4dad-96d3-a298fc04add6"
SharedFields:
- ID: "f6d8a61c-2f84-4401-bd24-52d2068172bc"
Hint: __Originator
Value: "{283F6CD6-EFB8-47AC-946A-ABB17FA45ECB}"
Languages:
- Language: en
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20181020T161858Z