diff --git a/src/features/ci-cd/hooks/app-update-trigger.ts b/src/features/ci-cd/hooks/app-update-trigger.ts index 6012836feb..2bf687ecb6 100644 --- a/src/features/ci-cd/hooks/app-update-trigger.ts +++ b/src/features/ci-cd/hooks/app-update-trigger.ts @@ -21,7 +21,7 @@ hooks.addPureHook('PATCH', 'resin', 'application', { is_running__release: { $ne: request.values.should_be_running__release, }, - should_be_running__release: null, + is_pinned_on__release: null, }, wait: false, }); diff --git a/src/features/ci-cd/hooks/device-update-trigger.ts b/src/features/ci-cd/hooks/device-update-trigger.ts index 8cace452d9..425c154d54 100644 --- a/src/features/ci-cd/hooks/device-update-trigger.ts +++ b/src/features/ci-cd/hooks/device-update-trigger.ts @@ -11,7 +11,7 @@ hooks.addPureHook('PATCH', 'resin', 'device', { // * target release changed // * device name changed - so a user can restart their service and it will pick up the change if ( - (request.values.should_be_running__release !== undefined || + (request.values.is_pinned_on__release !== undefined || request.values.belongs_to__application != null || request.values.device_name != null) && affectedIds.length !== 0 diff --git a/src/features/ci-cd/hooks/service-installs.ts b/src/features/ci-cd/hooks/service-installs.ts index 81a5849a86..d62c94a849 100644 --- a/src/features/ci-cd/hooks/service-installs.ts +++ b/src/features/ci-cd/hooks/service-installs.ts @@ -189,7 +189,7 @@ hooks.addPureHook('PATCH', 'resin', 'application', { api, { belongs_to__application: { $in: affectedIds }, - should_be_running__release: null, + is_pinned_on__release: null, }, { id: request.values.should_be_running__release, @@ -236,14 +236,14 @@ hooks.addPureHook('PATCH', 'resin', 'device', { POSTRUN: async ({ api, request }) => { const affectedIds = request.affectedIds!; if ( - request.values.should_be_running__release !== undefined && + request.values.is_pinned_on__release !== undefined && affectedIds.length !== 0 ) { // If the device was preloaded, and then pinned, service_installs do not exist // for this device+release combination. We need to create these - if (request.values.should_be_running__release != null) { + if (request.values.is_pinned_on__release != null) { await createReleaseServiceInstalls(api, affectedIds, { - id: request.values.should_be_running__release, + id: request.values.is_pinned_on__release, }); } else { const devices = (await api.get({ diff --git a/src/features/device-state/state-get-utils.ts b/src/features/device-state/state-get-utils.ts index 89155333b1..cc875dabc5 100644 --- a/src/features/device-state/state-get-utils.ts +++ b/src/features/device-state/state-get-utils.ts @@ -65,8 +65,8 @@ export const getConfig = ( export const getReleaseForDevice = ( device: AnyObject, ): AnyObject | undefined => { - if (device.should_be_running__release[0] != null) { - return device.should_be_running__release[0]; + if (device.is_pinned_on__release[0] != null) { + return device.is_pinned_on__release[0]; } return device.belongs_to__application[0]?.should_be_running__release[0]; }; diff --git a/src/features/devices/hooks/defaults-validation.ts b/src/features/devices/hooks/defaults-validation.ts index c79f7f5055..9946d1f055 100644 --- a/src/features/devices/hooks/defaults-validation.ts +++ b/src/features/devices/hooks/defaults-validation.ts @@ -31,12 +31,12 @@ hooks.addPureHook('POST', 'resin', 'device', { } // TODO[device management next step]: Drop this after re-migrating all data on step 2: - if (request.values.should_be_running__release !== undefined) { + if (request.values.is_pinned_on__release !== undefined) { // Add an async boundary so that value updates, // and doesn't remove the properties that we add. await null; - request.values.is_pinned_on__release = - request.values.should_be_running__release; + request.values.should_be_running__release = + request.values.is_pinned_on__release; } }, }); @@ -69,9 +69,9 @@ hooks.addPureHook('PATCH', 'resin', 'device', { // build has been targeted, instead of pointing to a build of the wrong application if ( request.values.belongs_to__application != null && - request.values.should_be_running__release === undefined + request.values.is_pinned_on__release === undefined ) { - request.values.should_be_running__release = null; + request.values.is_pinned_on__release = null; } if (request.values.is_connected_to_vpn != null) { @@ -84,12 +84,12 @@ hooks.addPureHook('PATCH', 'resin', 'device', { } // TODO[device management next step]: Drop this after re-migrating all data on step 2: - if (request.values.should_be_running__release !== undefined) { + if (request.values.is_pinned_on__release !== undefined) { // Add an async boundary so that value updates, // and doesn't remove the properties that we add. await null; - request.values.is_pinned_on__release = - request.values.should_be_running__release; + request.values.should_be_running__release = + request.values.is_pinned_on__release; } }, }); diff --git a/src/features/releases/hooks/restrict-release-deletion.ts b/src/features/releases/hooks/restrict-release-deletion.ts index 168a125148..94bf3dce65 100644 --- a/src/features/releases/hooks/restrict-release-deletion.ts +++ b/src/features/releases/hooks/restrict-release-deletion.ts @@ -40,7 +40,7 @@ hooks.addPureHook('DELETE', 'resin', 'release', { $top: 1, $select: 'id', $filter: { - should_be_running__release: { $in: affectedIds }, + is_pinned_on__release: { $in: affectedIds }, }, }, })) as Array>; diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 951ae5aba3..4c04b3bbd8 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -95,7 +95,7 @@ export const DEVICE_API_KEY_PERMISSIONS = [ `device/any(d:${matchesNonFrozenDeviceActor('d')})`, ), 'resin.application_config_variable.read?application/canAccess()', - 'resin.release.read?should_be_running_on__device/canAccess() or belongs_to__application/canAccess()', + 'resin.release.read?is_pinned_to__device/canAccess() or belongs_to__application/canAccess()', 'resin.release_tag.read?release/canAccess()', 'resin.device_environment_variable.read?device/canAccess()', ...writePerms( diff --git a/test/14_release-pinning.ts b/test/14_release-pinning.ts index c9856eba0f..b3eabd1949 100644 --- a/test/14_release-pinning.ts +++ b/test/14_release-pinning.ts @@ -33,6 +33,9 @@ export default () => { let device4: fakeDevice.Device; let device5: fakeDevice.Device; let applicationToDelete: Application['Read']; + const pinnedOnReleaseField = versions.gt(version, 'v6') + ? 'is_pinned_on__release' + : 'should_be_running__release'; before(async () => { fx = await fixtures.load('14-release-pinning'); @@ -85,7 +88,7 @@ export default () => { await supertest(admin) .patch(`/${version}/device(${device.id})`) .send({ - should_be_running__release: pinnedRelease.id, + [pinnedOnReleaseField]: pinnedRelease.id, }) .expect(200); @@ -106,7 +109,7 @@ export default () => { await supertest(admin) .patch(`/${version}/device(${device.id})`) .send({ - should_be_running__release: null, + [pinnedOnReleaseField]: null, }) .expect(200); }); @@ -464,7 +467,7 @@ export default () => { await supertest(device4) .patch(`/${version}/device(${device4.id})`) .send({ - should_be_running__release: app3ReleaseId, + [pinnedOnReleaseField]: app3ReleaseId, }) .expect(200); @@ -491,7 +494,7 @@ export default () => { await supertest(device4) .patch(`/${version}/device(${device4.id})`) .send({ - should_be_running__release: app3ReleaseId, + [pinnedOnReleaseField]: app3ReleaseId, }) .expect(200); }, @@ -579,7 +582,7 @@ export default () => { it('should not be able to delete a release if a device is pinned to it', async function () { await supertest(admin) .patch(`/${version}/device(${device4.id})`) - .send({ should_be_running__release: app4ReleaseId }); + .send({ [pinnedOnReleaseField]: app4ReleaseId }); await supertest(admin) .delete(`/${version}/release(${app4ReleaseId})`) .expect( diff --git a/test/scenarios/unpin-device-after-release.ts b/test/scenarios/unpin-device-after-release.ts index 710921e44f..cec24c9f5e 100644 --- a/test/scenarios/unpin-device-after-release.ts +++ b/test/scenarios/unpin-device-after-release.ts @@ -81,7 +81,7 @@ export default () => { await supertest(admin) .patch(`/${version}/device(${device.id})`) .send({ - should_be_running__release: releases['deadbeef'], + is_pinned_on__release: releases['deadbeef'], }) .expect(200); @@ -163,7 +163,7 @@ export default () => { await supertest(admin) .patch(`/${version}/device(${device.id})`) .send({ - should_be_running__release: null, + is_pinned_on__release: null, }) .expect(200); });