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

feature/GW-1763/branch-protections #78

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5e34af3
Calls for finishing the mapping tester
rubenvdlinde Nov 11, 2024
d2d9a3f
Merge branch 'feature/add-saveobjects' into feature/CONNECTOR-120/sav…
RalkeyOfficial Nov 12, 2024
6fc18c6
fixed mapping objects get
RalkeyOfficial Nov 12, 2024
a3f3075
fixed saving objects
RalkeyOfficial Nov 12, 2024
30ea9db
finished frontend saving objects
RalkeyOfficial Nov 12, 2024
1df05b5
changed function names
RalkeyOfficial Nov 12, 2024
be0ea08
removed a S after save objects
RalkeyOfficial Nov 12, 2024
8bb3786
lint fix
RalkeyOfficial Nov 12, 2024
c8d7686
added a clear timeout when closing modal
RalkeyOfficial Nov 12, 2024
c356d56
fixed console error when deleting endpoint
RalkeyOfficial Nov 13, 2024
f7293a9
added unset property to mapping
RalkeyOfficial Nov 13, 2024
be46c94
Merge pull request #61 from ConductionNL/feature/ONNECTOR-130/endpoin…
RalkeyOfficial Nov 13, 2024
20af346
removed a incorrect help text
RalkeyOfficial Nov 13, 2024
0838c31
forgot to include unset in the test
RalkeyOfficial Nov 13, 2024
aa36301
Merge pull request #59 from ConductionNL/feature/CONNECTOR-120/save-m…
remko48 Nov 14, 2024
85af8e0
Merge pull request #62 from ConductionNL/feature/CONNECTOR-122/mappin…
remko48 Nov 14, 2024
fdf5278
Merge pull request #60 from ConductionNL/feature/CONNECTOR-132/stop-t…
remko48 Nov 14, 2024
77cd388
Fixed small sync bug
remko48 Nov 14, 2024
c835df0
Set format on callLog
remko48 Nov 14, 2024
4ff6d45
cleanup
remko48 Nov 14, 2024
53daa49
Merge pull request #63 from ConductionNL/feature/small-fixes
remko48 Nov 14, 2024
9062428
Fix idPosition default, sourceId check and next page
bbrands02 Nov 14, 2024
f584a40
small cleanup
bbrands02 Nov 14, 2024
920ed57
Merge pull request #65 from ConductionNL/fix/sync-fixes
bbrands02 Nov 14, 2024
1277f47
fixed jobs next/last run view
RalkeyOfficial Nov 15, 2024
15eff74
Merge pull request #68 from ConductionNL/feature/CONNECTOR-46/jobs-ne…
RalkeyOfficial Nov 18, 2024
fc1d9e7
Added specific branch pr to main
remko48 Nov 20, 2024
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
18 changes: 18 additions & 0 deletions .github/workflows/pull-request-from-branch-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Main Branch Protection

on:
pull_request:
branches:
- main

jobs:
check-branch:
runs-on: ubuntu-latest
steps:
- name: Check branch
run: |
if [[ ${GITHUB_HEAD_REF} != development ]] && [[ ${GITHUB_HEAD_REF} != documentation ]] && ! [[ ${GITHUB_HEAD_REF} =~ ^hotfix/ ]];
then
echo "Error: Pull request must come from 'development', 'documentation' or 'hotfix/' branch"
exit 1
fi
2 changes: 2 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
['name' => 'synchronizations#test', 'url' => '/api/synchronizations-test/{id}', 'verb' => 'POST'],
// Mapping endpoints
['name' => 'mappings#test', 'url' => '/api/mappings/test', 'verb' => 'POST'],
['name' => 'mappings#saveObject', 'url' => '/api/mappings/objects', 'verb' => 'POST'],
['name' => 'mappings#getObjects', 'url' => '/api/mappings/objects', 'verb' => 'GET'],
// Running endpoints
['name' => 'endpoints#run', 'url' => '/api/v1/{endpoint}', 'verb' => 'GET'],
['name' => 'endpoints#run', 'url' => '/api/v1/{endpoint}', 'verb' => 'PUT'],
Expand Down
46 changes: 45 additions & 1 deletion lib/Controller/MappingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function __construct(
IRequest $request,
private readonly IAppConfig $config,
private readonly MappingMapper $mappingMapper,
private readonly MappingService $mappingService
private readonly MappingService $mappingService,
private readonly ObjectService $objectService
)
{
parent::__construct($appName, $request);
Expand Down Expand Up @@ -291,4 +292,47 @@ public function test(ObjectService $objectService, IURLGenerator $urlGenerator):
'validationErrors' => $validationErrors
]);
}

