Skip to content

Commit

Permalink
Merge branch 'main' into add-support-for-frontend-to-use-update-optio…
Browse files Browse the repository at this point in the history
…n-list-id-endpoint
  • Loading branch information
standeren authored Nov 27, 2024
2 parents 416bade + 4a7d1e2 commit d3a64af
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 124 deletions.
21 changes: 0 additions & 21 deletions backend/src/Designer/Controllers/ProcessModelingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,6 @@ public FileStreamResult GetProcessDefinition(string org, string repo)
}

[HttpPut("process-definition")]
[Obsolete("This endpoint should be replaced by process-definition-latest, and url fixed after integration with frontend")]
public async Task<IActionResult> SaveProcessDefinition(string org, string repo,
CancellationToken cancellationToken)
{
Request.EnableBuffering();
try
{
await Guard.AssertValidXmlStreamAndRewindAsync(Request.Body);
}
catch (ArgumentException)
{
return BadRequest("BPMN file is not valid XML");
}

string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
await _processModelingService.SaveProcessDefinitionAsync(
AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer), Request.Body, cancellationToken);
return Ok();
}

[HttpPut("process-definition-latest")]
public async Task<IActionResult> UpsertProcessDefinitionAndNotify(string org, string repo, [FromForm] IFormFile content, [FromForm] string metadata, CancellationToken cancellationToken)
{
Request.EnableBuffering();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public class EndpointNameSyncEvaluator : IRequestSyncEvaluator
nameof(ProcessModelingController).Replace(RemoveControllerSuffix, string.Empty),
GenerateFrozenSet(
nameof(ProcessModelingController.AddDataTypeToApplicationMetadata),
nameof(ProcessModelingController.DeleteDataTypeFromApplicationMetadata)
nameof(ProcessModelingController.DeleteDataTypeFromApplicationMetadata),
nameof(ProcessModelingController.UpsertProcessDefinitionAndNotify),
nameof(ProcessModelingController.SaveProcessDefinitionFromTemplate)
)
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Designer.Tests.Controllers.ProcessModelingController.FileSync.TaskIdCh
public class ApplicationMetadataFileSyncTaskIdTests : DesignerEndpointsTestsBase<ApplicationMetadataFileSyncTaskIdTests>, IClassFixture<WebApplicationFactory<Program>>
{

private static string VersionPrefix(string org, string repository) => $"/designer/api/{org}/{repository}/process-modelling/process-definition-latest";
private static string VersionPrefix(string org, string repository) => $"/designer/api/{org}/{repository}/process-modelling/process-definition";

public ApplicationMetadataFileSyncTaskIdTests(WebApplicationFactory<Program> factory) : base(factory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public LayoutFileSyncTaskIdTests(WebApplicationFactory<Program> factory) : base(

private static string GetVersionPrefix(string org, string repository)
{
return $"/designer/api/{org}/{repository}/process-modelling/process-definition-latest";
return $"/designer/api/{org}/{repository}/process-modelling/process-definition";
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LayoutSetsFileSyncTaskIdTests : DesignerEndpointsTestsBase<LayoutSe
IClassFixture<WebApplicationFactory<Program>>
{
private static string VersionPrefix(string org, string repository) =>
$"/designer/api/{org}/{repository}/process-modelling/process-definition-latest";
$"/designer/api/{org}/{repository}/process-modelling/process-definition";

public LayoutSetsFileSyncTaskIdTests(WebApplicationFactory<Program> factory) : base(factory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PolicyFileSyncTaskIdTests : DesignerEndpointsTestsBase<PolicyFileSy
IClassFixture<WebApplicationFactory<Program>>
{
private static string VersionPrefix(string org, string repository) =>
$"/designer/api/{org}/{repository}/process-modelling/process-definition-latest";
$"/designer/api/{org}/{repository}/process-modelling/process-definition";

public PolicyFileSyncTaskIdTests(WebApplicationFactory<Program> factory) : base(factory)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Designer.Tests.Controllers.ProcessModelingController;

public class UpsertProcessDefinitionAndNotifyTests : DesignerEndpointsTestsBase<UpsertProcessDefinitionAndNotifyTests>, IClassFixture<WebApplicationFactory<Program>>
{
private static string VersionPrefix(string org, string repository) => $"/designer/api/{org}/{repository}/process-modelling/process-definition-latest";
private static string VersionPrefix(string org, string repository) => $"/designer/api/{org}/{repository}/process-modelling/process-definition";

public UpsertProcessDefinitionAndNotifyTests(WebApplicationFactory<Program> factory) : base(factory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileNameUtils, FileNameValidationResult } from './FileNameUtils';
import { FileNameErrorResult, FileNameUtils } from './FileNameUtils';

describe('FileNameUtils', () => {
describe('removeExtension', () => {
Expand Down Expand Up @@ -91,78 +91,72 @@ describe('FileNameUtils', () => {
});
});

describe('validateFileName', () => {
describe('findFileNameError', () => {
it('Returns "FileNameIsEmpty" when file name is empty', () => {
const fileName: string = '';
const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName(
fileName,
[],
);
expect(fileNameValidation).toBe(FileNameValidationResult.FileNameIsEmpty);
const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(fileName, []);
expect(fileNameError).toBe(FileNameErrorResult.FileNameIsEmpty);
});

it('Returns "NoRegExMatch" when file name does not match given regex', () => {
const fileName: string = 'ABC';
const fileNameRegEx: RegExp = /^[a-z]+$/;
const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName(
const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(
fileName,
[],
fileNameRegEx,
);
expect(fileNameValidation).toBe(FileNameValidationResult.NoRegExMatch);
expect(fileNameError).toBe(FileNameErrorResult.NoRegExMatch);
});

it('Returns "FileExists" when file name matches regEx and exists in list', () => {
const fileName: string = 'fileName1';
const invalidFileNames: string[] = ['fileName1', 'fileName2', 'fileName3'];
const fileNameRegEx: RegExp = /^[a-zA-Z0-9]+$/;
const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName(
const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(
fileName,
invalidFileNames,
fileNameRegEx,
);
expect(fileNameValidation).toBe(FileNameValidationResult.FileExists);
expect(fileNameError).toBe(FileNameErrorResult.FileExists);
});

it('Returns "FileExists" when no regEx is provided and exists in list', () => {
const fileName: string = 'fileName1';
const invalidFileNames: string[] = ['fileName1', 'fileName2', 'fileName3'];
const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName(
const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(
fileName,
invalidFileNames,
);
expect(fileNameValidation).toBe(FileNameValidationResult.FileExists);
expect(fileNameError).toBe(FileNameErrorResult.FileExists);
});

it('Returns "Valid" when file name matches regEx and does not exist in list of invalid names', () => {
it('Returns null when file name matches regEx and does not exist in list of invalid names', () => {
const fileName: string = 'fileName';
const invalidFileNames: string[] = ['fileName2', 'fileName3'];
const fileNameRegEx: RegExp = /^[a-zA-Z]+$/;
const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName(
const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(
fileName,
invalidFileNames,
fileNameRegEx,
);
expect(fileNameValidation).toBe(FileNameValidationResult.Valid);
expect(fileNameError).toBeNull();
});

it('Returns "Valid" when no regEx is provided and file name does not exist in list of invalid names', () => {
it('Returns null when no regEx is provided and file name does not exist in list of invalid names', () => {
const fileName: string = 'fileName';
const invalidFileNames: string[] = ['fileName2', 'fileName3'];
const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName(
const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(
fileName,
invalidFileNames,
);
expect(fileNameValidation).toBe(FileNameValidationResult.Valid);
expect(fileNameError).toBeNull();
});

it('Returns "Valid" when no regEx is provided and list of invalid names is empty', () => {
it('Returns null when no regEx is provided and list of invalid names is empty', () => {
const fileName: string = 'fileName';
const fileNameValidation: FileNameValidationResult = FileNameUtils.validateFileName(
fileName,
[],
);
expect(fileNameValidation).toBe(FileNameValidationResult.Valid);
const fileNameError: FileNameErrorResult = FileNameUtils.findFileNameError(fileName, []);
expect(fileNameError).toBeNull();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { StringUtils } from '@studio/pure-functions';

export enum FileNameValidationResult {
export enum FileNameErrorResult {
FileNameIsEmpty = 'fileNameIsEmpty',
NoRegExMatch = 'noRegExMatch',
FileExists = 'fileExists',
Valid = 'valid',
}

export class FileNameUtils {
Expand Down Expand Up @@ -52,15 +51,15 @@ export class FileNameUtils {
* @param fileName
* @param invalidFileNames
* @param regEx
* @returns FileNameValidationResult
* @returns {FileNameErrorResult | null}
*/
static validateFileName = (
static findFileNameError = (
fileName: string,
invalidFileNames: string[],
regEx?: RegExp,
): FileNameValidationResult => {
): FileNameErrorResult => {
if (fileName === '') {
return FileNameValidationResult.FileNameIsEmpty;
return FileNameErrorResult.FileNameIsEmpty;
}

const isFileNameNotMatchingRegEx: boolean = regEx ? Boolean(!fileName.match(regEx)) : false;
Expand All @@ -69,11 +68,11 @@ export class FileNameUtils {
);

if (isFileNameNotMatchingRegEx) {
return FileNameValidationResult.NoRegExMatch;
return FileNameErrorResult.NoRegExMatch;
}
if (isFileNameInInvalidList) {
return FileNameValidationResult.FileExists;
return FileNameErrorResult.FileExists;
}
return FileNameValidationResult.Valid;
return null;
};
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { FileNameUtils } from './FileNameUtils';
export { FileNameValidationResult } from './FileNameUtils';
export { FileNameErrorResult } from './FileNameUtils';
4 changes: 2 additions & 2 deletions frontend/packages/shared/src/api/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
createAccessListsPath,
accessListMemberPath,
resourceAccessListPath,
processEditorPathPut,
layoutSetPath,
processEditorDataTypePath,
processEditorDataTypesChangePath,
Expand All @@ -44,6 +43,7 @@ import {
optionListUploadPath,
optionListUpdatePath,
optionListIdUpdatePath,
processEditorPath,
selectedMaskinportenScopesPath,
} from 'app-shared/api/paths';
import type { AddLanguagePayload } from 'app-shared/types/api/AddLanguagePayload';
Expand Down Expand Up @@ -146,7 +146,7 @@ export const addDataTypeToAppMetadata = (org: string, app: string, dataTypeId: s
export const deleteDataTypeFromAppMetadata = (org: string, app: string, dataTypeId: string) => del(processEditorDataTypePath(org, app, dataTypeId));

export const updateBpmnXml = (org: string, app: string, form: any) =>
put(processEditorPathPut(org, app), form, {
put(processEditorPath(org, app), form, {
headers: {
'Content-Type': 'multipart/form-data',
},
Expand Down
1 change: 0 additions & 1 deletion frontend/packages/shared/src/api/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export const altinn2DelegationsMigrationPath = (org, env) => `${basePath}/${org}

// Process Editor
export const processEditorPath = (org, app) => `${basePath}/${org}/${app}/process-modelling/process-definition`;
export const processEditorPathPut = (org, app) => `${basePath}/${org}/${app}/process-modelling/process-definition-latest`;
export const processEditorDataTypesChangePath = (org, app) => `${basePath}/${org}/${app}/process-modelling/data-types`;
export const processTaskTypePath = (org, app, taskId) => `${basePath}/${org}/${app}/process-modelling/task-type/${taskId}`; // Get
export const processEditorDataTypePath = (org, app, dataTypeId, taskId) => `${basePath}/${org}/${app}/process-modelling/data-type/${dataTypeId}?${s({ taskId })}`;
Expand Down

0 comments on commit d3a64af

Please sign in to comment.