Skip to content

Commit 95dbeb8

Browse files
committed
Merge branch 'main' into clean-up-studio-toggleable-textfield
2 parents e446316 + c07d821 commit 95dbeb8

File tree

143 files changed

+2692
-867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+2692
-867
lines changed

backend/src/Designer/Controllers/AppDevelopmentController.cs

+27-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45
using System.Text.Json.Nodes;
56
using System.Threading;
67
using System.Threading.Tasks;
@@ -9,7 +10,6 @@
910
using Altinn.Studio.Designer.Events;
1011
using Altinn.Studio.Designer.Filters;
1112
using Altinn.Studio.Designer.Helpers;
12-
using Altinn.Studio.Designer.Infrastructure.GitRepository;
1313
using Altinn.Studio.Designer.Models;
1414
using Altinn.Studio.Designer.Models.Dto;
1515
using Altinn.Studio.Designer.Services.Interfaces;
@@ -32,7 +32,6 @@ public class AppDevelopmentController : Controller
3232
private readonly IAppDevelopmentService _appDevelopmentService;
3333
private readonly IRepository _repository;
3434
private readonly ISourceControl _sourceControl;
35-
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
3635
private readonly ApplicationInsightsSettings _applicationInsightsSettings;
3736
private readonly IMediator _mediator;
3837

