Skip to content

Commit

Permalink
feat(webapi): Add flag for disabling SystemLabel reset (#1921)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## Related Issue(s)

- #1905 

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)
  • Loading branch information
oskogstad authored Feb 20, 2025
1 parent 5adda59 commit a5689f2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public static class Constants
public const string DisableAltinnEventsRequiresAdminScope =
"Disabling Altinn events requires service owner admin scope.";

public const string DisableSystemLabelResetRequiresAdminScope =
"Disabling SystemLabel reset requires service owner admin scope.";

public static readonly ImmutableArray<string> SupportedResourceTypes =
[
"GenericAccessResource",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using OneOf;
using Constants = Digdir.Domain.Dialogporten.Application.Common.Authorization.Constants;

namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Update;

Expand All @@ -29,6 +30,7 @@ public sealed class UpdateDialogCommand : IRequest<UpdateDialogResult>, IAltinnE
public Guid? IfMatchDialogRevision { get; set; }
public UpdateDialogDto Dto { get; set; } = null!;
public bool DisableAltinnEvents { get; set; }
public bool DisableSystemLabelReset { get; set; }
}

[GenerateOneOf]
Expand Down Expand Up @@ -66,6 +68,11 @@ public UpdateDialogCommandHandler(

public async Task<UpdateDialogResult> Handle(UpdateDialogCommand request, CancellationToken cancellationToken)
{
if (request.DisableSystemLabelReset && !_userResourceRegistry.IsCurrentUserServiceOwnerAdmin())
{
return new Forbidden(Constants.DisableSystemLabelResetRequiresAdminScope);
}

var resourceIds = await _userResourceRegistry.GetCurrentUserResourceIds(cancellationToken);

var dialog = await _db.Dialogs
Expand Down Expand Up @@ -164,7 +171,10 @@ public async Task<UpdateDialogResult> Handle(UpdateDialogCommand request, Cancel
return forbiddenResult;
}

UpdateLabel(dialog);
if (!request.DisableSystemLabelReset)
{
UpdateLabel(dialog);
}

var saveResult = await _unitOfWork
.EnableConcurrencyCheck(dialog, request.IfMatchDialogRevision)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ await errors.Match(
Id = req.DialogId,
IfMatchDialogRevision = req.IfMatchDialogRevision,
Dto = updateDialogDto,
DisableAltinnEvents = req.DisableAltinnEvents ?? false
DisableAltinnEvents = req.DisableAltinnEvents ?? false,
DisableSystemLabelReset = req.DisableSystemLabelReset ?? false
};

var result = await _sender.Send(updateDialogCommand, ct);
Expand Down Expand Up @@ -99,4 +100,7 @@ public sealed class CreateActivityRequest : ActivityDto

[HideFromDocs]
public bool? DisableAltinnEvents { get; init; }

[HideFromDocs]
public bool? DisableSystemLabelReset { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ await errors.Match(
Id = req.DialogId,
IfMatchDialogRevision = req.IfMatchDialogRevision,
Dto = updateDialogDto,
DisableAltinnEvents = req.DisableAltinnEvents ?? false
DisableAltinnEvents = req.DisableAltinnEvents ?? false,
DisableSystemLabelReset = req.DisableSystemLabelReset ?? false
};

var result = await _sender.Send(updateDialogCommand, ct);
Expand Down Expand Up @@ -97,4 +98,7 @@ public sealed class CreateTransmissionRequest : TransmissionDto

[HideFromDocs]
public bool? DisableAltinnEvents { get; init; }

[HideFromDocs]
public bool? DisableSystemLabelReset { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public async Task<IActionResult> Patch(
[FromHeader(Name = Constants.IfMatch)] Guid? etag,
[FromBody] JsonPatchDocument<UpdateDialogDto> patchDocument,
[OpenApiIgnore][FromQuery] bool? disableAltinnEvents,
[OpenApiIgnore][FromQuery] bool? disableSystemLabelReset,
CancellationToken ct)
{
var dialogQueryResult = await _sender.Send(new GetDialogQuery { DialogId = dialogId }, ct);
Expand All @@ -93,7 +94,8 @@ public async Task<IActionResult> Patch(
Id = dialogId,
IfMatchDialogRevision = etag,
Dto = updateDialogDto,
DisableAltinnEvents = disableAltinnEvents ?? false
DisableAltinnEvents = disableAltinnEvents ?? false,
DisableSystemLabelReset = disableSystemLabelReset ?? false
};

var result = await _sender.Send(command, ct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public override async Task HandleAsync(UpdateDialogRequest req, CancellationToke
Id = req.DialogId,
IfMatchDialogRevision = req.IfMatchDialogRevision,
Dto = req.Dto,
DisableAltinnEvents = req.DisableAltinnEvents ?? false
DisableAltinnEvents = req.DisableAltinnEvents ?? false,
DisableSystemLabelReset = req.DisableSystemLabelReset ?? false
};

var updateDialogResult = await _sender.Send(command, ct);
Expand Down Expand Up @@ -70,4 +71,7 @@ public sealed class UpdateDialogRequest

[HideFromDocs]
public bool? DisableAltinnEvents { get; init; }

[HideFromDocs]
public bool? DisableSystemLabelReset { get; init; }
}

0 comments on commit a5689f2

Please sign in to comment.