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

Use apps extended version of appmetadata csharp model #11435

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
2 changes: 2 additions & 0 deletions backend/packagegroups/NuGet.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>

<ItemGroup Label="Altinn specific packages">
<PackageReference Update="Altinn.App.Core" Version="8.0.0-preview.10" />
<PackageReference Update="Altinn.Common.AccessToken" Version="3.0.3" />
<PackageReference Update="Altinn.Common.AccessTokenClient" Version="1.1.5" />
<PackageReference Update="Altinn.Platform.Storage.Interface" Version="3.24.0" />
Expand All @@ -20,6 +21,7 @@
<PackageReference Update="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Update="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.23" />
<PackageReference Update="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Update="Microsoft.Azure.Security.KeyVault.Secrets" Version="4.5.0" />
<PackageReference Update="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
<PackageReference Update="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.24" />
<PackageReference Update="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.IO;
using System.Threading.Tasks;
using Altinn.Platform.Storage.Interface.Models;
using Altinn.App.Core.Models;
using Altinn.Studio.Designer.Services.Interfaces;

using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -37,7 +37,7 @@ public ApplicationMetadataController(IApplicationMetadataService applicationMeta
[HttpGet]
public async Task<ActionResult> GetApplicationMetadata(string org, string app)
{
Application application = await _applicationMetadataService.GetApplicationMetadataFromRepository(org, app);
ApplicationMetadata application = await _applicationMetadataService.GetApplicationMetadataFromRepository(org, app);
if (application == null)
{
return NotFound();
Expand All @@ -54,10 +54,10 @@ public async Task<ActionResult> GetApplicationMetadata(string org, string app)
/// <param name="applicationMetadata">The application metadata</param>
/// <returns>The updated application metadata</returns>
[HttpPut]
public async Task<ActionResult> UpdateApplicationMetadata(string org, string app, [FromBody] Application applicationMetadata)
public async Task<ActionResult> UpdateApplicationMetadata(string org, string app, [FromBody] ApplicationMetadata applicationMetadata)
{
await _applicationMetadataService.UpdateApplicationMetaDataLocally(org, app, applicationMetadata);
Application updatedApplicationMetadata = await _applicationMetadataService.GetApplicationMetadataFromRepository(org, app);
ApplicationMetadata updatedApplicationMetadata = await _applicationMetadataService.GetApplicationMetadataFromRepository(org, app);
return Ok(updatedApplicationMetadata);
}

Expand All @@ -77,7 +77,7 @@ public async Task<ActionResult> CreateApplicationMetadata(string org, string app
}

await _applicationMetadataService.CreateApplicationMetadata(org, app, app);
Application createdApplication = await _applicationMetadataService.GetApplicationMetadataFromRepository(org, app);
ApplicationMetadata createdApplication = await _applicationMetadataService.GetApplicationMetadataFromRepository(org, app);
if (createdApplication == null)
{
return StatusCode(500);
Expand Down
1 change: 0 additions & 1 deletion backend/src/Designer/Controllers/EnvironmentsController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Services.Implementation;
using Altinn.Studio.Designer.Services.Interfaces;
using Altinn.Studio.Designer.Services.Models;
using Microsoft.AspNetCore.Authorization;
Expand Down
9 changes: 6 additions & 3 deletions backend/src/Designer/Controllers/PreviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Altinn.App.Core.Models;
using Altinn.Platform.Profile.Models;
using Altinn.Platform.Register.Enums;
using Altinn.Platform.Register.Models;
Expand All @@ -18,6 +19,8 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ApplicationLanguage = Altinn.Studio.Designer.Models.ApplicationLanguage;
using LayoutSets = Altinn.Studio.Designer.Models.LayoutSets;

namespace Altinn.Studio.Designer.Controllers
{
Expand Down Expand Up @@ -120,11 +123,11 @@ public FileStreamResult Image(string org, string app, string imageFilePath, Canc
/// <returns>The application metadata for the app</returns>
[HttpGet]
[Route("api/v1/applicationmetadata")]
public async Task<ActionResult<Application>> ApplicationMetadata(string org, string app, CancellationToken cancellationToken)
public async Task<ActionResult<ApplicationMetadata>> ApplicationMetadata(string org, string app, CancellationToken cancellationToken)
{
string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
Application applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata(cancellationToken);
ApplicationMetadata applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata(cancellationToken);
return Ok(applicationMetadata);
}

Expand All @@ -141,7 +144,7 @@ public async Task<ActionResult<ApplicationSettings>> ApplicationSettings(string
{
string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
Application applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata(cancellationToken);
ApplicationMetadata applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata(cancellationToken);
ApplicationSettings applicationSettings = new()
{
Id = applicationMetadata.Id,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/Designer/Designer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Altinn.App.Core" />
<PackageReference Include="Altinn.Authorization.ABAC" />
<PackageReference Include="Altinn.ApiClients.Maskinporten" />
<PackageReference Include="Altinn.Common.AccessToken" />
<PackageReference Include="Altinn.Common.AccessTokenClient" />
<PackageReference Include="Altinn.Platform.Storage.Interface" />
<PackageReference Include="Altinn.Platform.Models" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
<PackageReference Include="CompilerAttributes" />
<PackageReference Include="ini-parser-netstandard" />
<PackageReference Include="JWTCookieAuthentication" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Platform.Storage.Interface.Models;
using Altinn.App.Core.Models;
using Altinn.Studio.Designer.Configuration;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Models;
Expand All @@ -17,6 +17,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.Tokens;
using JsonSerializer = System.Text.Json.JsonSerializer;
using LayoutSets = Altinn.Studio.Designer.Models.LayoutSets;

namespace Altinn.Studio.Designer.Infrastructure.GitRepository
{
Expand Down Expand Up @@ -74,12 +75,12 @@ public AltinnAppGitRepository(string org, string repository, string developer, s
/// <summary>
/// Gets the application metadata.
/// </summary>
public async Task<Application> GetApplicationMetadata(CancellationToken cancellationToken = default)
public async Task<ApplicationMetadata> GetApplicationMetadata(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
string appMetadataRelativeFilePath = Path.Combine(CONFIG_FOLDER_PATH, APP_METADATA_FILENAME);
string fileContent = await ReadTextByRelativePathAsync(appMetadataRelativeFilePath, cancellationToken);
Application applicationMetaData = JsonSerializer.Deserialize<Application>(fileContent, _jsonOptions);
ApplicationMetadata applicationMetaData = JsonSerializer.Deserialize<ApplicationMetadata>(fileContent, _jsonOptions);

return applicationMetaData;
}
Expand All @@ -94,7 +95,7 @@ public bool ApplicationMetadataExists()
/// Saves the application metadata file to disk.
/// </summary>
/// <param name="applicationMetadata">The updated application metadata to persist.</param>
public async Task SaveApplicationMetadata(Application applicationMetadata)
public async Task SaveApplicationMetadata(ApplicationMetadata applicationMetadata)
{
string metadataAsJson = JsonSerializer.Serialize(applicationMetadata, _jsonOptions);
string appMetadataRelativeFilePath = Path.Combine(CONFIG_FOLDER_PATH, APP_METADATA_FILENAME);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Services.Interfaces;
using Altinn.Studio.Designer.Services.Models;

namespace Altinn.Studio.Designer.Services.Implementation
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;
using Altinn.App.Core.Models;
using Altinn.Platform.Storage.Interface.Models;
using Altinn.Studio.Designer.Configuration;
using Altinn.Studio.Designer.Helpers;
Expand Down Expand Up @@ -58,7 +59,7 @@ public ApplicationMetadataService(
/// <inheritdoc/>
public async Task UpdateAppTitleInAppMetadata(string org, string app, string languageId, string title)
{
Application appMetadata = await GetApplicationMetadataFromRepository(org, app);
ApplicationMetadata appMetadata = await GetApplicationMetadataFromRepository(org, app);

Dictionary<string, string> titles = appMetadata.Title;
if (titles.ContainsKey(languageId))
Expand All @@ -76,7 +77,7 @@ public async Task UpdateAppTitleInAppMetadata(string org, string app, string lan
}

/// <inheritdoc/>
public async Task UpdateApplicationMetaDataLocally(string org, string app, Application applicationMetadata)
public async Task UpdateApplicationMetaDataLocally(string org, string app, ApplicationMetadata applicationMetadata)
{
string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
Expand Down Expand Up @@ -117,9 +118,10 @@ public async Task UpdateAppMetadataConfigAsync(string org, string app, ServiceCo
public async Task CreateApplicationMetadata(string org, string app, string appTitle)
{
string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
Application appMetadata = new()
string id = ApplicationHelper.GetFormattedApplicationId(org, app);
ApplicationMetadata appMetadata = new(id)
{
Id = ApplicationHelper.GetFormattedApplicationId(org, app),
Id = id,
VersionId = null,
Org = org,
Created = DateTime.UtcNow,
Expand All @@ -145,7 +147,7 @@ public async Task CreateApplicationMetadata(string org, string app, string appTi
public async Task AddMetadataForAttachment(string org, string app, string applicationMetadata)
{
DataType formMetadata = JsonConvert.DeserializeObject<DataType>(applicationMetadata);
Application existingApplicationMetadata = await GetApplicationMetadataFromRepository(org, app);
ApplicationMetadata existingApplicationMetadata = await GetApplicationMetadataFromRepository(org, app);
existingApplicationMetadata.DataTypes.Add(formMetadata);

await UpdateApplicationMetaDataLocally(org, app, existingApplicationMetadata);
Expand All @@ -156,7 +158,7 @@ public async Task UpdateMetadataForAttachment(string org, string app, string app
{
dynamic attachmentMetadata = JsonConvert.DeserializeObject(applicationMetadata);
string attachmentId = attachmentMetadata.GetValue("id").Value;
Application existingApplicationMetadata = await GetApplicationMetadataFromRepository(org, app);
ApplicationMetadata existingApplicationMetadata = await GetApplicationMetadataFromRepository(org, app);
DataType applicationForm = existingApplicationMetadata.DataTypes.FirstOrDefault(m => m.Id == attachmentId) ?? new DataType();
applicationForm.AllowedContentTypes = new List<string>();

Expand Down Expand Up @@ -186,7 +188,7 @@ public async Task<bool> DeleteMetadataForAttachment(string org, string app, stri
{
try
{
Application existingApplicationMetadata = await GetApplicationMetadataFromRepository(org, app);
ApplicationMetadata existingApplicationMetadata = await GetApplicationMetadataFromRepository(org, app);

if (existingApplicationMetadata.DataTypes != null)
{
Expand All @@ -208,8 +210,8 @@ public async Task<bool> DeleteMetadataForAttachment(string org, string app, stri
public async Task UpdateApplicationMetadataInStorageAsync(string org, string app, string shortCommitId, string envName)
{

Application applicationFromRepository = await GetApplicationMetadataFromSpecificReference(org, app, shortCommitId);
Application application = await GetApplicationMetadataFromStorage(org, app, envName);
ApplicationMetadata applicationFromRepository = await GetApplicationMetadataFromSpecificReference(org, app, shortCommitId);
ApplicationMetadata application = await GetApplicationMetadataFromStorage(org, app, envName);
if (application == null)
{
await CreateApplicationMetadataInStorage(org, app, applicationFromRepository, envName, shortCommitId);
Expand All @@ -219,11 +221,11 @@ public async Task UpdateApplicationMetadataInStorageAsync(string org, string app
await UpdateApplicationMetadataInStorage(org, app, applicationFromRepository, envName, shortCommitId);
}

public async Task<Application> GetApplicationMetadataFromRepository(string org, string app)
public async Task<ApplicationMetadata> GetApplicationMetadataFromRepository(string org, string app)
{
string developer = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext);
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(org, app, developer);
Application applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata();
ApplicationMetadata applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata();
return applicationMetadata;
}

Expand All @@ -234,7 +236,7 @@ public async Task<Application> GetApplicationMetadataFromRepository(string org,
/// <param name="app">Application identifier which is unique within an organisation.</param>
/// <param name="referenceId">The name of the commit/branch/tag. Default the repository’s default branch</param>
/// <returns>The application metadata for an application.</returns>
private async Task<Application> GetApplicationMetadataFromSpecificReference(string org, string app, string referenceId)
private async Task<ApplicationMetadata> GetApplicationMetadataFromSpecificReference(string org, string app, string referenceId)
{
var file = await _giteaApiWrapper.GetFileAsync(org, app, "App/config/applicationmetadata.json", referenceId);
if (string.IsNullOrEmpty(file.Content))
Expand All @@ -245,7 +247,7 @@ private async Task<Application> GetApplicationMetadataFromSpecificReference(stri
// It's used to avoid sensibility to BOM
using var fileStream = new MemoryStream(Convert.FromBase64String(file.Content));
using StreamReader utf8Reader = new(fileStream, Encoding.UTF8);
return JsonSerializer.Deserialize<Application>(await utf8Reader.ReadToEndAsync(),
return JsonSerializer.Deserialize<ApplicationMetadata>(await utf8Reader.ReadToEndAsync(),
new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
Expand All @@ -261,7 +263,7 @@ public bool ApplicationMetadataExistsInRepository(string org, string app)
return altinnAppGitRepository.ApplicationMetadataExists();
}

private async Task<Application> GetApplicationMetadataFromStorage(string org, string app, string envName)
private async Task<ApplicationMetadata> GetApplicationMetadataFromStorage(string org, string app, string envName)
{
try
{
Expand All @@ -282,15 +284,15 @@ private async Task<Application> GetApplicationMetadataFromStorage(string org, st
}
}

private async Task CreateApplicationMetadataInStorage(string org, string app, Application applicationFromRepository, string envName, string shortCommitId)
private async Task CreateApplicationMetadataInStorage(string org, string app, ApplicationMetadata applicationFromRepository, string envName, string shortCommitId)
{
applicationFromRepository.Id = $"{org}/{app}";
applicationFromRepository.VersionId = shortCommitId;

await _storageAppMetadataClient.CreateApplicationMetadata(org, app, applicationFromRepository, envName);
}

private async Task UpdateApplicationMetadataInStorage(string org, string app, Application applicationFromRepository, string envName, string shortCommitId)
private async Task UpdateApplicationMetadataInStorage(string org, string app, ApplicationMetadata applicationFromRepository, string envName, string shortCommitId)
{
applicationFromRepository.VersionId = shortCommitId;

Expand Down
5 changes: 3 additions & 2 deletions backend/src/Designer/Services/Implementation/RepositorySI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using Altinn.App.Core.Models;
using Altinn.Authorization.ABAC.Utils;
using Altinn.Authorization.ABAC.Xacml;
using Altinn.Studio.DataModeling.Metamodel;
Expand Down Expand Up @@ -312,7 +313,7 @@ private async Task CreateRepositorySettings(string org, string repository, strin

await targetAppRepository.SearchAndReplaceInFile(".git/config", $"repos/{org}/{sourceRepository}.git", $"repos/{org}/{targetRepository}.git");

PlatformStorageModels.Application appMetadata = await targetAppRepository.GetApplicationMetadata();
ApplicationMetadata appMetadata = await targetAppRepository.GetApplicationMetadata();
appMetadata.Id = $"{org}/{targetRepository}";
appMetadata.CreatedBy = developer;
appMetadata.LastChangedBy = developer;
Expand Down Expand Up @@ -662,7 +663,7 @@ private FileSystemObject GetFileSystemObjectForDirectory(string path)

private async Task<string> GetModelName(string org, string app)
{
PlatformStorageModels.Application application = await _applicationMetadataService.GetApplicationMetadataFromRepository(org, app);
ApplicationMetadata application = await _applicationMetadataService.GetApplicationMetadataFromRepository(org, app);
string dataTypeId = string.Empty;

if (application == null)
Expand Down
Loading
Loading