/**
* Saves a mapping object
*
* This method saves a mapping object based on POST data.
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function saveObject(): JSONResponse
{
// Check if the OpenRegister service is available
$openRegisters = $this->objectService->getOpenRegisters();
if ($openRegisters !== null) {
$data = $this->request->getParams();
return new JSONResponse($openRegisters->saveObject($data['register'], $data['schema'], $data['object']));
}
}

/**
* Retrieves a list of objects to map to
*
* This method retrieves a list of objects to map to based on GET data.
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getObjects(): JSONResponse
{
// Check if the OpenRegister service is available
$openRegisters = $this->objectService->getOpenRegisters();
$data = [];
if ($openRegisters !== null) {
$data['openRegisters'] = true;
$data['availableRegisters'] = $openRegisters->getRegisters();
}
else {
$data['openRegisters'] = false;
}

return new JSONResponse($data);

}
}
5 changes: 3 additions & 2 deletions lib/Db/CallLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public function jsonSerialize(): array
'synchronizationId' => $this->synchronizationId,
'userId' => $this->userId,
'sessionId' => $this->sessionId,
'expires' => $this->expires,
'created' => $this->created,
'expires' => isset($this->expires) ? $this->expires->format('c') : null,
'created' => isset($this->created) ? $this->created->format('c') : null,

];
}
}
16 changes: 10 additions & 6 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public function __construct(
*/
public function synchronize(Synchronization $synchronization, ?bool $isTest = false): array
{
if (empty($synchronization->getSourceId()) === true) {
throw new Exception('sourceId of synchronziation cannot be empty. Canceling synchronization..');
}

$objectList = $this->getAllObjectsFromSource(synchronization: $synchronization, isTest: $isTest);

Expand Down Expand Up @@ -151,7 +154,7 @@ private function getOriginId(Synchronization $synchronization, array $object): i
$sourceConfig = $synchronization->getSourceConfig();

// Check if a custom ID position is defined in the source configuration
if (isset($sourceConfig['idPosition']) === true) {
if (isset($sourceConfig['idPosition']) === true && empty($sourceConfig['idPosition']) === false) {
// Override default with custom ID position from config
$originIdPosition = $sourceConfig['idPosition'];
}
Expand Down Expand Up @@ -391,19 +394,21 @@ public function getAllObjectsFromApi(Synchronization $synchronization, ?bool $is

// Current page is 2 because the first call made above is page 1.
$currentPage = 2;
$usedNextEndpoint = false;
$useNextEndpoint = false;
if (array_key_exists('next', $body)) {
$useNextEndpoint = true;
}


// Continue making API calls if there are more pages from 'next' the response body or if paginationQuery is set
while($nextEndpoint = $this->getNextEndpoint(body: $body, url: $source->getLocation(), sourceConfig: $sourceConfig, currentPage: $currentPage)) {
$usedNextEndpoint = true;
while($useNextEndpoint === true && $nextEndpoint = $this->getNextEndpoint(body: $body, url: $source->getLocation(), sourceConfig: $sourceConfig, currentPage: $currentPage)) {
// Do not pass $config here becuase it overwrites the query attached to nextEndpoint
$response = $this->callService->call(source: $source, endpoint: $nextEndpoint)->getResponse();
$body = json_decode($response['body'], true);
$objects = array_merge($objects, $this->getAllObjectsFromArray($body, $synchronization));
}

if ($usedNextEndpoint === false) {
if ($useNextEndpoint === false) {
do {
$config = $this->getNextPage(config: $config, sourceConfig: $sourceConfig, currentPage: $currentPage);
$response = $this->callService->call(source: $source, endpoint: $endpoint, method: 'GET', config: $config)->getResponse();
Expand Down Expand Up @@ -523,7 +528,6 @@ public function getAllObjectsFromArray(array $array, Synchronization $synchroniz
*/
public function getNextlinkFromCall(array $body): ?string
{
// Check if the 'next' key exists in the response body
return $body['next'] ?? null;
}
}
1 change: 0 additions & 1 deletion src/components/CreateEndpointDialog.vue
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion src/components/CreateWebhookDialog.vue
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion src/components/EditEndpointDialog.vue
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion src/components/EditWebhookDialog.vue
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion src/entities/callLog/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './callLog.ts'
export * from './callLog.types.ts'
export * from './callLog.mock.ts'

1 change: 0 additions & 1 deletion src/entities/endpoint/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './endpoint.ts'
export * from './endpoint.types.ts'
export * from './endpoint.mock.ts'

2 changes: 1 addition & 1 deletion src/entities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export * from './webhook/index.js'
export * from './mapping/index.js'
export * from './synchronization/index.js'
export * from './source/index.js'
export * from './callLog/index.js'
export * from './callLog/index.js'
1 change: 0 additions & 1 deletion src/entities/jobLog/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './jobLog.types.ts'
export * from './jobLog.types.ts'
export * from './jobLog.mock.ts'

4 changes: 2 additions & 2 deletions src/entities/mapping/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Mapping extends ReadonlyBaseClass implements TMapping {
public readonly name: string
public readonly description: string
public readonly mapping: Record<string, unknown>
public readonly unset: any[]
public readonly unset: string[]
public readonly cast: Record<string, unknown>
public readonly passThrough: boolean
public readonly dateCreated: string
Expand Down Expand Up @@ -47,7 +47,7 @@ export class Mapping extends ReadonlyBaseClass implements TMapping {
name: z.string().max(255),
description: z.string(),
mapping: z.record(z.any()),
unset: z.array(z.any()),
unset: z.array(z.string()),
cast: z.record(z.any()),
passThrough: z.boolean(),
dateCreated: z.string().or(z.literal('')),
Expand Down
2 changes: 1 addition & 1 deletion src/entities/mapping/mapping.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type TMapping = {
name: string
description: string
mapping: Record<string, unknown>
unset: any[]
unset: string[]
cast: Record<string, unknown>
passThrough: boolean
dateCreated: string
Expand Down
2 changes: 2 additions & 0 deletions src/entities/source/source.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TSource } from './source.types'
export const mockSourceData = (): TSource[] => [
{
id: '5137a1e5-b54d-43ad-abd1-4b5bff5fcd3f',
uuid: '5137a1e5-b54d-43ad-abd1-4b5bff5fcd3f',
name: 'Test Source 1',
description: 'A test source for demonstration',
location: 'https://api.test1.com',
Expand Down Expand Up @@ -43,6 +44,7 @@ export const mockSourceData = (): TSource[] => [
},
{
id: '4c3edd34-a90d-4d2a-8894-adb5836ecde8',
uuid: '4c3edd34-a90d-4d2a-8894-adb5836ecde8',
name: 'Test Source 2',
description: 'Another test source',
location: 'https://api.test2.com',
Expand Down
3 changes: 3 additions & 0 deletions src/entities/source/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ReadonlyBaseClass from '../ReadonlyBaseClass.js'
export class Source extends ReadonlyBaseClass implements TSource {

public readonly id: string
public readonly uuid: string
public readonly name: string
public readonly description: string
public readonly reference: string
Expand Down Expand Up @@ -47,6 +48,7 @@ export class Source extends ReadonlyBaseClass implements TSource {
constructor(source: TSource) {
const processedSource: TSource = {
id: source.id || null,
uuid: source.uuid || '',
name: source.name || '',
description: source.description || '',
reference: source.reference || '',
Expand Down Expand Up @@ -91,6 +93,7 @@ export class Source extends ReadonlyBaseClass implements TSource {
public validate(): SafeParseReturnType<TSource, unknown> {
const schema = z.object({
id: z.string().nullable(),
uuid: z.string(),
name: z.string().max(255),
description: z.string(),
reference: z.string(),
Expand Down
1 change: 1 addition & 0 deletions src/entities/source/source.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
export type TSource = {
id: string
uuid: string
name: string
description: string
reference: string
Expand Down
2 changes: 1 addition & 1 deletion src/modals/Endpoint/DeleteEndpoint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { endpointStore, navigationStore } from '../../store/store.js'
size="normal"
:can-close="false">
<p v-if="!success">
Do you want to delete <b>{{ endpointStore.endpointItem.name }}</b>? This action cannot be undone.
Do you want to delete <b>{{ endpointStore.endpointItem?.name }}</b>? This action cannot be undone.
</p>

<NcNoteCard v-if="success" type="success">
Expand Down
8 changes: 2 additions & 6 deletions src/modals/JobArgument/DeleteJobArgument.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { navigationStore, jobStore } from '../../store/store.js'
Do you want to delete <b>{{ jobStore.jobArgumentKey }}</b>? This action cannot be undone.
</p>
<template #actions>
<NcButton :disabled="loading" icon="" @click="navigationStore.setModal(false)">
<NcButton :disabled="loading" icon="" @click="closeModal">
<template #icon>
<Cancel :size="20" />
</template>
Expand Down Expand Up @@ -94,11 +94,7 @@ export default {
this.success = true

// Wait for the user to read the feedback then close the model
const self = this
this.closeTimeoutFunc = setTimeout(function() {
self.success = null
navigationStore.setModal(false)
}, 2000)
this.closeTimeoutFunc = setTimeout(this.closeModal, 2000)
})
.catch((err) => {
this.error = err
Expand Down
5 changes: 3 additions & 2 deletions src/modals/MappingTest/TestMapping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { navigationStore } from '../../store/store.js'
@mapping-selected="receiveMappingSelected"
@mapping-test="receiveMappingTest" />
<TestMappingResult ref="mappingResultRef"
:mapping-test="mappingTest" />
:mapping-test="mappingTest"
:schema="schema" />
</div>
</div>
</NcModal>
Expand Down Expand Up @@ -82,7 +83,7 @@ export default {
value.error !== undefined && (this.mappingTest.error = value.error) // boolean / string
},
receiveSchemaSelected(value) {
value.selected && (this.schema.selected = value.selected)
value?.selected !== undefined && (this.schema.selected = value.selected)
value.schemas && (this.schema.schemas = value.schemas)
value.success !== undefined && (this.schema.success = value.success) // boolean
value.loading !== undefined && (this.schema.loading = value.loading) // boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ import { mappingStore } from '../../../store/store.js'
:error="!validJson(mappingItem.cast, true)"
:helper-text="!validJson(mappingItem.cast, true) ? 'Invalid JSON' : ''" />

<NcTextArea :value.sync="mappingItem.unset"
label="unset"
helper-text="Enter a comma-separated list of keys." />

<div class="buttons">
<NcButton class="reset-button"
type="secondary"
Expand Down Expand Up @@ -229,6 +233,7 @@ export default {
description: '',
mapping: '{}',
cast: '{}',
unset: '', // array as string
},
// use uniqueMappingId as the "No mapping" option's ID to avoid any possible truthy comparisons
uniqueMappingId: Symbol('No Mapping'), // Symbol creates a truly unique value, so unique making 2 of the same symbol will never be the same.
Expand Down Expand Up @@ -296,12 +301,14 @@ export default {
description: '',
mapping: '{}',
cast: '{}',
unset: '',
}
} else {
this.mappingItem.name = this.mappings.value.fullMapping.name
this.mappingItem.description = this.mappings.value.fullMapping.description
this.mappingItem.mapping = JSON.stringify(this.mappings.value.fullMapping.mapping, null, 2)
this.mappingItem.cast = JSON.stringify(this.mappings.value.fullMapping.cast, null, 2)
this.mappingItem.unset = this.mappings.value.fullMapping.unset.join(', ') // turn the array into a string
}
},
async fetchMappings(currentMappingItem = null) {
Expand Down Expand Up @@ -419,6 +426,7 @@ export default {
description: this.mappingItem.description,
mapping: JSON.parse(this.mappingItem.mapping),
cast: this.mappingItem.cast ? JSON.parse(this.mappingItem.cast) : null,
unset: this.mappingItem.unset.split(/ *, */g),
},
inputObject: JSON.parse(this.inputObject.value),
schema: this.schemas.value?.id,
Expand All @@ -443,6 +451,7 @@ export default {
description: this.mappingItem.description,
mapping: JSON.parse(this.mappingItem.mapping),
cast: JSON.parse(this.mappingItem.cast),
unset: this.mappingItem.unset.split(/ *, */g),
})

mappingStore.saveMapping(newMappingItem)
Expand Down
Loading
Loading