Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: or-1876 use key pollicy i.o. securityservice ti verify wether a … #1138

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using System.Threading.Tasks;
using Handling;
using Infrastructure.Authorization;
using Handling.Authorization;
using Infrastructure.Commands;
using Infrastructure.Configuration;
using Infrastructure.Domain;
Expand All @@ -14,16 +14,13 @@ public class AddOrganisationKeyCommandHandler :
ICommandEnvelopeHandler<AddOrganisationKey>
{
private readonly IOrganisationRegistryConfiguration _organisationRegistryConfiguration;
private readonly ISecurityService _securityService;

public AddOrganisationKeyCommandHandler(
ILogger<AddOrganisationKeyCommandHandler> logger,
ISession session,
IOrganisationRegistryConfiguration organisationRegistryConfiguration,
ISecurityService securityService) : base(logger, session)
IOrganisationRegistryConfiguration organisationRegistryConfiguration) : base(logger, session)
{
_organisationRegistryConfiguration = organisationRegistryConfiguration;
_securityService = securityService;
}

public Task Handle(ICommandEnvelope<AddOrganisationKey> envelope)
Expand All @@ -41,6 +38,9 @@ public Task Handle(ICommandEnvelope<AddOrganisationKey> envelope)
keyType,
envelope.Command.KeyValue,
new Period(new ValidFrom(envelope.Command.ValidFrom), new ValidTo(envelope.Command.ValidTo)),
keyTypeId => _securityService.CanUseKeyType(envelope.User, keyTypeId));
keyTypeId => new KeyPolicy(
organisation.State.OvoNumber,
_organisationRegistryConfiguration,
keyTypeId).Check(envelope.User).IsSuccessful);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using System.Threading.Tasks;
using Handling;
using Infrastructure.Authorization;
using Handling.Authorization;
using Infrastructure.Commands;
using Infrastructure.Configuration;
using Infrastructure.Domain;
Expand All @@ -14,32 +14,33 @@ public class UpdateOrganisationKeyCommandHandler :
ICommandEnvelopeHandler<UpdateOrganisationKey>
{
private readonly IOrganisationRegistryConfiguration _organisationRegistryConfiguration;
private readonly ISecurityService _securityService;

public UpdateOrganisationKeyCommandHandler(
ILogger<UpdateOrganisationKeyCommandHandler> logger,
ISession session,
IOrganisationRegistryConfiguration organisationRegistryConfiguration,
ISecurityService securityService) : base(logger, session)
IOrganisationRegistryConfiguration organisationRegistryConfiguration) : base(logger, session)
{
_organisationRegistryConfiguration = organisationRegistryConfiguration;
_securityService = securityService;
}

public Task Handle(ICommandEnvelope<UpdateOrganisationKey> envelope)
=> UpdateHandler<Organisation>.For(envelope.Command, envelope.User, Session)
.WithKeyPolicy(_organisationRegistryConfiguration, envelope.Command)
.Handle(session =>
{
var organisation = session.Get<Organisation>(envelope.Command.OrganisationId);
.Handle(
session =>
{
var organisation = session.Get<Organisation>(envelope.Command.OrganisationId);

var keyType = session.Get<KeyType>(envelope.Command.KeyTypeId);
var keyType = session.Get<KeyType>(envelope.Command.KeyTypeId);

organisation.UpdateKey(
envelope.Command.OrganisationKeyId,
keyType,
envelope.Command.Value,
new Period(new ValidFrom(envelope.Command.ValidFrom), new ValidTo(envelope.Command.ValidTo)),
keyTypeId => _securityService.CanUseKeyType(envelope.User, keyTypeId));
});
organisation.UpdateKey(
envelope.Command.OrganisationKeyId,
keyType,
envelope.Command.Value,
new Period(new ValidFrom(envelope.Command.ValidFrom), new ValidTo(envelope.Command.ValidTo)),
keyTypeId => new KeyPolicy(
organisation.State.OvoNumber,
_organisationRegistryConfiguration,
keyTypeId).Check(envelope.User).IsSuccessful);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ protected override AddOrganisationKeyCommandHandler BuildHandler(ISession sessio
=> new(
new Mock<ILogger<AddOrganisationKeyCommandHandler>>().Object,
session,
new OrganisationRegistryConfigurationStub(),
_securityServiceMock.Object);
new OrganisationRegistryConfigurationStub());

private IEvent[] Events
=> new IEvent[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ protected override AddOrganisationKeyCommandHandler BuildHandler(ISession sessio
=> new(
new Mock<ILogger<AddOrganisationKeyCommandHandler>>().Object,
session,
Mock.Of<IOrganisationRegistryConfiguration>(),
_securityServiceMock.Object);
Mock.Of<IOrganisationRegistryConfiguration>());

private IEvent[] Events
=> new IEvent[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ protected override UpdateOrganisationKeyCommandHandler BuildHandler(ISession ses
return new UpdateOrganisationKeyCommandHandler(
new Mock<ILogger<UpdateOrganisationKeyCommandHandler>>().Object,
session,
Mock.Of<IOrganisationRegistryConfiguration>(),
securityServiceMock.Object);
Mock.Of<IOrganisationRegistryConfiguration>());
}

private IEvent[] Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ protected override UpdateOrganisationKeyCommandHandler BuildHandler(ISession ses
=> new(
new Mock<ILogger<UpdateOrganisationKeyCommandHandler>>().Object,
session,
Mock.Of<IOrganisationRegistryConfiguration>(),
_securityServiceMock.Object);
Mock.Of<IOrganisationRegistryConfiguration>());

private IEvent[] Events
=> new IEvent[]
Expand Down
Loading