Skip to content

Commit b82d000

Browse files
committed
wip: rearrange
1 parent 173ffb3 commit b82d000

File tree

24 files changed

+136
-140
lines changed

24 files changed

+136
-140
lines changed

meteor/__mocks__/meteor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyE
22
import * as _ from 'underscore'
33
import { Fiber } from './Fibers'
44
import { MongoMock } from './mongo'
5+
import { USER_PERMISSIONS_HEADER } from '@sofie-automation/meteor-lib/dist/userPermissions'
56

67
let controllableDefer = false
78

@@ -122,6 +123,9 @@ export namespace MeteorMock {
122123
userId: mockUser ? mockUser._id : undefined,
123124
connection: {
124125
clientAddress: '1.1.1.1',
126+
httpHeaders: {
127+
[USER_PERMISSIONS_HEADER]: 'admin',
128+
},
125129
},
126130
unblock: () => {
127131
// noop

meteor/server/api/client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
checkAccessToRundown,
2727
VerifiedRundownForUserAction,
2828
VerifiedRundownPlaylistForUserAction,
29-
} from './lib'
29+
} from '../security/check'
3030
import { UserActionsLog } from '../collections'
3131
import { executePeripheralDeviceFunctionWithCustomTimeout } from './peripheralDevice/executeFunction'
3232
import { LeveledLogMethodFixed } from '@sofie-automation/corelib/dist/logging'
@@ -63,7 +63,7 @@ export namespace ServerClientAPI {
6363
async (userActionMetadata) => {
6464
checkArgs()
6565

66-
const playlist = await checkAccessToPlaylist(context, playlistId)
66+
const playlist = await checkAccessToPlaylist(context.connection, playlistId)
6767
return runStudioJob(playlist.studioId, jobName, jobArguments, userActionMetadata)
6868
}
6969
)
@@ -90,7 +90,7 @@ export namespace ServerClientAPI {
9090
async (userActionMetadata) => {
9191
checkArgs()
9292

93-
const rundown = await checkAccessToRundown(context, rundownId)
93+
const rundown = await checkAccessToRundown(context.connection, rundownId)
9494
return runStudioJob(rundown.studioId, jobName, jobArguments, userActionMetadata)
9595
}
9696
)
@@ -112,7 +112,7 @@ export namespace ServerClientAPI {
112112
return runUserActionInLog(context, userEvent, eventTime, methodName, args, async () => {
113113
checkArgs()
114114

115-
const playlist = await checkAccessToPlaylist(context, playlistId)
115+
const playlist = await checkAccessToPlaylist(context.connection, playlistId)
116116
return fcn(playlist)
117117
})
118118
}
@@ -133,7 +133,7 @@ export namespace ServerClientAPI {
133133
return runUserActionInLog(context, userEvent, eventTime, methodName, args, async () => {
134134
checkArgs()
135135

136-
const rundown = await checkAccessToRundown(context, rundownId)
136+
const rundown = await checkAccessToRundown(context.connection, rundownId)
137137
return fcn(rundown)
138138
})
139139
}

meteor/server/api/deviceTriggers/observer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
PreviewWrappedAdLib,
1111
} from '@sofie-automation/meteor-lib/dist/api/MountedTriggers'
1212
import { logger } from '../../logging'
13-
import { checkAccessAndGetPeripheralDevice } from '../ingest/lib'
13+
import { checkAccessAndGetPeripheralDevice } from '../../security/check'
1414
import { StudioActionManagers } from './StudioActionManagers'
1515
import { JobQueueWithClasses } from '@sofie-automation/shared-lib/dist/lib/JobQueueWithClasses'
1616
import { StudioDeviceTriggerManager } from './StudioDeviceTriggerManager'

meteor/server/api/evaluations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { fetchStudioLight } from '../optimizations'
99
import { sendSlackMessageToWebhook } from './integration/slack'
1010
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
1111
import { Evaluations, RundownPlaylists } from '../collections'
12-
import { VerifiedRundownPlaylistForUserAction } from './lib'
12+
import { VerifiedRundownPlaylistForUserAction } from '../security/check'
1313

1414
export async function saveEvaluation(
1515
_playlist: VerifiedRundownPlaylistForUserAction,

meteor/server/api/ingest/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GenericDeviceActions } from './genericDevice/actions'
66
import { PeripheralDeviceType } from '@sofie-automation/corelib/dist/dataModel/PeripheralDevice'
77
import { IngestJobs } from '@sofie-automation/corelib/dist/worker/ingest'
88
import { assertNever } from '@sofie-automation/corelib/dist/lib'
9-
import { VerifiedRundownForUserAction } from '../lib'
9+
import { VerifiedRundownForUserAction } from '../../security/check'
1010

