-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: store maskinporten scopes in db (#13930)
- Loading branch information
1 parent
1deff1c
commit 4adfb65
Showing
56 changed files
with
1,365 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
backend/src/Designer/Controllers/MaskinPortenController.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
backend/src/Designer/Migrations/20240919171846_AppScopesTable.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
backend/src/Designer/Migrations/20240919171846_AppScopesTable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
Oops, something went wrong.