@@ -43,15 +42,13 @@ public class AppDevelopmentController : Controller
4342
/// <param name="appDevelopmentService">The app development service</param>
4443
/// <param name="repositoryService">The application repository service</param>
4544
/// <param name="sourceControl">The source control service.</param>
46-
/// <param name="altinnGitRepositoryFactory"></param>
4745
/// <param name="applicationInsightsSettings">An <see cref="ApplicationInsightsSettings"/></param>
4846
/// <param name="mediator"></param>
49-
public AppDevelopmentController(IAppDevelopmentService appDevelopmentService, IRepository repositoryService, ISourceControl sourceControl, IAltinnGitRepositoryFactory altinnGitRepositoryFactory, ApplicationInsightsSettings applicationInsightsSettings, IMediator mediator)
47+
public AppDevelopmentController(IAppDevelopmentService appDevelopmentService, IRepository repositoryService, ISourceControl sourceControl, ApplicationInsightsSettings applicationInsightsSettings, IMediator mediator)
5048
{
5149
_appDevelopmentService = appDevelopmentService;
5250
_repository = repositoryService;
5351
_sourceControl = sourceControl;
54-
_altinnGitRepositoryFactory = altinnGitRepositoryFactory;
5552
_applicationInsightsSettings = applicationInsightsSettings;
5653
_mediator = mediator;
5754
}
@@ -123,8 +120,17 @@ public async Task<ActionResult> SaveFormLayout(string org, string app, [FromQuer
123120

124121
if (formLayoutPayload.ComponentIdsChange is not null && !string.IsNullOrEmpty(layoutSetName))
125122
{
126-
foreach (var componentIdChange in formLayoutPayload.ComponentIdsChange)
123+
foreach (var componentIdChange in formLayoutPayload.ComponentIdsChange.Where((componentIdChange) => componentIdChange.OldComponentId != componentIdChange.NewComponentId))
127124
{
125+
if (componentIdChange.NewComponentId == null)
126+
{
127+
await _mediator.Publish(new ComponentDeletedEvent
128+
{
129+
ComponentId = componentIdChange.OldComponentId,
130+
LayoutSetName = layoutSetName,
131+
EditingContext = editingContext
132+
}, cancellationToken);
133+
}
128134
await _mediator.Publish(new ComponentIdChangedEvent
129135
{
130136
OldComponentId = componentIdChange.OldComponentId,
@@ -159,16 +165,26 @@ await _mediator.Publish(new LayoutPageAddedEvent
159165
/// <param name="app">Application identifier which is unique within an organisation.</param>
160166
/// <param name="layoutSetName">The name of the layout set the specific layout belongs to</param>
161167
/// <param name="layoutName">The form layout to be deleted</param>
168+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
162169
/// <returns>A success message if the save was successful</returns>
163170
[HttpDelete]
164171
[Route("form-layout/{layoutName}")]
165-
public ActionResult DeleteFormLayout(string org, string app, [FromQuery] string layoutSetName, [FromRoute] string layoutName)
172+
public async Task<ActionResult> DeleteFormLayout(string org, string app, [FromQuery] string layoutSetName, [FromRoute] string layoutName, CancellationToken cancellationToken)
166173
{
167174
try
168175
{
169176
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
170177
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);
178+
179+
await _mediator.Publish(new LayoutPageDeletedEvent
180+
{
181+
EditingContext = editingContext,
182+
LayoutSetName = layoutSetName,
183+
LayoutName = layoutName,
184+
}, cancellationToken);
185+
171186
_appDevelopmentService.DeleteFormLayout(editingContext, layoutSetName, layoutName);
187+
172188
return Ok();
173189
}
174190
catch (FileNotFoundException exception)
@@ -402,13 +418,15 @@ public async Task<ActionResult> DeleteLayoutSet(string org, string app, [FromRou
402418
{
403419
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
404420
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);
405-
LayoutSets layoutSets = await _appDevelopmentService.DeleteLayoutSet(editingContext, layoutSetIdToUpdate, cancellationToken);
406421

407422
await _mediator.Publish(new LayoutSetDeletedEvent
408423
{
409424
EditingContext = editingContext,
410-
LayoutSetId = layoutSetIdToUpdate
425+
LayoutSetName = layoutSetIdToUpdate
411426
}, cancellationToken);
427+
428+
LayoutSets layoutSets = await _appDevelopmentService.DeleteLayoutSet(editingContext, layoutSetIdToUpdate, cancellationToken);
429+
412430
return Ok(layoutSets);
413431
}
414432

@@ -543,20 +561,6 @@ public ActionResult GetWidgetSettings(string org, string app)
543561
return Ok(widgetSettings);
544562
}
545563

546-
[HttpGet]
547-
[Route("option-list-ids")]
548-
public ActionResult GetOptionListIds(string org, string app)
549-
{
550-
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
551-
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
552-
string[] optionListIds = altinnAppGitRepository.GetOptionsListIds();
553-
if (optionListIds.Length == 0)
554-
{
555-
return NoContent();
556-
}
557-
return Ok(optionListIds);
558-
}
559-
560564
[HttpGet("app-version")]
561565
public VersionResponse GetAppVersion(string org, string app)
562566
{

backend/src/Designer/Controllers/ResourceAdminController.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public async Task<ActionResult<List<AvailableService>>> GetAltinn2LinkServices(s
487487
foreach (ServiceResource resource in allResources)
488488
{
489489
if (resource?.HasCompetentAuthority.Orgcode != null
490-
&& resource.ResourceReferences != null && resource.ResourceReferences.Exists(r => r.ReferenceType != null && r.ReferenceType.Equals(ReferenceType.ServiceCode))
490+
&& resource.ResourceReferences != null && resource.ResourceReferences.Exists(r => r.ReferenceType != null && r.ReferenceType.Equals(ResourceReferenceType.ServiceCode))
491491
&& resource.ResourceType == ResourceType.Altinn2Service)
492492
{
493493
AvailableService service = new AvailableService();
@@ -496,8 +496,8 @@ public async Task<ActionResult<List<AvailableService>>> GetAltinn2LinkServices(s
496496
service.ServiceName = resource.Title["nb"];
497497
}
498498

499-
service.ExternalServiceCode = resource.ResourceReferences.First(r => r.ReferenceType.Equals(ReferenceType.ServiceCode)).Reference;
500-
service.ExternalServiceEditionCode = Convert.ToInt32(resource.ResourceReferences.First(r => r.ReferenceType.Equals(ReferenceType.ServiceEditionCode)).Reference);
499+
service.ExternalServiceCode = resource.ResourceReferences.First(r => r.ReferenceType.Equals(ResourceReferenceType.ServiceCode)).Reference;
500+
service.ExternalServiceEditionCode = Convert.ToInt32(resource.ResourceReferences.First(r => r.ReferenceType.Equals(ResourceReferenceType.ServiceEditionCode)).Reference);
501501
service.ServiceOwnerCode = resource.HasCompetentAuthority.Orgcode;
502502
unfiltered.Add(service);
503503
}
@@ -551,7 +551,7 @@ private ValidationProblemDetails ValidateResource(ServiceResource resource)
551551

552552
if (resource.ResourceType == ResourceType.MaskinportenSchema)
553553
{
554-
if (resource.ResourceReferences == null || !resource.ResourceReferences.Any((x) => x.ReferenceType == ReferenceType.MaskinportenScope))
554+
if (resource.ResourceReferences == null || !resource.ResourceReferences.Any((x) => x.ReferenceType == ResourceReferenceType.MaskinportenScope))
555555
{
556556
ModelState.AddModelError($"{resource.Identifier}.resourceReferences", "resourceerror.missingmaskinportenscope");
557557
}
+3-25
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
1-
using System.Runtime.Serialization;
2-
31
namespace Altinn.Studio.Designer.Enums
42
{
5-
/// <summary>
6-
/// Enum for reference types of resources in the resource registry
7-
/// </summary>
83
public enum ReferenceType
94
{
10-
[EnumMember(Value = "Default")]
11-
Default = 0,
12-
13-
[EnumMember(Value = "Uri")]
14-
Uri = 1,
15-
16-
[EnumMember(Value = "DelegationSchemeId")]
17-
DelegationSchemeId = 2,
18-
19-
[EnumMember(Value = "MaskinportenScope")]
20-
MaskinportenScope = 3,
21-
22-
[EnumMember(Value = "ServiceCode")]
23-
ServiceCode = 4,
24-
25-
[EnumMember(Value = "ServiceEditionCode")]
26-
ServiceEditionCode = 5,
27-
28-
[EnumMember(Value = "ApplicationId")]
29-
ApplicationId = 6,
5+
LayoutSet,
6+
Layout,
7+
Component
308
}
319
}

backend/src/Designer/Enums/ReferenceSource.cs backend/src/Designer/Enums/ResourceReferenceSource.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Altinn.Studio.Designer.Enums
55
/// <summary>
66
/// Enum for the different reference sources for resources in the resource registry
77
/// </summary>
8-
public enum ReferenceSource
8+
public enum ResourceReferenceSource
99
{
1010
[EnumMember(Value = "Default")]
1111
Default = 0,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Altinn.Studio.Designer.Enums
4+
{
5+
/// <summary>
6+
/// Enum for reference types of resources in the resource registry
7+
/// </summary>
8+
public enum ResourceReferenceType
9+
{
10+
[EnumMember(Value = "Default")]
11+
Default = 0,
12+
13+
[EnumMember(Value = "Uri")]
14+
Uri = 1,
15+
16+
[EnumMember(Value = "DelegationSchemeId")]
17+
DelegationSchemeId = 2,
18+
19+
[EnumMember(Value = "MaskinportenScope")]
20+
MaskinportenScope = 3,
21+
22+
[EnumMember(Value = "ServiceCode")]
23+
ServiceCode = 4,
24+
25+
[EnumMember(Value = "ServiceEditionCode")]
26+
ServiceEditionCode = 5,
27+
28+
[EnumMember(Value = "ApplicationId")]
29+
ApplicationId = 6,
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Altinn.Studio.Designer.Enums;
5+
using Altinn.Studio.Designer.Events;
6+
using Altinn.Studio.Designer.Hubs.SyncHub;
7+
using Altinn.Studio.Designer.Models;
8+
using Altinn.Studio.Designer.Services.Interfaces;
9+
using MediatR;
10+
11+
namespace Altinn.Studio.Designer.EventHandlers.ComponentDeleted;
12+
13+
public class ComponentDeletedLayoutsHandler(IFileSyncHandlerExecutor fileSyncHandlerExecutor, IAppDevelopmentService appDevelopmentService) : INotificationHandler<ComponentDeletedEvent>
14+
{
15+
public async Task Handle(ComponentDeletedEvent notification, CancellationToken cancellationToken)
16+
{
17+
await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
18+
notification.EditingContext,
19+
SyncErrorCodes.ComponentDeletedLayoutsSyncError,
20+
"layouts",
21+
async () =>
22+
{
23+
List<Reference> referencesToDelete = [new Reference(ReferenceType.Component, notification.LayoutSetName, notification.ComponentId)];
24+
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToDelete, cancellationToken);
25+
});
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Altinn.Studio.Designer.Enums;
5+
using Altinn.Studio.Designer.Events;
6+
using Altinn.Studio.Designer.Hubs.SyncHub;
7+
using Altinn.Studio.Designer.Models;
8+
using Altinn.Studio.Designer.Services.Interfaces;
9+
using MediatR;
10+
11+
namespace Altinn.Studio.Designer.EventHandlers.LayoutPageDeleted;
12+
13+
public class LayoutPageDeletedLayoutsHandler(IFileSyncHandlerExecutor fileSyncHandlerExecutor, IAppDevelopmentService appDevelopmentService) : INotificationHandler<LayoutPageDeletedEvent>
14+
{
15+
public async Task Handle(LayoutPageDeletedEvent notification, CancellationToken cancellationToken)
16+
{
17+
await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
18+
notification.EditingContext,
19+
SyncErrorCodes.LayoutPageDeletedLayoutsSyncError,
20+
"layouts",
21+
async () =>
22+
{
23+
List<Reference> referencesToDelete = [new Reference(ReferenceType.Layout, notification.LayoutSetName, notification.LayoutName)];
24+
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToDelete, cancellationToken);
25+
});
26+
}
27+
}

backend/src/Designer/EventHandlers/LayoutSetDeleted/LayoutSetDeletedComponentRefHandler.cs

-73
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Altinn.Studio.Designer.Enums;
5+
using Altinn.Studio.Designer.Events;
6+
using Altinn.Studio.Designer.Hubs.SyncHub;
7+
using Altinn.Studio.Designer.Models;
8+
using Altinn.Studio.Designer.Services.Interfaces;
9+
using MediatR;
10+
11+
namespace Altinn.Studio.Designer.EventHandlers.LayoutSetDeleted;
12+
13+
public class LayoutSetDeletedLayoutsHandler(IFileSyncHandlerExecutor fileSyncHandlerExecutor, IAppDevelopmentService appDevelopmentService) : INotificationHandler<LayoutSetDeletedEvent>
14+
{
15+
public async Task Handle(LayoutSetDeletedEvent notification, CancellationToken cancellationToken)
16+
{
17+
await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
18+
notification.EditingContext,
19+
SyncErrorCodes.LayoutSetDeletedLayoutsSyncError,
20+
"layouts",
21+
async () =>
22+
{
23+
List<Reference> referencesToDelete = [new Reference(ReferenceType.LayoutSet, notification.LayoutSetName, notification.LayoutSetName)];
24+
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToDelete, cancellationToken);
25+
});
26+
}
27+
}

0 commit comments

Comments
 (0)