@@ -32,22 +32,18 @@ import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyE
3232import { createAsyncOnlyMongoCollection , createAsyncOnlyReadOnlyMongoCollection } from './collection'
3333import { ObserveChangesForHash } from './lib'
3434import { logger } from '../logging'
35- import { resolveCredentials } from '../security/lib/credentials'
36- import { logNotAllowed , allowOnlyFields , rejectFields } from '../security/lib/lib'
37- import {
38- allowAccessToCoreSystem ,
39- allowAccessToOrganization ,
40- allowAccessToShowStyleBase ,
41- allowAccessToStudio ,
42- } from '../security/lib/security'
35+ import { allowOnlyFields , rejectFields } from '../security/lib/lib'
4336import type { DBNotificationObj } from '@sofie-automation/corelib/dist/dataModel/Notifications'
37+ import { checkUserIdHasOneOfPermissions } from '../security/auth'
4438
4539export * from './bucket'
4640export * from './packages-media'
4741export * from './rundown'
4842
4943export const Blueprints = createAsyncOnlyMongoCollection < Blueprint > ( CollectionName . Blueprints , {
50- update ( _userId , doc , fields , _modifier ) {
44+ update ( userId , doc , fields , _modifier ) {
45+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . Blueprints , 'configure' ) ) return false
46+
5147 return allowOnlyFields ( doc , fields , [ 'name' , 'disableVersionChecks' ] )
5248 } ,
5349} )
@@ -57,9 +53,7 @@ registerIndex(Blueprints, {
5753
5854export const CoreSystem = createAsyncOnlyMongoCollection < ICoreSystem > ( CollectionName . CoreSystem , {
5955 async update ( userId , doc , fields , _modifier ) {
60- const cred = await resolveCredentials ( { userId : userId } )
61- const access = await allowAccessToCoreSystem ( cred )
62- if ( ! access . update ) return logNotAllowed ( 'CoreSystem' , access . reason )
56+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . CoreSystem , 'configure' ) ) return false
6357
6458 return allowOnlyFields ( doc , fields , [
6559 'support' ,
@@ -119,8 +113,8 @@ registerIndex(Notifications, {
119113
120114export const Organizations = createAsyncOnlyMongoCollection < DBOrganization > ( CollectionName . Organizations , {
121115 async update ( userId , doc , fields , _modifier ) {
122- const access = await allowAccessToOrganization ( { userId : userId } , doc . _id )
123- if ( ! access . update ) return logNotAllowed ( 'Organization' , access . reason )
116+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . Organizations , 'configure' ) ) return false
117+
124118 return allowOnlyFields ( doc , fields , [ 'userRoles' ] )
125119 } ,
126120} )
@@ -134,7 +128,9 @@ registerIndex(PeripheralDeviceCommands, {
134128} )
135129
136130export const PeripheralDevices = createAsyncOnlyMongoCollection < PeripheralDevice > ( CollectionName . PeripheralDevices , {
137- update ( _userId , doc , fields , _modifier ) {
131+ update ( userId , doc , fields , _modifier ) {
132+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . PeripheralDevices , 'configure' ) ) return false
133+
138134 return rejectFields ( doc , fields , [
139135 'type' ,
140136 'parentDeviceId' ,
@@ -163,8 +159,8 @@ registerIndex(PeripheralDevices, {
163159
164160export const RundownLayouts = createAsyncOnlyMongoCollection < RundownLayoutBase > ( CollectionName . RundownLayouts , {
165161 async update ( userId , doc , fields ) {
166- const access = await allowAccessToShowStyleBase ( { userId : userId } , doc . showStyleBaseId )
167- if ( ! access . update ) return logNotAllowed ( 'ShowStyleBase' , access . reason )
162+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . RundownLayouts , 'configure' ) ) return false
163+
168164 return rejectFields ( doc , fields , [ '_id' , 'showStyleBaseId' ] )
169165 } ,
170166} )
@@ -180,8 +176,8 @@ registerIndex(RundownLayouts, {
180176
181177export const ShowStyleBases = createAsyncOnlyMongoCollection < DBShowStyleBase > ( CollectionName . ShowStyleBases , {
182178 async update ( userId , doc , fields ) {
183- const access = await allowAccessToShowStyleBase ( { userId : userId } , doc . _id )
184- if ( ! access . update ) return logNotAllowed ( 'ShowStyleBase' , access . reason )
179+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . ShowStyleBases , 'configure' ) ) return false
180+
185181 return rejectFields ( doc , fields , [ '_id' ] )
186182 } ,
187183} )
@@ -191,8 +187,7 @@ registerIndex(ShowStyleBases, {
191187
192188export const ShowStyleVariants = createAsyncOnlyMongoCollection < DBShowStyleVariant > ( CollectionName . ShowStyleVariants , {
193189 async update ( userId , doc , fields ) {
194- const access = await allowAccessToShowStyleBase ( { userId : userId } , doc . showStyleBaseId )
195- if ( ! access . update ) return logNotAllowed ( 'ShowStyleBase' , access . reason )
190+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . ShowStyleVariants , 'configure' ) ) return false
196191
197192 return rejectFields ( doc , fields , [ 'showStyleBaseId' ] )
198193 } ,
@@ -203,7 +198,9 @@ registerIndex(ShowStyleVariants, {
203198} )
204199
205200export const Snapshots = createAsyncOnlyMongoCollection < SnapshotItem > ( CollectionName . Snapshots , {
206- update ( _userId , doc , fields , _modifier ) {
201+ update ( userId , doc , fields , _modifier ) {
202+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . Snapshots , 'configure' ) ) return false
203+
207204 return allowOnlyFields ( doc , fields , [ 'comment' ] )
208205 } ,
209206} )
@@ -216,8 +213,8 @@ registerIndex(Snapshots, {
216213
217214export const Studios = createAsyncOnlyMongoCollection < DBStudio > ( CollectionName . Studios , {
218215 async update ( userId , doc , fields , _modifier ) {
219- const access = await allowAccessToStudio ( { userId : userId } , doc . _id )
220- if ( ! access . update ) return logNotAllowed ( 'Studio' , access . reason )
216+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . Studios , 'configure' ) ) return false
217+
221218 return rejectFields ( doc , fields , [ '_id' ] )
222219 } ,
223220} )
@@ -245,17 +242,9 @@ export const TranslationsBundles = createAsyncOnlyMongoCollection<TranslationsBu
245242
246243export const TriggeredActions = createAsyncOnlyMongoCollection < DBTriggeredActions > ( CollectionName . TriggeredActions , {
247244 async update ( userId , doc , fields ) {
248- const cred = await resolveCredentials ( { userId : userId } )
249-
250- if ( doc . showStyleBaseId ) {
251- const access = await allowAccessToShowStyleBase ( cred , doc . showStyleBaseId )
252- if ( ! access . update ) return logNotAllowed ( 'ShowStyleBase' , access . reason )
253- return rejectFields ( doc , fields , [ '_id' ] )
254- } else {
255- const access = await allowAccessToCoreSystem ( cred )
256- if ( ! access . update ) return logNotAllowed ( 'CoreSystem' , access . reason )
257- return rejectFields ( doc , fields , [ '_id' ] )
258- }
245+ if ( ! checkUserIdHasOneOfPermissions ( userId , CollectionName . TriggeredActions , 'configure' ) ) return false
246+
247+ return rejectFields ( doc , fields , [ '_id' ] )
259248 } ,
260249} )
261250registerIndex ( TriggeredActions , {
0 commit comments