1111
/*
1212
This file contains actions that can be performed on an ingest-device

meteor/server/api/ingest/lib.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyE
55
import { PeripheralDevice, PeripheralDeviceCategory } from '@sofie-automation/corelib/dist/dataModel/PeripheralDevice'
66
import { Rundown, RundownSourceNrcs } from '@sofie-automation/corelib/dist/dataModel/Rundown'
77
import { logger } from '../../logging'
8-
import { MethodContext } from '../methodContext'
98
import { profiler } from '../profiler'
109
import { IngestJobFunc } from '@sofie-automation/corelib/dist/worker/ingest'
1110
import { QueueIngestJob } from '../../worker/worker'
@@ -19,8 +18,6 @@ import {
1918
} from '@sofie-automation/corelib/dist/dataModel/Ids'
2019
import { PeripheralDevices } from '../../collections'
2120
import { getStudioIdFromDevice } from '../studio/lib'
22-
import { assertConnectionHasOneOfPermissions } from '../../security/auth'
23-
import { SubscriptionContext } from '../../publications/lib'
2421

2522
/**
2623
* Run an ingest operation via the worker.
@@ -64,43 +61,6 @@ export async function runIngestOperation<T extends keyof IngestJobFunc>(
6461
}
6562
}
6663

67-
/** Check Access and return PeripheralDevice, throws otherwise */
68-
export async function checkAccessAndGetPeripheralDevice(
69-
deviceId: PeripheralDeviceId,
70-
token: string | undefined,
71-
context: MethodContext | SubscriptionContext
72-
): Promise<PeripheralDevice> {
73-
const span = profiler.startSpan('lib.checkAccessAndGetPeripheralDevice')
74-
75-
assertConnectionHasOneOfPermissions(context.connection, 'gateway')
76-
77-
// If no token, we will never match
78-
if (!token) throw new Meteor.Error(401, `Not allowed access to peripheralDevice`)
79-
80-
const device = await PeripheralDevices.findOneAsync({ _id: deviceId })
81-
if (!device) throw new Meteor.Error(404, `PeripheralDevice "${deviceId}" not found`)
82-
83-
// Check if the device has a token, and if it matches:
84-
if (device.token && device.token === token) {
85-
span?.end()
86-
return device
87-
}
88-
89-
// If the device has a parent, try that for access control:
90-
const parentDevice = device.parentDeviceId ? await PeripheralDevices.findOneAsync(device.parentDeviceId) : device
91-
if (!parentDevice) throw new Meteor.Error(404, `PeripheralDevice parentDevice "${device.parentDeviceId}" not found`)
92-
93-
// Check if the parent device has a token, and if it matches:
94-
if (parentDevice.token && parentDevice.token === token) {
95-
span?.end()
96-
return device
97-
}
98-
99-
// No match for token found
100-
span?.end()
101-
throw new Meteor.Error(401, `Not allowed access to peripheralDevice`)
102-
}
103-
10464
export function getRundownId(studioId: StudioId, rundownExternalId: string): RundownId {
10565
if (!studioId) throw new Meteor.Error(500, 'getRundownId: studio not set!')
10666
if (!rundownExternalId) throw new Meteor.Error(401, 'getRundownId: rundownExternalId must be set!')

meteor/server/api/ingest/mosDevice/mosIntegration.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import { MOS } from '@sofie-automation/corelib'
22
import { logger } from '../../../logging'
3-
import {
4-
checkAccessAndGetPeripheralDevice,
5-
fetchStudioIdFromDevice,
6-
generateRundownSource,
7-
runIngestOperation,
8-
} from '../lib'
3+
import { fetchStudioIdFromDevice, generateRundownSource, runIngestOperation } from '../lib'
94
import { parseMosString } from './lib'
105
import { MethodContext } from '../../methodContext'
116
import { profiler } from '../../profiler'
127
import { IngestJobs } from '@sofie-automation/corelib/dist/worker/ingest'
138
import { PeripheralDeviceId } from '@sofie-automation/corelib/dist/dataModel/Ids'
9+
import { checkAccessAndGetPeripheralDevice } from '../../../security/check'
1410

1511
const apmNamespace = 'mosIntegration'
1612

meteor/server/api/ingest/rundownInput.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ import { lazyIgnore } from '../../lib/lib'
77
import { IngestRundown, IngestSegment, IngestPart, IngestPlaylist } from '@sofie-automation/blueprints-integration'
88
import { logger } from '../../logging'
99
import { RundownIngestDataCache } from './ingestCache'
10-
import {
11-
checkAccessAndGetPeripheralDevice,
12-
fetchStudioIdFromDevice,
13-
generateRundownSource,
14-
runIngestOperation,
15-
} from './lib'
10+
import { fetchStudioIdFromDevice, generateRundownSource, runIngestOperation } from './lib'
1611
import { MethodContext } from '../methodContext'
1712
import { IngestJobs } from '@sofie-automation/corelib/dist/worker/ingest'
1813
import { MediaObject } from '@sofie-automation/shared-lib/dist/core/model/MediaObjects'
1914
import { PeripheralDeviceId, RundownId, SegmentId, StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2015
import { NrcsIngestCacheType } from '@sofie-automation/corelib/dist/dataModel/NrcsIngestDataCache'
2116
import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyError'
17+
import { checkAccessAndGetPeripheralDevice } from '../../security/check'
2218

2319
export namespace RundownInput {
2420
export async function dataPlaylistGet(

meteor/server/api/integration/expectedPackages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { check } from '../../lib/check'
22
import { Meteor } from 'meteor/meteor'
33
import { MethodContext } from '../methodContext'
4-
import { checkAccessAndGetPeripheralDevice } from '../ingest/lib'
4+
import { checkAccessAndGetPeripheralDevice } from '../../security/check'
55
import { ExpectedPackageStatusAPI, PackageInfo } from '@sofie-automation/blueprints-integration'
66
import { ExpectedPackageWorkStatus } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackageWorkStatuses'
77
import { assertNever, literal, protectString } from '../../lib/tempLib'

meteor/server/api/integration/media-scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Meteor } from 'meteor/meteor'
22
import { protectString } from '../../lib/tempLib'
3-
import { checkAccessAndGetPeripheralDevice } from '../ingest/lib'
3+
import { checkAccessAndGetPeripheralDevice } from '../../security/check'
44
import { MethodContext } from '../methodContext'
55
import { MediaObject } from '@sofie-automation/shared-lib/dist/core/model/MediaObjects'
66
import { MediaObjId, PeripheralDeviceId } from '@sofie-automation/corelib/dist/dataModel/Ids'

0 commit comments

Comments
 (0)