@@ -7,35 +7,30 @@ import { ClientAPI, NewClientAPI, ClientAPIMethods } from '@sofie-automation/met
77import { UserActionsLogItem } from '@sofie-automation/meteor-lib/dist/collections/UserActionsLog'
88import { registerClassToMeteorMethods } from '../methods'
99import { MethodContext , MethodContextAPI } from './methodContext'
10- import { Settings } from '../Settings'
11- import { resolveCredentials } from '../security/lib/credentials'
1210import { isInTestWrite , triggerWriteAccessBecauseNoCheckNecessary } from '../security/lib/securityVerify'
13- import { PeripheralDeviceContentWriteAccess } from '../security/peripheralDevice'
1411import { endTrace , sendTrace , startTrace } from './integration/influx'
1512import { interpollateTranslation , translateMessage } from '@sofie-automation/corelib/dist/TranslatableMessage'
1613import { UserError } from '@sofie-automation/corelib/dist/error'
1714import { StudioJobFunc } from '@sofie-automation/corelib/dist/worker/studio'
1815import { QueueStudioJob } from '../worker/worker'
1916import { profiler } from './profiler'
2017import {
21- OrganizationId ,
2218 PeripheralDeviceId ,
2319 RundownId ,
2420 RundownPlaylistId ,
2521 StudioId ,
2622 UserActionsLogItemId ,
27- UserId ,
2823} from '@sofie-automation/corelib/dist/dataModel/Ids'
2924import {
3025 checkAccessToPlaylist ,
3126 checkAccessToRundown ,
3227 VerifiedRundownForUserAction ,
3328 VerifiedRundownPlaylistForUserAction ,
3429} from './lib'
35- import { BasicAccessContext } from '../security/organization'
3630import { UserActionsLog } from '../collections'
3731import { executePeripheralDeviceFunctionWithCustomTimeout } from './peripheralDevice/executeFunction'
3832import { LeveledLogMethodFixed } from '@sofie-automation/corelib/dist/logging'
33+ import { assertConnectionHasOneOfPermissions } from '../security/auth'
3934
4035function rewrapError ( methodName : string , e : any ) : ClientAPI . ClientResponseError {
4136 const userError = UserError . fromUnknown ( e )
@@ -65,7 +60,7 @@ export namespace ServerClientAPI {
6560 eventTime ,
6661 `worker.${ jobName } ` ,
6762 jobArguments as any ,
68- async ( _credentials , userActionMetadata ) => {
63+ async ( userActionMetadata ) => {
6964 checkArgs ( )
7065
7166 const playlist = await checkAccessToPlaylist ( context , playlistId )
@@ -92,7 +87,7 @@ export namespace ServerClientAPI {
9287 eventTime ,
9388 `worker.${ jobName } ` ,
9489 jobArguments as any ,
95- async ( _credentials , userActionMetadata ) => {
90+ async ( userActionMetadata ) => {
9691 checkArgs ( )
9792
9893 const rundown = await checkAccessToRundown ( context , rundownId )
@@ -185,11 +180,11 @@ export namespace ServerClientAPI {
185180 eventTime : Time ,
186181 methodName : string ,
187182 methodArgs : Record < string , unknown > ,
188- fcn : ( credentials : BasicAccessContext , userActionMetadata : UserActionMetadata ) => Promise < TRes >
183+ fcn : ( userActionMetadata : UserActionMetadata ) => Promise < TRes >
189184 ) : Promise < ClientAPI . ClientResponse < TRes > > {
190185 // If we are in the test write auth check mode, then bypass all special logic to ensure errors dont get mangled
191186 if ( isInTestWrite ( ) ) {
192- const result = await fcn ( { organizationId : null , userId : null } , { } )
187+ const result = await fcn ( { } )
193188 return ClientAPI . responseSuccess ( result )
194189 }
195190
@@ -203,23 +198,21 @@ export namespace ServerClientAPI {
203198 // Called internally from server-side.
204199 // Just run and return right away:
205200 try {
206- const result = await fcn ( { organizationId : null , userId : null } , { } )
201+ const result = await fcn ( { } )
207202
208203 return ClientAPI . responseSuccess ( result )
209204 } catch ( e ) {
210205 return rewrapError ( methodName , e )
211206 }
212207 } else {
213- const credentials = await getLoggedInCredentials ( context )
214-
215208 // Start the db entry, but don't wait for it
216209 const actionId : UserActionsLogItemId = getRandomId ( )
217210 const pInitialInsert = UserActionsLog . insertAsync (
218211 literal < UserActionsLogItem > ( {
219212 _id : actionId ,
220213 clientAddress : context . connection . clientAddress ,
221- organizationId : credentials . organizationId ,
222- userId : credentials . userId ,
214+ organizationId : null ,
215+ userId : null ,
223216 context : userEvent ,
224217 method : methodName ,
225218 args : JSON . stringify ( methodArgs ) ,
@@ -233,7 +226,7 @@ export namespace ServerClientAPI {
233226
234227 const userActionMetadata : UserActionMetadata = { }
235228 try {
236- const result = await fcn ( credentials , userActionMetadata )
229+ const result = await fcn ( userActionMetadata )
237230
238231 const completeTime = Date . now ( )
239232 pInitialInsert
@@ -325,14 +318,15 @@ export namespace ServerClientAPI {
325318 } )
326319 }
327320
328- const access = await PeripheralDeviceContentWriteAccess . executeFunction ( methodContext , deviceId )
321+ // TODO - check this. This probably needs to be moved out of this method, with the client using more targetted methods
322+ assertConnectionHasOneOfPermissions ( methodContext . connection , 'studio' , 'configure' , 'service' )
329323
330324 await UserActionsLog . insertAsync (
331325 literal < UserActionsLogItem > ( {
332326 _id : actionId ,
333327 clientAddress : methodContext . connection ? methodContext . connection . clientAddress : '' ,
334- organizationId : access . organizationId ,
335- userId : access . userId ,
328+ organizationId : null ,
329+ userId : null ,
336330 context : context ,
337331 method : `${ deviceId } : ${ method } ` ,
338332 args : JSON . stringify ( args ) ,
@@ -395,7 +389,8 @@ export namespace ServerClientAPI {
395389 } )
396390 }
397391
398- await PeripheralDeviceContentWriteAccess . executeFunction ( methodContext , deviceId )
392+ // TODO - check this. This probably needs to be moved out of this method, with the client using more targetted methods
393+ assertConnectionHasOneOfPermissions ( methodContext . connection , 'studio' , 'configure' , 'service' )
399394
400395 return executePeripheralDeviceFunctionWithCustomTimeout ( deviceId , timeoutTime , {
401396 functionName,
@@ -407,17 +402,6 @@ export namespace ServerClientAPI {
407402 return Promise . reject ( err )
408403 } )
409404 }
410-
411- async function getLoggedInCredentials ( methodContext : MethodContext ) : Promise < BasicAccessContext > {
412- let userId : UserId | null = null
413- let organizationId : OrganizationId | null = null
414- if ( Settings . enableUserAccounts ) {
415- const cred = await resolveCredentials ( { userId : methodContext . userId } )
416- if ( cred . user ) userId = cred . user . _id
417- organizationId = cred . organizationId
418- }
419- return { userId, organizationId }
420- }
421405}
422406
423407class ServerClientAPIClass extends MethodContextAPI implements NewClientAPI {
0 commit comments