Skip to content

Commit a791445

Browse files
Ticket #929 : Don't publish events
1 parent 6c0ebe5 commit a791445

9 files changed

Lines changed: 38 additions & 16 deletions

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ protected async Task<IActionResult> InternalAdd(string prefix, RepresentationPar
349349
_logger.LogInformation(Global.AddResource);
350350
try
351351
{
352-
var command = new AddRepresentationCommand(_resourceType, jobj, _uriProvider.GetAbsoluteUriWithVirtualPath(), realm);
352+
var command = new AddRepresentationCommand(_resourceType, jobj, _uriProvider.GetAbsoluteUriWithVirtualPath(), realm, IsPublishEvtsEnabled);
353353
var addRepresentationResult = await _addRepresentationCommandHandler.Handle(command);
354354
if (addRepresentationResult.HasError) return this.BuildError(addRepresentationResult);
355355
var representation = addRepresentationResult.Result;
@@ -398,13 +398,17 @@ protected async Task<IActionResult> InternalDelete(string prefix, string id, Can
398398
_logger.LogInformation(string.Format(Global.DeleteResource, id));
399399
try
400400
{
401-
var getRepresentationResult = await _deleteRepresentationCommandHandler.Handle(new DeleteRepresentationCommand(id, _resourceType, _uriProvider.GetAbsoluteUriWithVirtualPath(), realm));
401+
var getRepresentationResult = await _deleteRepresentationCommandHandler.Handle(new DeleteRepresentationCommand(id, _resourceType, _uriProvider.GetAbsoluteUriWithVirtualPath(), realm, IsPublishEvtsEnabled));
402402
if (getRepresentationResult.HasError) return this.BuildError(getRepresentationResult);
403403
var representation = getRepresentationResult.Result;
404404
representation.ApplyEmptyArray();
405405
var location = GetLocation(realm, representation);
406406
var content = representation.ToResponse(location, false, mergeExtensionAttributes: _options.MergeExtensionAttributes);
407-
if (IsPublishEvtsEnabled) await _busControl.Publish(new RepresentationRemovedEvent(id, representation.Version, GetResourceType(_resourceType), realm, content, _options.IncludeToken ? Request.GetToken() : string.Empty));
407+
if (IsPublishEvtsEnabled)
408+
{
409+
await _busControl.Publish(new RepresentationRemovedEvent(id, representation.Version, GetResourceType(_resourceType), realm, content, _options.IncludeToken ? Request.GetToken() : string.Empty));
410+
}
411+
408412
return new StatusCodeResult((int)HttpStatusCode.NoContent);
409413
}
410414
catch (SCIMSchemaViolatedException ex)
@@ -442,7 +446,7 @@ protected async Task<IActionResult> InternalUpdate(string prefix, string id, Rep
442446
_logger.LogInformation(Global.UpdateResource, id);
443447
try
444448
{
445-
var updateResult = await _replaceRepresentationCommandHandler.Handle(new ReplaceRepresentationCommand(id, _resourceType, representationParameter, _uriProvider.GetAbsoluteUriWithVirtualPath(), realm));
449+
var updateResult = await _replaceRepresentationCommandHandler.Handle(new ReplaceRepresentationCommand(id, _resourceType, representationParameter, _uriProvider.GetAbsoluteUriWithVirtualPath(), realm, IsPublishEvtsEnabled));
446450
if (updateResult.HasError) return this.BuildError(updateResult);
447451
if (!updateResult.Result.IsReplaced) return NoContent();
448452
var representation = updateResult.Result.Representation;
@@ -515,7 +519,7 @@ protected async Task<IActionResult> InternalPatch(string prefix, string id, Patc
515519
_logger.LogInformation(string.Format(Global.PatchResource, id, patchRepresentation == null ? string.Empty : JsonSerializer.Serialize(patchRepresentation)));
516520
try
517521
{
518-
var patchRes = await _patchRepresentationCommandHandler.Handle(new PatchRepresentationCommand(id, ResourceType, patchRepresentation, _uriProvider.GetAbsoluteUriWithVirtualPath(), realm));
522+
var patchRes = await _patchRepresentationCommandHandler.Handle(new PatchRepresentationCommand(id, ResourceType, patchRepresentation, _uriProvider.GetAbsoluteUriWithVirtualPath(), realm, IsPublishEvtsEnabled));
519523
if (patchRes.HasError) return this.BuildError(patchRes);
520524
var patchResult = patchRes.Result;
521525
if (!patchResult.IsPatched) return NoContent();
@@ -525,9 +529,7 @@ protected async Task<IActionResult> InternalPatch(string prefix, string id, Patc
525529
if(!_options.IsFullRepresentationReturned)
526530
{
527531
var content = representation.ToResponse(location, true, mergeExtensionAttributes: _options.MergeExtensionAttributes);
528-
if (IsPublishEvtsEnabled)
529-
await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), realm, content, _options.IncludeToken ? Request.GetToken() : string.Empty, patchRes.Result.PatchOperations));
530-
532+
if (IsPublishEvtsEnabled) await _busControl.Publish(new RepresentationUpdatedEvent(representation.Id, representation.Version, GetResourceType(_resourceType), realm, content, _options.IncludeToken ? Request.GetToken() : string.Empty, patchRes.Result.PatchOperations));
531533
return BuildHTTPResult(HttpStatusCode.OK, location, representation.Version, content);
532534
}
533535
else

src/Scim/SimpleIdServer.Scim/Commands/AddRepresentationCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ namespace SimpleIdServer.Scim.Commands
88
{
99
public class AddRepresentationCommand : ISCIMCommand<SCIMRepresentation>
1010
{
11-
public AddRepresentationCommand(string resourceType, RepresentationParameter representation, string location, string realm)
11+
public AddRepresentationCommand(string resourceType, RepresentationParameter representation, string location, string realm, bool isPublishEvtsEnabled)
1212
{
1313
ResourceType = resourceType;
1414
Representation = representation;
1515
Location = location;
1616
Realm = realm;
17+
IsPublishEvtsEnabled = isPublishEvtsEnabled;
1718
}
1819

1920
public string ResourceType { get; set; }
2021
public RepresentationParameter Representation { get; }
2122
public string Location { get; }
2223
public string Realm { get; set; }
24+
public bool IsPublishEvtsEnabled { get; set; }
2325
}
2426
}

src/Scim/SimpleIdServer.Scim/Commands/DeleteRepresentationCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ namespace SimpleIdServer.Scim.Commands
77
{
88
public class DeleteRepresentationCommand : ISCIMCommand<SCIMRepresentation>
99
{
10-
public DeleteRepresentationCommand(string id, string resourceType, string location, string realm)
10+
public DeleteRepresentationCommand(string id, string resourceType, string location, string realm, bool isPublishEvtsEnabled)
1111
{
1212
Id = id;
1313
ResourceType = resourceType;
1414
Location = location;
1515
Realm = realm;
16+
IsPublishEvtsEnabled = isPublishEvtsEnabled;
1617
}
1718

1819
public string Id { get; set; }
1920
public string ResourceType { get; set; }
2021
public string Location { get; }
2122
public string Realm { get; set; }
23+
public bool IsPublishEvtsEnabled { get; set; }
2224
}
2325
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ public async virtual Task<GenericResult<SCIMRepresentation>> Handle(AddRepresent
8888
}
8989

9090
await transaction.Commit().ConfigureAwait(false);
91-
await NotifyAllReferences(references).ConfigureAwait(false);
91+
if(addRepresentationCommand.IsPublishEvtsEnabled)
92+
{
93+
await NotifyAllReferences(references).ConfigureAwait(false);
94+
}
9295
}
9396

9497
scimRepresentation.Apply(references, patchOperations);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public virtual async Task<GenericResult<SCIMRepresentation>> Handle(DeleteRepres
5555

5656
await _scimRepresentationCommandRepository.Delete(representation).ConfigureAwait(false);
5757
await transaction.Commit().ConfigureAwait(false);
58-
await NotifyAllReferences(references).ConfigureAwait(false);
58+
if(request.IsPublishEvtsEnabled)
59+
{
60+
await NotifyAllReferences(references).ConfigureAwait(false);
61+
}
5962
}
6063

6164
return GenericResult<SCIMRepresentation>.Ok(result);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ private async Task<GenericResult<PatchRepresentationResult>> UpdateRepresentatio
8383

8484
await _scimRepresentationCommandRepository.Update(existingRepresentation).ConfigureAwait(false);
8585
await transaction.Commit().ConfigureAwait(false);
86-
await NotifyAllReferences(references).ConfigureAwait(false);
86+
if(patchRepresentationCommand.IsPublishEvtsEnabled)
87+
{
88+
await NotifyAllReferences(references).ConfigureAwait(false);
89+
}
8790
}
8891

8992
existingRepresentation.Apply(references, patchResultLst);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ public async virtual Task<GenericResult<ReplaceRepresentationResult>> Handle(Rep
7676

7777
await _scimRepresentationCommandRepository.Update(existingRepresentation).ConfigureAwait(false);
7878
await transaction.Commit().ConfigureAwait(false);
79-
await NotifyAllReferences(references).ConfigureAwait(false);
79+
if(replaceRepresentationCommand.IsPublishEvtsEnabled)
80+
{
81+
await NotifyAllReferences(references).ConfigureAwait(false);
82+
}
8083
}
8184

8285
existingRepresentation.Apply(references, patchOperations);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ namespace SimpleIdServer.Scim.Commands
99
{
1010
public class PatchRepresentationCommand : ISCIMCommand<PatchRepresentationResult>
1111
{
12-
public PatchRepresentationCommand(string id, string resourceType, PatchRepresentationParameter patchRepresentation, string location, string realm)
12+
public PatchRepresentationCommand(string id, string resourceType, PatchRepresentationParameter patchRepresentation, string location, string realm, bool isPublishEvtsEnabled)
1313
{
1414
Id = id;
1515
ResourceType = resourceType;
1616
PatchRepresentation = patchRepresentation;
1717
Location = location;
1818
Realm = realm;
19+
IsPublishEvtsEnabled = isPublishEvtsEnabled;
1920
}
2021

2122
public string Id { get; private set; }
2223
public PatchRepresentationParameter PatchRepresentation { get; private set; }
2324
public string ResourceType { get; private set; }
2425
public string Location { get; }
2526
public string Realm { get; set; }
27+
public bool IsPublishEvtsEnabled { get; set; }
2628
}
2729

2830
public class PatchRepresentationResult

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ namespace SimpleIdServer.Scim.Commands
99
{
1010
public class ReplaceRepresentationCommand : ISCIMCommand<ReplaceRepresentationResult>
1111
{
12-
public ReplaceRepresentationCommand(string id, string resourceType, RepresentationParameter representation, string location, string realm)
12+
public ReplaceRepresentationCommand(string id, string resourceType, RepresentationParameter representation, string location, string realm, bool isPublishEvtsEnabled)
1313
{
1414
Id = id;
1515
ResourceType = resourceType;
1616
Representation = representation;
1717
Location = location;
1818
Realm = realm;
19+
IsPublishEvtsEnabled = isPublishEvtsEnabled;
1920
}
2021

2122
public string Id { get; private set; }
2223
public string ResourceType{ get; private set; }
2324
public RepresentationParameter Representation { get; private set; }
2425
public string Location { get; }
2526
public string Realm { get; set; }
27+
public bool IsPublishEvtsEnabled { get; set; }
2628
}
2729

2830
public class ReplaceRepresentationResult

0 commit comments

Comments
 (0)