Skip to content

Commit

Permalink
Merge branch 'main' into 13871-move-useWebSocket-to-app-development
Browse files Browse the repository at this point in the history
  • Loading branch information
wrt95 authored Oct 30, 2024
2 parents 8995df7 + bea682e commit 3d91f21
Show file tree
Hide file tree
Showing 251 changed files with 4,166 additions and 1,410 deletions.
7 changes: 4 additions & 3 deletions backend/packagegroups/NuGet.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@
<PackageReference Update="xunit" Version="2.9.2" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.8.2" />
<PackageReference Update="coverlet.collector" Version="6.0.2" />
<PackageReference Update="Basic.Reference.Assemblies" Version="1.7.9" />
<PackageReference Update="Basic.Reference.Assemblies" Version="1.7.8" />
<PackageReference Update="Fare" Version="2.2.1" />
<PackageReference Update="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Update="Microsoft.CodeAnalysis.Common" Version="4.11.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageReference Update="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
<PackageReference Update="Testcontainers" Version="3.10.0" />
<PackageReference Update="Testcontainers.PostgreSql" Version="3.10.0" />
<PackageReference Update="Microsoft.AspNetCore.SignalR.Client" Version="8.0.10" />
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="8.0.2" />
<PackageReference Update="WireMock.Net" Version="1.6.7" />
</ItemGroup>
</Project>
77 changes: 77 additions & 0 deletions backend/src/Designer/Controllers/AppScopesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Constants;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Models.Dto;
using Altinn.Studio.Designer.Repository.Models.AppScope;
using Altinn.Studio.Designer.Services.Interfaces;
using Altinn.Studio.Designer.TypedHttpClients.MaskinPorten;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.FeatureManagement.Mvc;


namespace Altinn.Studio.Designer.Controllers;

[FeatureGate(StudioFeatureFlags.AnsattPorten)]
[Route("designer/api/{org}/{app:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/app-scopes")]

public class AppScopesController(IMaskinPortenHttpClient maskinPortenHttpClient,
IAppScopesService appScopesService) : ControllerBase
{
[Authorize(AnsattPortenConstants.AnsattportenAuthorizationPolicy)]
[HttpGet("maskinporten")]
public async Task<IActionResult> GetScopesFromMaskinPorten(string org, string app, CancellationToken cancellationToken)
{
var scopes = await maskinPortenHttpClient.GetAvailableScopes(cancellationToken);

var reponse = new AppScopesResponse()
{
Scopes = scopes.Select(x => new MaskinPortenScopeDto()
{
Scope = x.Scope,
Description = x.Description
}).ToHashSet()
};

return Ok(reponse);
}


[Authorize]
[HttpPut]
public async Task UpsertAppScopes(string org, string app, [FromBody] AppScopesUpsertRequest appScopesUpsertRequest,
CancellationToken cancellationToken)
{
var scopes = appScopesUpsertRequest.Scopes.Select(x => new MaskinPortenScopeEntity()
{
Scope = x.Scope,
Description = x.Description
}).ToHashSet();

string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
await appScopesService.UpsertScopesAsync(AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer), scopes, cancellationToken);
}


[Authorize]
[HttpGet]
public async Task<IActionResult> GetAppScopes(string org, string app, CancellationToken cancellationToken)
{
var appScopes = await appScopesService.GetAppScopesAsync(AltinnRepoContext.FromOrgRepo(org, app), cancellationToken);

var reponse = new AppScopesResponse()
{
Scopes = appScopes?.Scopes.Select(x => new MaskinPortenScopeDto()
{
Scope = x.Scope,
Description = x.Description
}).ToHashSet() ?? []
};

return Ok(reponse);
}

}
26 changes: 0 additions & 26 deletions backend/src/Designer/Controllers/MaskinPortenController.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ private static IServiceCollection AddAnsattPortenAuthentication(this IServiceCol
options.Events.OnRedirectToIdentityProvider = context =>
{
if (!context.Request.Path.StartsWithSegments("/designer/api/maskinporten"))
if (!context.Request.Path.StartsWithSegments("/designer/api") ||
!context.Request.Path.Value!.Contains("/maskinporten"))
{
context.Response.StatusCode = StatusCodes.Status401Unauthorized;
context.HandleResponse();
Expand Down
2 changes: 2 additions & 0 deletions backend/src/Designer/Infrastructure/ServiceRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public static IServiceCollection RegisterServiceImplementations(this IServiceCol

services.AddScoped<IReleaseRepository, ORMReleaseRepository>();
services.AddScoped<IDeploymentRepository, ORMDeploymentRepository>();
services.AddScoped<IAppScopesRepository, AppScopesRepository>();
services.AddTransient<IReleaseService, ReleaseService>();
services.AddTransient<IDeploymentService, DeploymentService>();
services.AddTransient<IAppScopesService, AppScopesService>();
services.AddTransient<IKubernetesDeploymentsService, KubernetesDeploymentsService>();
services.AddTransient<IApplicationInformationService, ApplicationInformationService>();
services.AddTransient<IApplicationMetadataService, ApplicationMetadataService>();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions backend/src/Designer/Migrations/20240919171846_AppScopesTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace Altinn.Studio.Designer.Migrations
{
/// <inheritdoc />
public partial class AppScopesTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "app_scopes",
schema: "designer",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
app = table.Column<string>(type: "character varying", nullable: false),
org = table.Column<string>(type: "character varying", nullable: false),
created = table.Column<DateTime>(type: "timestamptz", nullable: false),
scopes = table.Column<string>(type: "jsonb", nullable: false),
created_by = table.Column<string>(type: "character varying", nullable: true),
last_modified_by = table.Column<string>(type: "character varying", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("app_scopes_pkey", x => x.id);
});

migrationBuilder.CreateIndex(
name: "idx_app_scopes_org_app",
schema: "designer",
table: "app_scopes",
columns: new[] { "org", "app" },
unique: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "app_scopes",
schema: "designer");
}
}
}
Loading

0 comments on commit 3d91f21

Please sign in to comment.