Skip to content

Commit 61055a9

Browse files
committed
wip: fixup nocommits
1 parent ab3853e commit 61055a9

File tree

7 files changed

+73
-35
lines changed

7 files changed

+73
-35
lines changed

meteor/server/api/rest/v1/studios.ts

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ import { runUpgradeForStudio, validateConfigForStudio } from '../../../migration
1313
import { NoteSeverity } from '@sofie-automation/blueprints-integration'
1414
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
1515
import { ServerClientAPI } from '../../client'
16-
import { assertNever } from '../../../lib/tempLib'
16+
import { assertNever, literal } from '../../../lib/tempLib'
1717
import { getCurrentTime } from '../../../lib/lib'
1818
import { StudioJobs } from '@sofie-automation/corelib/dist/worker/studio'
19-
import { DBStudio } from '@sofie-automation/corelib/dist/dataModel/Studio'
19+
import { DBStudio, StudioDeviceSettings } from '@sofie-automation/corelib/dist/dataModel/Studio'
2020
import { PeripheralDevice } from '@sofie-automation/corelib/dist/dataModel/PeripheralDevice'
2121
import { ServerPlayoutAPI } from '../../playout/playout'
2222
import { assertConnectionHasOneOfPermissions } from '../../../security/auth'
2323
import { UserPermissions } from '@sofie-automation/meteor-lib/dist/userPermissions'
24+
import {
25+
applyAndValidateOverrides,
26+
ObjectOverrideSetOp,
27+
} from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
2428

2529
const PERMISSIONS_FOR_PLAYOUT_USERACTION: Array<keyof UserPermissions> = ['studio']
2630

@@ -213,7 +217,8 @@ class StudiosServerAPI implements StudiosRestAPI {
213217
_connection: Meteor.Connection,
214218
_event: string,
215219
studioId: StudioId,
216-
deviceId: PeripheralDeviceId
220+
deviceId: PeripheralDeviceId,
221+
configId: string | undefined
217222
): Promise<ClientAPI.ClientResponse<void>> {
218223
const studio = await Studios.findOneAsync(studioId)
219224
if (!studio)
@@ -238,9 +243,33 @@ class StudiosServerAPI implements StudiosRestAPI {
238243
412
239244
)
240245
}
246+
247+
// If no configId is provided, use the id of the device
248+
configId = configId || unprotectString(device._id)
249+
250+
// Ensure that the requested config blob exists
251+
const availableDeviceSettings = applyAndValidateOverrides(studio.peripheralDeviceSettings.deviceSettings).obj
252+
if (!availableDeviceSettings[configId]) {
253+
await Studios.updateAsync(studioId, {
254+
$push: {
255+
'peripheralDeviceSettings.deviceSettings.overrides': literal<ObjectOverrideSetOp>({
256+
op: 'set',
257+
path: configId,
258+
value: literal<StudioDeviceSettings>({
259+
name: device.name,
260+
options: {},
261+
}),
262+
}),
263+
},
264+
})
265+
}
266+
241267
await PeripheralDevices.updateAsync(deviceId, {
242268
$set: {
243-
studioId, // nocommit - this
269+
studioAndConfigId: {
270+
studioId,
271+
configId,
272+
},
244273
},
245274
})
246275

@@ -259,11 +288,17 @@ class StudiosServerAPI implements StudiosRestAPI {
259288
UserError.from(new Error(`Studio does not exist`), UserErrorMessage.StudioNotFound),
260289
404
261290
)
262-
await PeripheralDevices.updateAsync(deviceId, {
263-
$unset: {
264-
studioId: 1, // nocommit - this
291+
await PeripheralDevices.updateAsync(
292+
{
293+
_id: deviceId,
294+
'studioAndConfigId.studioId': studioId,
265295
},
266-
})
296+
{
297+
$unset: {
298+
studioAndConfigId: 1,
299+
},
300+
}
301+
)
267302

268303
return ClientAPI.responseSuccess(undefined, 200)
269304
}
@@ -392,7 +427,7 @@ export function registerRoutes(registerRoute: APIRegisterHook<StudiosRestAPI>):
392427
}
393428
)
394429

