Skip to content

Commit ab3853e

Browse files
committed
wip: split out secretSettingsStatus
1 parent 042adfd commit ab3853e

File tree

7 files changed

+63
-21
lines changed

7 files changed

+63
-21
lines changed

meteor/server/api/peripheralDevice.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export namespace ServerPeripheralDeviceAPI {
533533
$set: {
534534
accessTokenUrl: '',
535535
'secretSettings.accessToken': accessToken,
536-
'settings.secretAccessToken': true,
536+
'secretSettingsStatus.accessToken': true,
537537
},
538538
})
539539
}
@@ -634,7 +634,7 @@ peripheralDeviceRouter.post('/:deviceId/uploadCredentials', bodyParser(), async
634634
await PeripheralDevices.updateAsync(peripheralDevice._id, {
635635
$set: {
636636
'secretSettings.credentials': body,
637-
'settings.secretCredentials': true, // nocommit - fix me
637+
'secretSettingsStatus.credentials': true,
638638
},
639639
})
640640

@@ -705,7 +705,7 @@ peripheralDeviceRouter.post('/:deviceId/resetAuth', async (ctx) => {
705705
$unset: {
706706
// User credentials
707707
'secretSettings.accessToken': true,
708-
'settings.secretAccessToken': true, // nocommit - fix me
708+
'secretSettingsStatus.accessToken': true,
709709
accessTokenUrl: true,
710710
},
711711
})
@@ -735,10 +735,10 @@ peripheralDeviceRouter.post('/:deviceId/resetAppCredentials', async (ctx) => {
735735
$unset: {
736736
// App credentials
737737
'secretSettings.credentials': true,
738-
'settings.secretCredentials': true, // nocommit - fix me
738+
'secretSettingsStatus.credentials': true,
739739
// User credentials
740740
'secretSettings.accessToken': true,
741-
'settings.secretAccessToken': true, // nocommit - fix me
741+
'secretSettingsStatus.accessToken': true,
742742
accessTokenUrl: true,
743743
},
744744
})

meteor/server/migration/X_X_X.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import { StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
1616
import { literal, unprotectString } from '../lib/tempLib'
1717
import { logger } from '../logging'
18+
import { IngestDeviceSecretSettingsStatus } from '@sofie-automation/corelib/src/dataModel/PeripheralDeviceSettings/ingestDevice'
1819

1920
/*
2021
* **************************************************************************************
@@ -230,9 +231,53 @@ export const addSteps = addMigrationSteps(CURRENT_SYSTEM_VERSION, [
230231
},
231232

232233
{
233-
id: `move PeripheralDevice settings to studio`,
234+
id: `PeripheralDevice populate secretSettingsStatus`,
234235
canBeRunAutomatically: true,
235236
dependOnResultFrom: `studios create peripheralDeviceSettings.deviceSettings`,
237+
validate: async () => {
238+
const devices = await PeripheralDevices.findFetchAsync({
239+
secretSettings: { $exists: true },
240+
settings: { $exists: true },
241+
secretSettingsStatus: { $exists: false },
242+
})
243+
244+
if (devices.length > 0) {
245+
return 'settings must be moved to the studio'
246+
}
247+
248+
return false
249+
},
250+
migrate: async () => {
251+
const devices = await PeripheralDevices.findFetchAsync({
252+
secretSettings: { $exists: true },
253+
settings: { $exists: true },
254+
secretSettingsStatus: { $exists: false },
255+
})
256+
257+
for (const device of devices) {
258+
// @ts-expect-error settings is typed as Record<string, any>
259+
const oldSettings = device.settings as IngestDeviceSecretSettingsStatus | undefined
260+
261+
await PeripheralDevices.updateAsync(device._id, {
262+
$set: {
263+
secretSettingsStatus: {
264+
secretCredentials: oldSettings?.secretCredentials,
265+
secretAccessToken: oldSettings?.secretAccessToken,
266+
},
267+
},
268+
$unset: {
269+
'settings.secretCredentials': 1,
270+
'settings.secretAccessToken': 1,
271+
},
272+
})
273+
}
274+
},
275+
},
276+
277+
{
278+
id: `move PeripheralDevice settings to studio`,
279+
canBeRunAutomatically: true,
280+
dependOnResultFrom: `PeripheralDevice populate secretSettingsStatus`,
236281
validate: async () => {
237282
const devices = await PeripheralDevices.findFetchAsync({
238283
studioId: { $exists: true },

packages/corelib/src/dataModel/PeripheralDevice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
PeripheralDeviceSubType,
1111
PERIPHERAL_SUBTYPE_PROCESS,
1212
} from '@sofie-automation/shared-lib/dist/peripheralDevice/peripheralDeviceAPI'
13+
import { IngestDeviceSecretSettingsStatus } from '@sofie-automation/corelib/src/dataModel/PeripheralDeviceSettings/ingestDevice'
1314

1415
export {
1516
PeripheralDeviceStatusObject,
@@ -44,8 +45,6 @@ export interface PeripheralDevice {
4445
created: number
4546
status: PeripheralDeviceStatusObject
4647

47-
// settings: IngestDeviceSettings | GenericPeripheralDeviceSettings
48-
4948
/** If set, this device is owned by that organization */
5049
organizationId: OrganizationId | null
5150

@@ -68,6 +67,7 @@ export interface PeripheralDevice {
6867
token: string
6968

7069
secretSettings?: IngestDeviceSecretSettings | { [key: string]: any }
70+
secretSettingsStatus?: IngestDeviceSecretSettingsStatus
7171

7272
/** If the device is of category ingest, the name of the NRCS being used */
7373
nrcsName?: string
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export * from '@sofie-automation/shared-lib/dist/peripheralDevice/ingest'
22

33
export {
4-
IngestDeviceSettings,
4+
IngestDeviceSecretSettingsStatus,
55
IngestDeviceSecretSettings,
66
} from '@sofie-automation/shared-lib/dist/core/model/peripheralDevice'

packages/corelib/src/dataModel/Studio.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ import {
1515
StudioAbPlayerDisabling,
1616
} from '@sofie-automation/shared-lib/dist/core/model/StudioRouteSet'
1717
import { StudioPackageContainer } from '@sofie-automation/shared-lib/dist/core/model/PackageContainer'
18-
import {
19-
GenericPeripheralDeviceSettings,
20-
IngestDeviceSettings,
21-
} from '@sofie-automation/shared-lib/dist/core/model/peripheralDevice'
18+
import { GenericPeripheralDeviceSettings } from '@sofie-automation/shared-lib/dist/core/model/peripheralDevice'
2219

2320
export { MappingsExt, MappingExt, MappingsHash }
2421

@@ -200,5 +197,5 @@ export interface StudioDeviceSettings {
200197
*/
201198
name: string
202199

203-
options: IngestDeviceSettings | GenericPeripheralDeviceSettings
200+
options: GenericPeripheralDeviceSettings
204201
}

packages/shared-lib/src/core/model/peripheralDevice.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { PeripheralDeviceId, StudioId } from './Ids'
33

44
export type GenericPeripheralDeviceSettings = Record<string, never>
55

6-
export interface IngestDeviceSettings {
6+
export interface IngestDeviceSecretSettingsStatus {
77
/** OAuth: Set to true when secret value exists */
8-
secretCredentials: boolean
9-
secretAccessToken: boolean
8+
credentials?: boolean
9+
accessToken?: boolean
1010
}
1111
export interface IngestDeviceSecretSettings {
1212
/** OAuth: */

packages/webui/src/client/ui/Settings/components/ConfigManifestOAuthFlow.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import { withTranslation } from 'react-i18next'
33
import { PeripheralDevice } from '@sofie-automation/corelib/dist/dataModel/PeripheralDevice'
44
import { Translated } from '../../../lib/ReactMeteorData/react-meteor-data'
5-
import { IngestDeviceSettings } from '@sofie-automation/corelib/dist/dataModel/PeripheralDeviceSettings/ingestDevice'
5+
import { IngestDeviceSecretSettingsStatus } from '@sofie-automation/corelib/dist/dataModel/PeripheralDeviceSettings/ingestDevice'
66
import { NotificationCenter, Notification, NoticeLevel } from '../../../lib/notifications/notifications'
77
import { fetchFrom } from '../../../lib/lib'
88

@@ -126,12 +126,12 @@ export const ConfigManifestOAuthFlowComponent = withTranslation()(
126126

127127
render(): JSX.Element {
128128
const { t } = this.props
129-
const settings = (this.props.device.settings || {}) as IngestDeviceSettings
129+
const secretStatus = (this.props.device.secretSettingsStatus || {}) as IngestDeviceSecretSettingsStatus
130130
const device = this.props.device
131131

132132
return (
133133
<div>
134-
{settings.secretAccessToken ? (
134+
{secretStatus.accessToken ? (
135135
// If this is set, we have completed the authentication procedure.
136136
// A reset button is provided to begin the flow again if authorization is revoked by the user.
137137
<div className="mod mvs mhs">
@@ -145,7 +145,7 @@ export const ConfigManifestOAuthFlowComponent = withTranslation()(
145145
</div>
146146
) : (
147147
<div className="mod mvs mhs">
148-
{!settings.secretCredentials ? (
148+
{!secretStatus.credentials ? (
149149
<label className="field">
150150
<div className="mvs">{t('Application credentials')}</div>
151151
<div className="mdi">

0 commit comments

Comments
 (0)