Skip to content

Commit

Permalink
Merge branch 'main' into split-app-contnet-library
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasEng authored Jan 20, 2025
2 parents 4c78eb2 + 1cf0f2e commit 5b7a8c3
Show file tree
Hide file tree
Showing 74 changed files with 2,020 additions and 235 deletions.
50 changes: 27 additions & 23 deletions backend/src/Designer/Controllers/AppDevelopmentController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -9,7 +10,6 @@
using Altinn.Studio.Designer.Events;
using Altinn.Studio.Designer.Filters;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Infrastructure.GitRepository;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Models.Dto;
using Altinn.Studio.Designer.Services.Interfaces;
Expand All @@ -32,7 +32,6 @@ public class AppDevelopmentController : Controller
private readonly IAppDevelopmentService _appDevelopmentService;
private readonly IRepository _repository;
private readonly ISourceControl _sourceControl;
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
private readonly ApplicationInsightsSettings _applicationInsightsSettings;
private readonly IMediator _mediator;

Expand All @@ -43,15 +42,13 @@ public class AppDevelopmentController : Controller
/// <param name="appDevelopmentService">The app development service</param>
/// <param name="repositoryService">The application repository service</param>
/// <param name="sourceControl">The source control service.</param>
/// <param name="altinnGitRepositoryFactory"></param>
/// <param name="applicationInsightsSettings">An <see cref="ApplicationInsightsSettings"/></param>
/// <param name="mediator"></param>
public AppDevelopmentController(IAppDevelopmentService appDevelopmentService, IRepository repositoryService, ISourceControl sourceControl, IAltinnGitRepositoryFactory altinnGitRepositoryFactory, ApplicationInsightsSettings applicationInsightsSettings, IMediator mediator)
public AppDevelopmentController(IAppDevelopmentService appDevelopmentService, IRepository repositoryService, ISourceControl sourceControl, ApplicationInsightsSettings applicationInsightsSettings, IMediator mediator)
{
_appDevelopmentService = appDevelopmentService;
_repository = repositoryService;
_sourceControl = sourceControl;
_altinnGitRepositoryFactory = altinnGitRepositoryFactory;
_applicationInsightsSettings = applicationInsightsSettings;
_mediator = mediator;
}
Expand Down Expand Up @@ -123,8 +120,17 @@ public async Task<ActionResult> SaveFormLayout(string org, string app, [FromQuer

if (formLayoutPayload.ComponentIdsChange is not null && !string.IsNullOrEmpty(layoutSetName))
{
foreach (var componentIdChange in formLayoutPayload.ComponentIdsChange)
foreach (var componentIdChange in formLayoutPayload.ComponentIdsChange.Where((componentIdChange) => componentIdChange.OldComponentId != componentIdChange.NewComponentId))
{
if (componentIdChange.NewComponentId == null)
{
await _mediator.Publish(new ComponentDeletedEvent
{
ComponentId = componentIdChange.OldComponentId,
LayoutSetName = layoutSetName,
EditingContext = editingContext
}, cancellationToken);
}
await _mediator.Publish(new ComponentIdChangedEvent
{
OldComponentId = componentIdChange.OldComponentId,
Expand Down Expand Up @@ -159,16 +165,26 @@ await _mediator.Publish(new LayoutPageAddedEvent
/// <param name="app">Application identifier which is unique within an organisation.</param>
/// <param name="layoutSetName">The name of the layout set the specific layout belongs to</param>
/// <param name="layoutName">The form layout to be deleted</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
/// <returns>A success message if the save was successful</returns>
[HttpDelete]
[Route("form-layout/{layoutName}")]
public ActionResult DeleteFormLayout(string org, string app, [FromQuery] string layoutSetName, [FromRoute] string layoutName)
public async Task<ActionResult> DeleteFormLayout(string org, string app, [FromQuery] string layoutSetName, [FromRoute] string layoutName, CancellationToken cancellationToken)
{
try
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);

await _mediator.Publish(new LayoutPageDeletedEvent
{
EditingContext = editingContext,
LayoutSetName = layoutSetName,
LayoutName = layoutName,
}, cancellationToken);

_appDevelopmentService.DeleteFormLayout(editingContext, layoutSetName, layoutName);

return Ok();
}
catch (FileNotFoundException exception)
Expand Down Expand Up @@ -402,13 +418,15 @@ public async Task<ActionResult> DeleteLayoutSet(string org, string app, [FromRou
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);
LayoutSets layoutSets = await _appDevelopmentService.DeleteLayoutSet(editingContext, layoutSetIdToUpdate, cancellationToken);

await _mediator.Publish(new LayoutSetDeletedEvent
{
EditingContext = editingContext,
LayoutSetId = layoutSetIdToUpdate
LayoutSetName = layoutSetIdToUpdate
}, cancellationToken);

LayoutSets layoutSets = await _appDevelopmentService.DeleteLayoutSet(editingContext, layoutSetIdToUpdate, cancellationToken);

return Ok(layoutSets);
}

Expand Down Expand Up @@ -543,20 +561,6 @@ public ActionResult GetWidgetSettings(string org, string app)
return Ok(widgetSettings);
}

[HttpGet]
[Route("option-list-ids")]
public ActionResult GetOptionListIds(string org, string app)
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
string[] optionListIds = altinnAppGitRepository.GetOptionsListIds();
if (optionListIds.Length == 0)
{
return NoContent();
}
return Ok(optionListIds);
}

[HttpGet("app-version")]
public VersionResponse GetAppVersion(string org, string app)
{
Expand Down
8 changes: 4 additions & 4 deletions backend/src/Designer/Controllers/ResourceAdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public async Task<ActionResult<List<AvailableService>>> GetAltinn2LinkServices(s
foreach (ServiceResource resource in allResources)
{
if (resource?.HasCompetentAuthority.Orgcode != null
&& resource.ResourceReferences != null && resource.ResourceReferences.Exists(r => r.ReferenceType != null && r.ReferenceType.Equals(ReferenceType.ServiceCode))
&& resource.ResourceReferences != null && resource.ResourceReferences.Exists(r => r.ReferenceType != null && r.ReferenceType.Equals(ResourceReferenceType.ServiceCode))
&& resource.ResourceType == ResourceType.Altinn2Service)
{
AvailableService service = new AvailableService();
Expand All @@ -496,8 +496,8 @@ public async Task<ActionResult<List<AvailableService>>> GetAltinn2LinkServices(s
service.ServiceName = resource.Title["nb"];
}

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

if (resource.ResourceType == ResourceType.MaskinportenSchema)
{
if (resource.ResourceReferences == null || !resource.ResourceReferences.Any((x) => x.ReferenceType == ReferenceType.MaskinportenScope))
if (resource.ResourceReferences == null || !resource.ResourceReferences.Any((x) => x.ReferenceType == ResourceReferenceType.MaskinportenScope))
{
ModelState.AddModelError($"{resource.Identifier}.resourceReferences", "resourceerror.missingmaskinportenscope");
}
Expand Down
28 changes: 3 additions & 25 deletions backend/src/Designer/Enums/ReferenceType.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
using System.Runtime.Serialization;

namespace Altinn.Studio.Designer.Enums
{
/// <summary>
/// Enum for reference types of resources in the resource registry
/// </summary>
public enum ReferenceType
{
[EnumMember(Value = "Default")]
Default = 0,

[EnumMember(Value = "Uri")]
Uri = 1,

[EnumMember(Value = "DelegationSchemeId")]
DelegationSchemeId = 2,

[EnumMember(Value = "MaskinportenScope")]
MaskinportenScope = 3,

[EnumMember(Value = "ServiceCode")]
ServiceCode = 4,

[EnumMember(Value = "ServiceEditionCode")]
ServiceEditionCode = 5,

[EnumMember(Value = "ApplicationId")]
ApplicationId = 6,
LayoutSet,
Layout,
Component
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Altinn.Studio.Designer.Enums
/// <summary>
/// Enum for the different reference sources for resources in the resource registry
/// </summary>
public enum ReferenceSource
public enum ResourceReferenceSource
{
[EnumMember(Value = "Default")]
Default = 0,
Expand Down
31 changes: 31 additions & 0 deletions backend/src/Designer/Enums/ResourceReferenceType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Runtime.Serialization;

namespace Altinn.Studio.Designer.Enums
{
/// <summary>
/// Enum for reference types of resources in the resource registry
/// </summary>
public enum ResourceReferenceType
{
[EnumMember(Value = "Default")]
Default = 0,

[EnumMember(Value = "Uri")]
Uri = 1,

[EnumMember(Value = "DelegationSchemeId")]
DelegationSchemeId = 2,

[EnumMember(Value = "MaskinportenScope")]
MaskinportenScope = 3,

[EnumMember(Value = "ServiceCode")]
ServiceCode = 4,

[EnumMember(Value = "ServiceEditionCode")]
ServiceEditionCode = 5,

[EnumMember(Value = "ApplicationId")]
ApplicationId = 6,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Enums;
using Altinn.Studio.Designer.Events;
using Altinn.Studio.Designer.Hubs.SyncHub;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Services.Interfaces;
using MediatR;

namespace Altinn.Studio.Designer.EventHandlers.ComponentDeleted;

public class ComponentDeletedLayoutsHandler(IFileSyncHandlerExecutor fileSyncHandlerExecutor, IAppDevelopmentService appDevelopmentService) : INotificationHandler<ComponentDeletedEvent>
{
public async Task Handle(ComponentDeletedEvent notification, CancellationToken cancellationToken)
{
await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
notification.EditingContext,
SyncErrorCodes.ComponentDeletedLayoutsSyncError,
"layouts",
async () =>
{
List<Reference> referencesToDelete = [new Reference(ReferenceType.Component, notification.LayoutSetName, notification.ComponentId)];
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToDelete, cancellationToken);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Enums;
using Altinn.Studio.Designer.Events;
using Altinn.Studio.Designer.Hubs.SyncHub;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Services.Interfaces;
using MediatR;

namespace Altinn.Studio.Designer.EventHandlers.LayoutPageDeleted;

public class LayoutPageDeletedLayoutsHandler(IFileSyncHandlerExecutor fileSyncHandlerExecutor, IAppDevelopmentService appDevelopmentService) : INotificationHandler<LayoutPageDeletedEvent>
{
public async Task Handle(LayoutPageDeletedEvent notification, CancellationToken cancellationToken)
{
await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
notification.EditingContext,
SyncErrorCodes.LayoutPageDeletedLayoutsSyncError,
"layouts",
async () =>
{
List<Reference> referencesToDelete = [new Reference(ReferenceType.Layout, notification.LayoutSetName, notification.LayoutName)];
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToDelete, cancellationToken);
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Enums;
using Altinn.Studio.Designer.Events;
using Altinn.Studio.Designer.Hubs.SyncHub;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Services.Interfaces;
using MediatR;

namespace Altinn.Studio.Designer.EventHandlers.LayoutSetDeleted;

public class LayoutSetDeletedLayoutsHandler(IFileSyncHandlerExecutor fileSyncHandlerExecutor, IAppDevelopmentService appDevelopmentService) : INotificationHandler<LayoutSetDeletedEvent>
{
public async Task Handle(LayoutSetDeletedEvent notification, CancellationToken cancellationToken)
{
await fileSyncHandlerExecutor.ExecuteWithExceptionHandlingAndConditionalNotification(
notification.EditingContext,
SyncErrorCodes.LayoutSetDeletedLayoutsSyncError,
"layouts",
async () =>
{
List<Reference> referencesToDelete = [new Reference(ReferenceType.LayoutSet, notification.LayoutSetName, notification.LayoutSetName)];
return await appDevelopmentService.UpdateLayoutReferences(notification.EditingContext, referencesToDelete, cancellationToken);
});
}
}
Loading

0 comments on commit 5b7a8c3

Please sign in to comment.