From ef246e6026d5f309866d5819795fe865105be873 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Mon, 27 May 2024 14:45:40 +0530 Subject: [PATCH 1/3] feat: Editable tags function added --- .talismanrc | 2 + .../Interfaces/IEmbeddedObject.cs | 8 ++ Contentstack.Utils/Utils.cs | 89 +++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/.talismanrc b/.talismanrc index bd9bf54..4628b50 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,4 +1,6 @@ fileignoreconfig: - filename: Contentstack.Utils/Models/Options.cs checksum: 3dc51f0de02429ef9a43b66e666ac4dbde41195e245f8ecc0094548ca8603245 +- filename: Contentstack.Utils/Utils.cs + checksum: dfcfa04bedf8e5f9e74f68d02a9f8cb4e35de399e272da015453c6bc4c481e3f version: "" \ No newline at end of file diff --git a/Contentstack.Utils/Interfaces/IEmbeddedObject.cs b/Contentstack.Utils/Interfaces/IEmbeddedObject.cs index 278de5f..8244017 100644 --- a/Contentstack.Utils/Interfaces/IEmbeddedObject.cs +++ b/Contentstack.Utils/Interfaces/IEmbeddedObject.cs @@ -24,6 +24,14 @@ string Title } } + public interface EditableEntry: IEmbeddedEntry + { + + string Locale { get; set; } + + object this[string key] { get; set; } + } + public interface IEmbeddedAsset: IEmbeddedObject { string Title diff --git a/Contentstack.Utils/Utils.cs b/Contentstack.Utils/Utils.cs index 645f8bf..34b6a96 100644 --- a/Contentstack.Utils/Utils.cs +++ b/Contentstack.Utils/Utils.cs @@ -193,5 +193,94 @@ private static IEmbeddedObject findEmbedded(Metadata metadata, List GetTag(object content, string prefix, bool tagsAsObject, string locale) + { + var tags = new Dictionary(); + foreach (var property in (Dictionary)content) + { + var key = property.Key; + var value = property.Value; + + if (key == "$") + continue; + + switch (value) + { + case object obj when obj is object[] array: + for (int index = 0; index < array.Length; index++) + { + object objValue = array[index]; + string childKey = $"{key}__{index}"; + string parentKey = $"{key}__parent"; + + tags[childKey] = GetTagsValue($"{prefix}.{key}.{index}", tagsAsObject); + tags[parentKey] = GetParentTagsValue($"{prefix}.{key}", tagsAsObject); + + if (objValue != null && + objValue.GetType().GetProperty("_content_type_uid") != null && + objValue.GetType().GetProperty("Uid") != null) + { + var typedObj = (EditableEntry)objValue; + string locale_ = Convert.ToString(typedObj.GetType().GetProperty("locale").GetValue(typedObj)); + string ctUid = Convert.ToString(typedObj.GetType().GetProperty("_content_type_uid").GetValue(typedObj)); + string uid = Convert.ToString(typedObj.GetType().GetProperty("uid").GetValue(typedObj)); + string localeStr = ""; + if (locale_ != null) + { + localeStr = locale_; + } else + { + localeStr = locale; + } + typedObj["$"] = GetTag(typedObj, $"{ctUid}.{uid}.{localeStr}", tagsAsObject, locale); + } + else if (value is object) + { + ((EditableEntry)value)["$"] = GetTag(value, $"{prefix}.{key}.{index}", tagsAsObject, locale); + } + } + tags[key] = GetTagsValue($"{prefix}.{key}", tagsAsObject); + break; + case object obj when obj != null: + if (value != null) + { + ((EditableEntry)value)["$"] = GetTag(value, $"{prefix}.{key}", tagsAsObject, locale); + } + break; + } + } + return tags; + } + + private static object GetTagsValue(string dataValue, bool tagsAsObject) + { + if (tagsAsObject) + { + return new Dictionary { { "data-cslp", dataValue } }; + } + else + { + return $"data-cslp={dataValue}"; + } + } + + private static object GetParentTagsValue(string dataValue, bool tagsAsObject) + { + if (tagsAsObject) + { + return new Dictionary { { "data-cslp-parent-field", dataValue } }; + } + else + { + return $"data-cslp-parent-field={dataValue}"; + } + } } } From 31bdf6b39c39e194bbe536d671360b159edd8249 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Tue, 9 Jul 2024 15:07:59 +0530 Subject: [PATCH 2/3] chore: version bump --- CHANGELOG.md | 4 ++++ Directory.Build.props | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9b7376..766d318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ +### Version: 1.0.3 +#### Date: Jul-10-2024 +- Editable tags added + ### Version: 1.0.2 #### Date: Mar-14-2024 - Style attributes supported in converted HTML. diff --git a/Directory.Build.props b/Directory.Build.props index 4f93bc6..80b11f8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.0.2 + 1.0.3 From 8ea40dbd8ece40cc66d83ccc7e124a776f2db8c0 Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Tue, 9 Jul 2024 15:18:41 +0530 Subject: [PATCH 3/3] Update sca-scan.yml --- .github/workflows/sca-scan.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml index 4fa4560..a642aef 100644 --- a/.github/workflows/sca-scan.yml +++ b/.github/workflows/sca-scan.yml @@ -6,10 +6,14 @@ jobs: security-sca: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - name: Checkout repository + uses: actions/checkout@master + - uses: snyk/actions/setup@master + - name: Setup .NET + uses: actions/setup-dotnet@v3.0.3 + - name: Restore dependencies + run: dotnet restore ./Contentstack.Utils.sln - name: Run Snyk to check for vulnerabilities - uses: snyk/actions/dotnet@master + run: cd Contentstack.Utils && snyk test --fail-on=all env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - with: - args: --fail-on=all