Skip to content

Commit 9822430

Browse files
Returns the list of patch operations in the "RepresentationUpdatedEvent"
1 parent 26d27c7 commit 9822430

7 files changed

Lines changed: 61 additions & 13 deletions

File tree

src/Scim/SimpleIdServer.Scim/Api/BaseApiController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ protected async Task<IActionResult> InternalUpdate(string prefix, string id, Rep
446446
if (!_options.IsFullRepresentationReturned)
447447
{
448448
var content = representation.ToResponse(location, true, mergeExtensionAttributes: _options.MergeExtensionAttributes);
449-
if (IsPublishEvtsEnabled) await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), content, _options.IncludeToken ? Request.GetToken() : string.Empty));
449+
if (IsPublishEvtsEnabled) await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), content, _options.IncludeToken ? Request.GetToken() : string.Empty, updateResult.Result.PatchOperations));
450450
return BuildHTTPResult(HttpStatusCode.OK, location, representation.Version, content);
451451
}
452452
else
@@ -455,7 +455,7 @@ protected async Task<IActionResult> InternalUpdate(string prefix, string id, Rep
455455
representation = getRepresentationResult.Result;
456456
await _attributeReferenceEnricher.Enrich(_resourceType, new List<SCIMRepresentation> { representation }, _uriProvider.GetAbsoluteUriWithVirtualPath());
457457
var content = representation.ToResponse(location, true, mergeExtensionAttributes: _options.MergeExtensionAttributes);
458-
if (IsPublishEvtsEnabled) await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), content, _options.IncludeToken ? Request.GetToken() : string.Empty));
458+
if (IsPublishEvtsEnabled) await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), content, _options.IncludeToken ? Request.GetToken() : string.Empty, updateResult.Result.PatchOperations));
459459
return BuildHTTPResult(HttpStatusCode.OK, location, representation.Version, content);
460460
}
461461
}
@@ -520,7 +520,7 @@ protected async Task<IActionResult> InternalPatch(string prefix, string id, Patc
520520
{
521521
var content = representation.ToResponse(location, true, mergeExtensionAttributes: _options.MergeExtensionAttributes);
522522
if (IsPublishEvtsEnabled)
523-
await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), content, _options.IncludeToken ? Request.GetToken() : string.Empty));
523+
await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), content, _options.IncludeToken ? Request.GetToken() : string.Empty, patchRes.Result.PatchOperations));
524524

525525
return BuildHTTPResult(HttpStatusCode.OK, location, representation.Version, content);
526526
}
@@ -530,7 +530,7 @@ protected async Task<IActionResult> InternalPatch(string prefix, string id, Patc
530530
representation = getRepresentationResult.Result;
531531
await _attributeReferenceEnricher.Enrich(_resourceType, new List<SCIMRepresentation> { representation }, _uriProvider.GetAbsoluteUriWithVirtualPath());
532532
var content = representation.ToResponse(location, true, mergeExtensionAttributes: _options.MergeExtensionAttributes);
533-
if (IsPublishEvtsEnabled) await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), content, _options.IncludeToken ? Request.GetToken() : string.Empty));
533+
if (IsPublishEvtsEnabled) await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), content, _options.IncludeToken ? Request.GetToken() : string.Empty, patchRes.Result.PatchOperations));
534534
return BuildHTTPResult(HttpStatusCode.OK, location, representation.Version, content);
535535
}
536536
}

src/Scim/SimpleIdServer.Scim/Commands/Handlers/PatchRepresentationCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private async Task<GenericResult<PatchRepresentationResult>> UpdateRepresentatio
8282
}
8383

8484
existingRepresentation.Apply(references, patchResultLst);
85-
return GenericResult<PatchRepresentationResult>.Ok(PatchRepresentationResult.Ok(existingRepresentation));
85+
return GenericResult<PatchRepresentationResult>.Ok(PatchRepresentationResult.Ok(existingRepresentation, patchResultLst));
8686
}
8787

8888
private void CheckParameter(PatchRepresentationParameter patchRepresentation)

src/Scim/SimpleIdServer.Scim/Commands/Handlers/ReplaceRepresentationCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async virtual Task<GenericResult<ReplaceRepresentationResult>> Handle(Rep
8181
}
8282

8383
existingRepresentation.Apply(references, patchOperations);
84-
return GenericResult<ReplaceRepresentationResult>.Ok(ReplaceRepresentationResult.Ok(existingRepresentation));
84+
return GenericResult<ReplaceRepresentationResult>.Ok(ReplaceRepresentationResult.Ok(existingRepresentation, patchOperations));
8585
}
8686

8787
private async Task<(SCIMRepresentation, SCIMSchema)> Validate(ReplaceRepresentationCommand replaceRepresentationCommand)

src/Scim/SimpleIdServer.Scim/Commands/PatchRepresentationCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using SimpleIdServer.Scim.Domains;
44
using SimpleIdServer.Scim.DTOs;
55
using SimpleIdServer.Scim.Infrastructure;
6+
using System.Collections.Generic;
67

