-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #476 from Strongminds/release/11.4.2
Release/11.4.2
- Loading branch information
Showing
286 changed files
with
5,311 additions
and
1,426 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
...tructure.Services/Caching/IObjectCache.cs → Core.Abstractions/Caching/IObjectCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Core.Abstractions.Extensions; | ||
|
||
namespace Core.Abstractions.Types | ||
{ | ||
public class EnumMap<TLeft, TRight> | ||
where TLeft : Enum | ||
where TRight : Enum | ||
{ | ||
private readonly IReadOnlyDictionary<TLeft, TRight> _leftToRightMap; | ||
private readonly IReadOnlyDictionary<TRight, TLeft> _rightToLeftMap; | ||
|
||
public EnumMap(params (TLeft left, TRight right)[] mappings) | ||
{ | ||
_leftToRightMap = mappings | ||
.ToDictionary(x => x.left, x => x.right) | ||
.AsReadOnly(); | ||
|
||
_rightToLeftMap = _leftToRightMap | ||
.ToDictionary(kvp => kvp.Value, kvp => kvp.Key) | ||
.AsReadOnly(); | ||
} | ||
|
||
public TRight FromLeftToRight(TLeft value) | ||
{ | ||
return _leftToRightMap.TryGetValue(value, out var result) | ||
? result | ||
: throw new ArgumentException($@"Unmapped 'Left'->'Right':{value:G}", nameof(value)); | ||
} | ||
|
||
public TLeft FromRightToLeft(TRight value) | ||
{ | ||
return _rightToLeftMap.TryGetValue(value, out var result) | ||
? result | ||
: throw new ArgumentException($@"Unmapped 'Right'->'Left' value:{value:G}", nameof(value)); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Core.ApplicationServices/Authorization/CachingUserContextFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Core.ApplicationServices/Authorization/ResourcePermissionsResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Core.Abstractions.Types; | ||
using Core.DomainModel; | ||
|
||
namespace Core.ApplicationServices.Authorization | ||
{ | ||
public class ResourcePermissionsResult | ||
{ | ||
private static readonly ResourcePermissionsResult Empty = new(false, false, false); | ||
|
||
public bool Read { get; } | ||
public bool Modify { get; } | ||
public bool Delete { get; } | ||
|
||
public ResourcePermissionsResult(bool read, bool modify, bool delete) | ||
{ | ||
Read = read; | ||
Modify = modify; | ||
Delete = delete; | ||
} | ||
|
||
public static Result<ResourcePermissionsResult, OperationError> FromResolutionResult<T>( | ||
Result<T, OperationError> getEntityResult, | ||
IAuthorizationContext authorizationContext) where T : IEntity | ||
{ | ||
return getEntityResult | ||
.Select(entity => new ResourcePermissionsResult(true, authorizationContext.AllowModify(entity), authorizationContext.AllowDelete(entity))) | ||
.Match<Result<ResourcePermissionsResult, OperationError>> | ||
( | ||
result => result, | ||
error => error.FailureType == OperationFailure.Forbidden ? Empty : error | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Core.ApplicationServices/Messages/IPublicMessagesService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Core.Abstractions.Types; | ||
using Core.ApplicationServices.Authorization; | ||
using Core.ApplicationServices.Model.Messages; | ||
|
||
namespace Core.ApplicationServices.Messages | ||
{ | ||
public interface IPublicMessagesService | ||
{ | ||
ResourcePermissionsResult GetPermissions(); | ||
PublicMessages Read(); | ||
Result<PublicMessages, OperationError> Write(WritePublicMessagesParams parameters); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
Core.ApplicationServices/Messages/PublicMessagesService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Core.Abstractions.Types; | ||
using Core.ApplicationServices.Authorization; | ||
using Core.ApplicationServices.Model.Messages; | ||
using Core.ApplicationServices.Model.Shared; | ||
using Core.DomainModel; | ||
using Core.DomainServices; | ||
using Serilog; | ||
|
||
namespace Core.ApplicationServices.Messages | ||
{ | ||
public class PublicMessagesService : IPublicMessagesService | ||
{ | ||
private readonly IGenericRepository<Text> _repository; | ||
private readonly IOrganizationalUserContext _organizationalUserContext; | ||
private readonly ILogger _logger; | ||
|
||
public PublicMessagesService( | ||
IGenericRepository<Text> repository, | ||
IOrganizationalUserContext organizationalUserContext, | ||
ILogger logger) | ||
{ | ||
_repository = repository; | ||
_organizationalUserContext = organizationalUserContext; | ||
_logger = logger; | ||
} | ||
|
||
public ResourcePermissionsResult GetPermissions() | ||
{ | ||
var allowModify = _organizationalUserContext.IsGlobalAdmin(); | ||
return new ResourcePermissionsResult(true, allowModify, false); | ||
} | ||
|
||
public PublicMessages Read() | ||
{ | ||
var texts = GetTextsLookup(); | ||
return MapPublicMessages(texts); | ||
} | ||
|
||
private PublicMessages MapPublicMessages(IReadOnlyDictionary<int, Text> texts) | ||
{ | ||
return new PublicMessages( | ||
MapText(texts, Text.SectionIds.About), | ||
MapText(texts, Text.SectionIds.Guides), | ||
MapText(texts, Text.SectionIds.StatusMessages), | ||
MapText(texts, Text.SectionIds.Misc), | ||
MapText(texts, Text.SectionIds.ContactInfo) | ||
); | ||
} | ||
|
||
public Result<PublicMessages, OperationError> Write(WritePublicMessagesParams parameters) | ||
{ | ||
if (!GetPermissions().Modify) | ||
{ | ||
return new OperationError(OperationFailure.Forbidden); | ||
} | ||
var texts = GetTextsLookup(); | ||
WriteChange(parameters.About, Text.SectionIds.About, texts); | ||
WriteChange(parameters.ContactInfo, Text.SectionIds.ContactInfo, texts); | ||
WriteChange(parameters.Guides, Text.SectionIds.Guides, texts); | ||
WriteChange(parameters.Misc, Text.SectionIds.Misc, texts); | ||
WriteChange(parameters.StatusMessages, Text.SectionIds.StatusMessages, texts); | ||
_repository.Save(); | ||
|
||
return MapPublicMessages(texts); | ||
} | ||
|
||
private void WriteChange(OptionalValueChange<string> change, int textId, Dictionary<int, Text> texts) | ||
{ | ||
if (change.HasChange) | ||
{ | ||
if (texts.TryGetValue(textId, out var text)) | ||
{ | ||
text.Value = change.NewValue; | ||
} | ||
else | ||
{ | ||
_logger.Error("Missing text id for the front page {textId}. Not able to change unknown text", textId); | ||
} | ||
} | ||
} | ||
|
||
private Dictionary<int, Text> GetTextsLookup() | ||
{ | ||
return _repository.AsQueryable().ToDictionary(x => x.Id, x => x); | ||
} | ||
|
||
private string MapText(IReadOnlyDictionary<int, Text> textMap, int textId) | ||
{ | ||
if (textMap.TryGetValue(textId, out var text)) | ||
{ | ||
return text.Value ?? string.Empty; | ||
} | ||
|
||
_logger.Error("Missing text id for the front page {textId}. Returning empty text", textId); | ||
return string.Empty; | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...cationServices/Model/EventHandler/ClearCacheOnAdministrativeAccessRightsChangedHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.