From 9437217e3624a318405a127066281a865bcb07d0 Mon Sep 17 00:00:00 2001 From: Florian Maunier Date: Tue, 23 Jul 2024 10:42:33 +0200 Subject: [PATCH 1/2] ci(doc): fix major version in CI doc step --- .github/workflows/push_branches.workflow.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/push_branches.workflow.yaml b/.github/workflows/push_branches.workflow.yaml index a3bc8134..a4d65950 100644 --- a/.github/workflows/push_branches.workflow.yaml +++ b/.github/workflows/push_branches.workflow.yaml @@ -47,6 +47,14 @@ jobs: with: token: ${{ secrets.ACCESS_TOKEN_CI }} + - name: Extract references from context + shell: bash + id: extract-refs + run: | + version=$(jq -r .version package.json | cut -d. -f 1) + echo "major-version=$(($version == 0 ? 1 : $version))" >> $GITHUB_OUTPUT + echo "repo=$(echo $GITHUB_REPOSITORY | cut -d/ -f 2)" >> $GITHUB_OUTPUT + - uses: convictional/trigger-workflow-and-wait@v1.6.3 with: owner: kuzzleio @@ -54,4 +62,4 @@ jobs: github_token: ${{ secrets.ACCESS_TOKEN_CI }} workflow_file_name: child_repo.workflow.yml ref: ${{ github.ref_name == 'master' && 'master' || 'develop' }} - client_payload: '{"repo_name":"kuzzle-plugin-device-manager","branch":"${{ github.ref_name }}","version":"1"}' + client_payload: '{"repo_name":"${{ steps.extract-refs.outputs.repo }}","branch":"${{ github.ref_name }}","version":"${{ steps.extract-refs.outputs.major-version }}"}' From b9164b2477fdd02cf82ca3f21ce659865ffe030e Mon Sep 17 00:00:00 2001 From: Quentin Date: Thu, 21 Nov 2024 15:56:55 +0100 Subject: [PATCH 2/2] feat(deviceservice): add hook on tenant deletion to set its devices as orphans --- lib/modules/device/DeviceService.ts | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/modules/device/DeviceService.ts b/lib/modules/device/DeviceService.ts index 3a71d968..f62dd234 100644 --- a/lib/modules/device/DeviceService.ts +++ b/lib/modules/device/DeviceService.ts @@ -80,6 +80,43 @@ export class DeviceService extends DigitalTwinService { await this.attachEngine(engineId, deviceId, request); }, ); + + /** + * On deletion of a tenant, remove association for all of + * its formerly linked devices in the admin index. + */ + this.app.hook.register( + "multi-tenancy/tenant:afterDelete", + async (request) => { + const { group, name } = request.input.args; + const tenantIndex = `tenant-${group}-${name}`; + const devices = []; + + let result = await this.sdk.document.search( + this.config.adminIndex, + "devices", + { + _source: false, + query: { bool: { must: { term: { engineId: tenantIndex } } } }, + }, + { + scroll: "2s", + size: 100, + }, + ); + while (result !== null) { + devices.push(...result.hits); + result = await result.next(); + } + void this.sdk.document.mUpdate( + this.config.adminIndex, + "devices", + devices.map((device) => { + return { _id: device._id, body: { assetId: null, engineId: null } }; + }), + ); + }, + ); } /**