Skip to content

Commit

Permalink
Fix case insensitive dictionary problem (Lombiq Technologies: OCORE-1…
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig authored Aug 28, 2024
1 parent e23ab9e commit 5278abf
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
using OrchardCore.Data.Documents;
using Format = OrchardCore.Media.Processing.Format;
using ResizeMode = OrchardCore.Media.Processing.ResizeMode;

namespace OrchardCore.Media.Models;

public class MediaProfilesDocument : Document
{
public Dictionary<string, MediaProfile> MediaProfiles { get; init; } = new Dictionary<string, MediaProfile>(StringComparer.OrdinalIgnoreCase);
public Dictionary<string, MediaProfile> MediaProfiles { get; init; } = new(StringComparer.OrdinalIgnoreCase);
}

public class MediaProfile
{
public string Hint { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public Processing.ResizeMode Mode { get; set; }
public Processing.Format Format { get; set; }
public ResizeMode Mode { get; set; }
public Format Format { get; set; }
public int Quality { get; set; }
public string BackgroundColor { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OrchardCore.Shortcodes.Models;

public class ShortcodeTemplatesDocument : Document
{
public Dictionary<string, ShortcodeTemplate> ShortcodeTemplates { get; init; } = new Dictionary<string, ShortcodeTemplate>(StringComparer.OrdinalIgnoreCase);
public Dictionary<string, ShortcodeTemplate> ShortcodeTemplates { get; init; } = new(StringComparer.OrdinalIgnoreCase);
}

public class ShortcodeTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace OrchardCore.Sitemaps.Routing;

public class SitemapRouteDocument : Document
{
public Dictionary<string, string> SitemapIds { get; set; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
public Dictionary<string, string> SitemapIds { get; init; } = new(StringComparer.OrdinalIgnoreCase);

public Dictionary<string, string> SitemapPaths { get; set; } = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,40 +352,36 @@ public async Task<ActionResult> ListPost(ContentOptions options, IEnumerable<str
{
return Forbid();
}

if (itemIds?.Count() > 0)
switch (options.BulkAction)
{
var templatesDocument = options.AdminTemplates
? await _adminTemplatesManager.LoadTemplatesDocumentAsync()
: await _templatesManager.LoadTemplatesDocumentAsync();
var checkedContentItems = templatesDocument.Templates.Where(x => itemIds.Contains(x.Key));

switch (options.BulkAction)
{
case ContentsBulkAction.None:
break;
case ContentsBulkAction.Remove:
foreach (var item in checkedContentItems)
case ContentsBulkAction.None:
break;
case ContentsBulkAction.Remove:
if (itemIds != null)
{
var templatesDocument = options.AdminTemplates
? await _adminTemplatesManager.LoadTemplatesDocumentAsync()
: await _templatesManager.LoadTemplatesDocumentAsync();
var checkedContentItemIds = templatesDocument.Templates.Keys
.Intersect(itemIds, StringComparer.OrdinalIgnoreCase);

foreach (var id in checkedContentItemIds)
{
await (options.AdminTemplates
? _adminTemplatesManager.RemoveTemplateAsync(item.Key)
: _templatesManager.RemoveTemplateAsync(item.Key));
? _adminTemplatesManager.RemoveTemplateAsync(id)
: _templatesManager.RemoveTemplateAsync(id));
}

await _notifier.SuccessAsync(H["Templates successfully removed."]);
break;
default:
return BadRequest();
}
}
}

if (options.AdminTemplates)
{
return RedirectToAction(nameof(Admin));
}
else
{
return RedirectToAction(nameof(Index));
break;
default:
return BadRequest();
}

return RedirectToAction(options.AdminTemplates ? nameof(Admin) : nameof(Index));
}

private IActionResult RedirectToReturnUrlOrIndex(string returnUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OrchardCore.Templates.Models;

public class TemplatesDocument : Document
{
public Dictionary<string, Template> Templates { get; set; } = new Dictionary<string, Template>(StringComparer.OrdinalIgnoreCase);
public Dictionary<string, Template> Templates { get; init; } = new(StringComparer.OrdinalIgnoreCase);
}

public class Template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ public async Task<ShapeBinding> GetShapeBindingAsync(string shapeType)
return null;
}

if (_localTemplates?.Templates?.Count != 0)
if (_localTemplates?.Templates?.TryGetValue(shapeType, out var localTemplate) == true)
{
if (_localTemplates.Templates.TryGetValue(shapeType, out var localTemplate))
{
return BuildShapeBinding(shapeType, localTemplate);
}
return BuildShapeBinding(shapeType, localTemplate);
}

_templatesDocument ??= await _templatesManager.GetTemplatesDocumentAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.Json.Serialization;
using Microsoft.Extensions.Options;
using OrchardCore.Json;
using OrchardCore.Json.Extensions;

namespace OrchardCore.Extensions;

Expand All @@ -16,18 +17,7 @@ public DocumentJsonSerializerOptionsConfiguration(IOptions<JsonDerivedTypesOptio

public void Configure(DocumentJsonSerializerOptions options)
{
options.SerializerOptions.DefaultIgnoreCondition = JOptions.Base.DefaultIgnoreCondition;
options.SerializerOptions.ReferenceHandler = JOptions.Base.ReferenceHandler;
options.SerializerOptions.ReadCommentHandling = JOptions.Base.ReadCommentHandling;
options.SerializerOptions.PropertyNameCaseInsensitive = JOptions.Base.PropertyNameCaseInsensitive;
options.SerializerOptions.AllowTrailingCommas = JOptions.Base.AllowTrailingCommas;
options.SerializerOptions.WriteIndented = JOptions.Base.WriteIndented;

options.SerializerOptions.Merge(JOptions.Default);
options.SerializerOptions.TypeInfoResolverChain.Add(new PolymorphicJsonTypeInfoResolver(_derivedTypesOptions));

foreach (var converter in JOptions.KnownConverters)
{
options.SerializerOptions.Converters.Add(converter);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static JsonSerializerOptions Merge(this JsonSerializerOptions destination
destination.PropertyNamingPolicy = source.PropertyNamingPolicy;
destination.Encoder = source.Encoder;
destination.TypeInfoResolver = source.TypeInfoResolver;
destination.PreferredObjectCreationHandling = source.PreferredObjectCreationHandling;

foreach (var resolver in source.TypeInfoResolverChain)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public IDocumentStore DocumentStore

public async Task<TDocument> GetOrCreateMutableAsync(Func<Task<TDocument>> factoryAsync = null)
{
TDocument document = null;
TDocument document;

if (!_isVolatile)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace OrchardCore.Queries.Core.Models;

public sealed class QueriesDocument : Document
{
public Dictionary<string, Query> Queries { get; set; } = new(StringComparer.OrdinalIgnoreCase);
public Dictionary<string, Query> Queries { get; init; } = new(StringComparer.OrdinalIgnoreCase);
}

0 comments on commit 5278abf

Please sign in to comment.