78
namespace SimpleIdServer.Scim.Commands
89
{
@@ -28,15 +29,16 @@ public class PatchRepresentationResult
2829
{
2930
public bool IsPatched { get; private set; }
3031
public SCIMRepresentation Representation { get; private set; }
32+
public List<SCIMPatchResult> PatchOperations { get; private set; } = new List<SCIMPatchResult>();
3133

3234
public static PatchRepresentationResult NoPatch()
3335
{
3436
return new PatchRepresentationResult { IsPatched = false };
3537
}
3638

37-
public static PatchRepresentationResult Ok(SCIMRepresentation representation)
39+
public static PatchRepresentationResult Ok(SCIMRepresentation representation, List<SCIMPatchResult> patchOperations)
3840
{
39-
return new PatchRepresentationResult { IsPatched = true, Representation = representation };
41+
return new PatchRepresentationResult { IsPatched = true, Representation = representation, PatchOperations = patchOperations };
4042
}
4143
}
4244
}

src/Scim/SimpleIdServer.Scim/Commands/ReplaceRepresentationCommand.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using SimpleIdServer.Scim.Domains;
44
using SimpleIdServer.Scim.DTOs;
55
using SimpleIdServer.Scim.Infrastructure;
6+
using System.Collections.Generic;
67

78
namespace SimpleIdServer.Scim.Commands
89
{
@@ -28,25 +29,26 @@ public class ReplaceRepresentationResult
2829
{
2930
public bool IsReplaced { get; private set; }
3031
public SCIMRepresentation Representation { get; private set; }
32+
public List<SCIMPatchResult> PatchOperations { get; private set; } = new List<SCIMPatchResult>();
3133

3234
public ReplaceRepresentationResult()
3335
{
34-
3536
}
3637

37-
public ReplaceRepresentationResult(SCIMRepresentation representation)
38+
public ReplaceRepresentationResult(SCIMRepresentation representation, List<SCIMPatchResult> patchOperations)
3839
{
3940
Representation = representation;
41+
PatchOperations = patchOperations;
4042
}
4143

4244
public static ReplaceRepresentationResult NoReplacement()
4345
{
4446
return new ReplaceRepresentationResult { IsReplaced = false };
4547
}
4648

47-
public static ReplaceRepresentationResult Ok(SCIMRepresentation representation)
49+
public static ReplaceRepresentationResult Ok(SCIMRepresentation representation, List<SCIMPatchResult> patchOperations)
4850
{
49-
return new ReplaceRepresentationResult { IsReplaced = true, Representation = representation };
51+
return new ReplaceRepresentationResult { IsReplaced = true, Representation = representation, PatchOperations = patchOperations };
5052
}
5153
}
5254
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) SimpleIdServer. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
using SimpleIdServer.Scim.Domains;
4+
using SimpleIdServer.Scim.DTOs;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
9+
namespace SimpleIdServer.Scim.ExternalEvents;
10+
11+
public class PatchAttributeOperation
12+
{
13+
public string Path { get; set; }
14+
public SCIMPatchOperations Operation { get; set; }
15+
public SCIMSchemaAttributeTypes Type { get; set; }
16+
public string ValueString { get; set; }
17+
public bool? ValueBoolean { get; set; }
18+
public int? ValueInteger { get; set; }
19+
public DateTime? ValueDateTime { get; set; }
20+
public string ValueReference { get; set; }
21+
public decimal? ValueDecimal { get; set; }
22+
public string ValueBinary { get; set; }
23+
24+
public static List<PatchAttributeOperation> Transform(List<SCIMPatchResult> patchOperations)
25+
{
26+
return patchOperations.Select(o => new PatchAttributeOperation
27+
{
28+
Operation = o.Operation,
29+
Path = o.Path,
30+
Type = o.Attr.SchemaAttribute.Type,
31+
ValueBinary = o.Attr.ValueBinary,
32+
ValueBoolean = o.Attr.ValueBoolean,
33+
ValueDateTime = o.Attr.ValueDateTime,
34+
ValueDecimal = o.Attr.ValueDecimal,
35+
ValueInteger = o.Attr.ValueInteger,
36+
ValueReference = o.Attr.ValueReference,
37+
ValueString = o.Attr.ValueString
38+
}).ToList();
39+
}
40+
}

src/Scim/SimpleIdServer.Scim/ExternalEvents/RepresentationUpdatedEvent.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) SimpleIdServer. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33
using Newtonsoft.Json.Linq;
4+
using SimpleIdServer.Scim.DTOs;
5+
using System.Collections.Generic;
46

57
namespace SimpleIdServer.Scim.ExternalEvents
68
{
@@ -11,11 +13,13 @@ public RepresentationUpdatedEvent()
1113

1214
}
1315

14-
public RepresentationUpdatedEvent(string id, int version, string resourceType, JObject representation, string token) : base(id, version, resourceType, representation)
16+
public RepresentationUpdatedEvent(string id, int version, string resourceType, JObject representation, string token, List<SCIMPatchResult> patchOperations) : base(id, version, resourceType, representation)
1517
{
1618
Token = token;
19+
PatchOperations = PatchAttributeOperation.Transform(patchOperations);
1720
}
1821

1922
public string Token { get; set; }
23+
public List<PatchAttributeOperation> PatchOperations { get; set; }
2024
}
2125
}

0 commit comments

Comments
 (0)