395-
registerRoute<{ studioId: string }, { deviceId: string }, void>(
430+
registerRoute<{ studioId: string }, { deviceId: string; configId: string | undefined }, void>(
396431
'put',
397432
'/studios/:studioId/devices',
398433
new Map([
@@ -403,9 +438,10 @@ export function registerRoutes(registerRoute: APIRegisterHook<StudiosRestAPI>):
403438
async (serverAPI, connection, events, params, body) => {
404439
const studioId = protectString<StudioId>(params.studioId)
405440
const deviceId = protectString<PeripheralDeviceId>(body.deviceId)
406-
logger.info(`API PUT: Attach device ${deviceId} to studio ${studioId}`)
441+
const configId = body.configId
442+
logger.info(`API PUT: Attach device ${deviceId} to studio ${studioId} (${configId})`)
407443

408-
return await serverAPI.attachDeviceToStudio(connection, events, studioId, deviceId)
444+
return await serverAPI.attachDeviceToStudio(connection, events, studioId, deviceId, configId)
409445
}
410446
)
411447

meteor/server/collections/collection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export interface AsyncOnlyMongoCollection<DBInterface extends { _id: ProtectedSt
149149
* @param options Options for the operation
150150
*/
151151
updateAsync(
152-
selector: DBInterface['_id'] | { _id: DBInterface['_id'] },
152+
selector: DBInterface['_id'] | ({ _id: DBInterface['_id'] } & MongoQuery<Omit<DBInterface, '_id'>>),
153153
modifier: MongoModifier<DBInterface>,
154154
options?: UpdateOptions
155155
): Promise<number>

meteor/server/collections/index.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,13 @@ export const PeripheralDevices = createAsyncOnlyMongoCollection<PeripheralDevice
130130
update(userId, doc, fields, _modifier) {
131131
if (!checkUserIdHasOneOfPermissions(userId, CollectionName.PeripheralDevices, 'configure')) return false
132132

133-
return rejectFields(doc, fields, [
134-
'type',
135-
'parentDeviceId',
136-
'versions',
137-
'created',
138-
'status',
139-
'lastSeen',
140-
'lastConnected',
141-
'connected',
142-
'connectionId',
143-
'token',
144-
'studioAndConfigId', // nocommit ensure this is respected
145-
// 'settings' is allowed
133+
return allowOnlyFields(doc, fields, [
134+
'name',
135+
'deviceName',
136+
'organizationId',
137+
'disableVersionChecks',
138+
'nrcsName',
139+
'ignore',
146140
])
147141
},
148142
})

meteor/server/lib/rest/v1/studios.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ export interface StudiosRestAPI {
106106
* @param event User event string
107107
* @param studioId Studio to attach to
108108
* @param deviceId Device to attach
109+
* @param configId Id of the studio owned configuration to assign to the device. If not set, one will be created.
109110
*/
110111
attachDeviceToStudio(
111112
connection: Meteor.Connection,
112113
event: string,
113114
studioId: StudioId,
114-
deviceId: PeripheralDeviceId
115+
deviceId: PeripheralDeviceId,
116+
configId: string | undefined
115117
): Promise<ClientAPI.ClientResponse<void>>
116118
/**
117119
* Detaches a device from a studio.

meteor/server/migration/1_50_0.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,9 @@ export const addSteps = addMigrationSteps('1.50.0', [
497497
'settings.devices': { $exists: true },
498498
})
499499
for (const device of objects) {
500-
if (!device.studioId) continue
500+
// @ts-expect-error removed in 1.52
501+
const studioId: StudioId = device.studioId
502+
if (!studioId) continue
501503

502504
const newOverrides: SomeObjectOverrideOp[] = []
503505

@@ -514,7 +516,7 @@ export const addSteps = addMigrationSteps('1.50.0', [
514516
)
515517
}
516518

517-
await Studios.updateAsync(device.studioId, {
519+
await Studios.updateAsync(studioId, {
518520
$set: {
519521
[`peripheralDeviceSettings.playoutDevices.overrides`]: newOverrides,
520522
},
@@ -551,7 +553,9 @@ export const addSteps = addMigrationSteps('1.50.0', [
551553
'settings.devices': { $exists: true },
552554
})
553555
for (const device of objects) {
554-
if (!device.studioId) continue
556+
// @ts-expect-error removed in 1.52
557+
const studioId: StudioId = device.studioId
558+
if (!studioId) continue
555559

556560
const newOverrides: SomeObjectOverrideOp[] = []
557561

@@ -568,7 +572,7 @@ export const addSteps = addMigrationSteps('1.50.0', [
568572
)
569573
}
570574

571-
await Studios.updateAsync(device.studioId, {
575+
await Studios.updateAsync(studioId, {
572576
$set: {
573577
[`peripheralDeviceSettings.ingestDevices.overrides`]: newOverrides,
574578
},
@@ -605,7 +609,9 @@ export const addSteps = addMigrationSteps('1.50.0', [
605609
'settings.devices': { $exists: true },
606610
})
607611
for (const device of objects) {
608-
if (!device.studioId) continue
612+
// @ts-expect-error removed in 1.52
613+
const studioId: StudioId = device.studioId
614+
if (!studioId) continue
609615

610616
const newOverrides: SomeObjectOverrideOp[] = []
611617

@@ -622,7 +628,7 @@ export const addSteps = addMigrationSteps('1.50.0', [
622628
)
623629
}
624630

625-
await Studios.updateAsync(device.studioId, {
631+
await Studios.updateAsync(studioId, {
626632
$set: {
627633
[`peripheralDeviceSettings.inputDevices.overrides`]: newOverrides,
628634
},

meteor/server/publications/peripheralDeviceForDevice.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ export function convertPeripheralDeviceForGateway(
6969
studio.peripheralDeviceSettings.deviceSettings
7070
).obj
7171
deviceSettings = allDeviceSettingsInStudio[peripheralDevice.studioAndConfigId.configId] ?? deviceSettings
72-
// Object.values<StudioDeviceSettings>(allDeviceSettingsInStudio).find(
73-
// (v) => v.peripheralDeviceId === peripheralDevice._id
74-
// )?.options ?? deviceSettings
7572
}
7673

7774
switch (peripheralDevice.category) {

packages/openapi/api/definitions/studios.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ resources:
247247
properties:
248248
deviceId:
249249
type: string
250+
configId:
251+
type: string
252+
description: Id of the studio owned configuration to assign to the device. If not specified, one will be created.
250253
required:
251254
- deviceId
252255
responses:

0 commit comments

Comments
 (0)