1- import { meteorPublish , AutoFillSelector } from './lib'
1+ import { meteorPublish } from './lib'
22import { MeteorPubSub } from '@sofie-automation/meteor-lib/dist/api/pubsub'
33import { Blueprint } from '@sofie-automation/corelib/dist/dataModel/Blueprint'
44import { Evaluation } from '@sofie-automation/meteor-lib/dist/collections/Evaluations'
55import { SnapshotItem } from '@sofie-automation/meteor-lib/dist/collections/Snapshots'
66import { UserActionsLogItem } from '@sofie-automation/meteor-lib/dist/collections/UserActionsLog'
7- import { OrganizationReadAccess } from '../security/organization'
87import { FindOptions } from '@sofie-automation/meteor-lib/dist/collections/lib'
98import { DBOrganization } from '@sofie-automation/meteor-lib/dist/collections/Organization'
10- import { isProtectedString } from '@sofie-automation/corelib/dist/protectedString'
119import { Blueprints , Evaluations , Organizations , Snapshots , UserActionsLog } from '../collections'
1210import { MongoQuery } from '@sofie-automation/corelib/dist/mongo'
1311import { BlueprintId , OrganizationId } from '@sofie-automation/corelib/dist/dataModel/Ids'
1412import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'
1513import { check , Match } from '../lib/check'
1614import { getCurrentTime } from '../lib/lib'
15+ import { triggerWriteAccessBecauseNoCheckNecessary } from '../security/lib/securityVerify'
1716
1817meteorPublish (
1918 MeteorPubSub . organization ,
20- async function ( organizationId : OrganizationId | null , token : string | undefined ) {
19+ async function ( organizationId : OrganizationId | null , _token : string | undefined ) {
20+ triggerWriteAccessBecauseNoCheckNecessary ( )
21+
2122 if ( ! organizationId ) return null
2223
23- const { cred, selector } = await AutoFillSelector . organizationId ( this . userId , { _id : organizationId } , token )
24+ const selector : MongoQuery < DBOrganization > = { _id : organizationId }
25+
2426 const modifier : FindOptions < DBOrganization > = {
2527 fields : {
2628 name : 1 ,
@@ -29,83 +31,70 @@ meteorPublish(
2931 userRoles : 1 , // to not expose too much information consider [`userRoles.${this.userId}`]: 1, and a method/publication for getting all the roles, or limiting the returned roles based on requesting user's role
3032 } ,
3133 }
32- if (
33- isProtectedString ( selector . organizationId ) &&
34- ( ! cred || ( await OrganizationReadAccess . organizationContent ( selector . organizationId , cred ) ) )
35- ) {
36- return Organizations . findWithCursor ( { _id : selector . organizationId } , modifier )
37- }
38- return null
34+
35+ return Organizations . findWithCursor ( { _id : selector . organizationId } , modifier )
3936 }
4037)
4138
42- meteorPublish ( CorelibPubSub . blueprints , async function ( blueprintIds : BlueprintId [ ] | null , token : string | undefined ) {
43- check ( blueprintIds , Match . Maybe ( Array ) )
39+ meteorPublish (
40+ CorelibPubSub . blueprints ,
41+ async function ( blueprintIds : BlueprintId [ ] | null , _token : string | undefined ) {
42+ // nocommit - is this correct?
43+ triggerWriteAccessBecauseNoCheckNecessary ( )
4444
45- // If values were provided, they must have values
46- if ( blueprintIds && blueprintIds . length === 0 ) return null
45+ check ( blueprintIds , Match . Maybe ( Array ) )
4746
48- const { cred, selector } = await AutoFillSelector . organizationId < Blueprint > ( this . userId , { } , token )
47+ // If values were provided, they must have values
48+ if ( blueprintIds && blueprintIds . length === 0 ) return null
4949
50- // Add the requested filter
51- if ( blueprintIds ) selector . _id = { $in : blueprintIds }
50+ // Add the requested filter
51+ const selector : MongoQuery < Blueprint > = { }
52+ if ( blueprintIds ) selector . _id = { $in : blueprintIds }
5253
53- if ( ! cred || ( await OrganizationReadAccess . organizationContent ( selector . organizationId , cred ) ) ) {
5454 return Blueprints . findWithCursor ( selector , {
5555 fields : {
5656 code : 0 ,
5757 } ,
5858 } )
5959 }
60- return null
61- } )
62- meteorPublish ( MeteorPubSub . evaluations , async function ( dateFrom : number , dateTo : number , token : string | undefined ) {
63- const selector0 : MongoQuery < Evaluation > = {
60+ )
61+ meteorPublish ( MeteorPubSub . evaluations , async function ( dateFrom : number , dateTo : number , _token : string | undefined ) {
62+ triggerWriteAccessBecauseNoCheckNecessary ( )
63+
64+ const selector : MongoQuery < Evaluation > = {
6465 timestamp : {
6566 $gte : dateFrom ,
6667 $lt : dateTo ,
6768 } ,
6869 }
6970
70- const { cred, selector } = await AutoFillSelector . organizationId < Evaluation > ( this . userId , selector0 , token )
71- if ( ! cred || ( await OrganizationReadAccess . organizationContent ( selector . organizationId , cred ) ) ) {
72- return Evaluations . findWithCursor ( selector )
73- }
74- return null
71+ return Evaluations . findWithCursor ( selector )
7572} )
76- meteorPublish ( MeteorPubSub . snapshots , async function ( token : string | undefined ) {
77- const selector0 : MongoQuery < SnapshotItem > = {
73+ meteorPublish ( MeteorPubSub . snapshots , async function ( _token : string | undefined ) {
74+ triggerWriteAccessBecauseNoCheckNecessary ( )
75+
76+ const selector : MongoQuery < SnapshotItem > = {
7877 created : {
7978 $gt : getCurrentTime ( ) - 30 * 24 * 3600 * 1000 , // last 30 days
8079 } ,
8180 }
8281
83- const { cred, selector } = await AutoFillSelector . organizationId < SnapshotItem > ( this . userId , selector0 , token )
84- if ( ! cred || ( await OrganizationReadAccess . organizationContent ( selector . organizationId , cred ) ) ) {
85- return Snapshots . findWithCursor ( selector )
86- }
87- return null
82+ return Snapshots . findWithCursor ( selector )
8883} )
8984meteorPublish (
9085 MeteorPubSub . userActionsLog ,
91- async function ( dateFrom : number , dateTo : number , token : string | undefined ) {
92- const selector0 : MongoQuery < UserActionsLogItem > = {
86+ async function ( dateFrom : number , dateTo : number , _token : string | undefined ) {
87+ triggerWriteAccessBecauseNoCheckNecessary ( )
88+
89+ const selector : MongoQuery < UserActionsLogItem > = {
9390 timestamp : {
9491 $gte : dateFrom ,
9592 $lt : dateTo ,
9693 } ,
9794 }
9895
99- const { cred, selector } = await AutoFillSelector . organizationId < UserActionsLogItem > (
100- this . userId ,
101- selector0 ,
102- token
103- )
104- if ( ! cred || ( await OrganizationReadAccess . organizationContent ( selector . organizationId , cred ) ) ) {
105- return UserActionsLog . findWithCursor ( selector , {
106- limit : 10_000 , // this is to prevent having a publication that produces a very large array
107- } )
108- }
109- return null
96+ return UserActionsLog . findWithCursor ( selector , {
97+ limit : 10_000 , // this is to prevent having a publication that produces a very large array
98+ } )
11099 }
111100)
0 commit comments