Skip to content

Commit 6fd795c

Browse files
committed
wip: publications
1 parent 2b405de commit 6fd795c

File tree

6 files changed

+264
-419
lines changed

6 files changed

+264
-419
lines changed

meteor/server/api/blueprints/api.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { parseVersion } from '../../systemStatus/semverUtils'
2020
import { evalBlueprint } from './cache'
2121
import { removeSystemStatus } from '../../systemStatus/systemStatus'
2222
import { MethodContext, MethodContextAPI } from '../methodContext'
23-
import { OrganizationReadAccess } from '../../security/organization'
2423
import { generateTranslationBundleOriginId, upsertBundles } from '../translationsBundles'
2524
import { BlueprintId, OrganizationId, ShowStyleBaseId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2625
import { Blueprints, CoreSystem, ShowStyleBases, ShowStyleVariants, Studios } from '../../collections'
@@ -371,9 +370,6 @@ async function assignSystemBlueprint(methodContext: MethodContext, blueprintId:
371370
const blueprint = await fetchBlueprintLight(blueprintId)
372371
if (!blueprint) throw new Meteor.Error(404, 'Blueprint not found')
373372

374-
if (blueprint.organizationId)
375-
await OrganizationReadAccess.organizationContent(blueprint.organizationId, { userId: methodContext.userId })
376-
377373
if (blueprint.blueprintType !== BlueprintManifestType.SYSTEM)
378374
throw new Meteor.Error(404, 'Blueprint not of type SYSTEM')
379375

meteor/server/api/heapSnapshot.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ import { fixValidPath } from '../lib/lib'
77
import { sleep } from '../lib/lib'
88
import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyError'
99
import { logger } from '../logging'
10-
import { Settings } from '../Settings'
11-
import { Credentials } from '../security/lib/credentials'
12-
import { SystemWriteAccess } from '../security/system'
10+
import { assertConnectionIsDeveloper, RequestCredentials } from '../security/auth'
11+
12+
async function retrieveHeapSnapshot(cred: RequestCredentials): Promise<Readable> {
13+
assertConnectionIsDeveloper(cred)
1314

14-
async function retrieveHeapSnapshot(cred0: Credentials): Promise<Readable> {
15-
if (Settings.enableUserAccounts) {
16-
await SystemWriteAccess.coreSystem(cred0)
17-
}
1815
logger.warn('Taking heap snapshot, expect system to be unresponsive for a few seconds..')
1916
await sleep(100) // Allow the logger to catch up before continuing..
2017

@@ -51,19 +48,9 @@ async function handleKoaResponse(ctx: Koa.ParameterizedContext, snapshotFcn: ()
5148
}
5249
}
5350

54-
// For backwards compatibility:
55-
if (!Settings.enableUserAccounts) {
56-
// Retrieve heap snapshot:
57-
heapSnapshotPrivateApiRouter.get('/retrieve', async (ctx) => {
58-
return handleKoaResponse(ctx, async () => {
59-
return retrieveHeapSnapshot({ userId: null })
60-
})
61-
})
62-
}
63-
6451
// Retrieve heap snapshot:
65-
heapSnapshotPrivateApiRouter.get('/:token/retrieve', async (ctx) => {
52+
heapSnapshotPrivateApiRouter.get('/retrieve', async (ctx) => {
6653
return handleKoaResponse(ctx, async () => {
67-
return retrieveHeapSnapshot({ userId: null, token: ctx.params.token })
54+
return retrieveHeapSnapshot(ctx)
6855
})
6956
})
Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
11
import { FindOptions } from '@sofie-automation/meteor-lib/dist/collections/lib'
2-
import { BucketSecurity } from '../security/buckets'
32
import { meteorPublish } from './lib'
43
import { MeteorPubSub } from '@sofie-automation/meteor-lib/dist/api/pubsub'
54
import { Bucket } from '@sofie-automation/meteor-lib/dist/collections/Buckets'
6-
import { StudioReadAccess } from '../security/studio'
7-
import { isProtectedString } from '@sofie-automation/corelib/dist/protectedString'
85
import { BucketAdLibActions, BucketAdLibs, Buckets } from '../collections'
96
import { check, Match } from 'meteor/check'
107
import { StudioId, BucketId, ShowStyleVariantId } from '@sofie-automation/corelib/dist/dataModel/Ids'
118
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'
9+
import { triggerWriteAccessBecauseNoCheckNecessary } from '../security/lib/securityVerify'
1210

1311
meteorPublish(
1412
MeteorPubSub.buckets,
1513
async function (studioId: StudioId, bucketId: BucketId | null, _token: string | undefined) {
1614
check(studioId, String)
1715
check(bucketId, Match.Maybe(String))
1816

17+
triggerWriteAccessBecauseNoCheckNecessary()
18+
1919
const modifier: FindOptions<Bucket> = {
2020
fields: {},
2121
}
22-
if (
23-
(await StudioReadAccess.studioContent(studioId, this)) ||
24-
(isProtectedString(bucketId) && bucketId && (await BucketSecurity.allowReadAccess(this, bucketId)))
25-
) {
26-
return Buckets.findWithCursor(
27-
bucketId
28-
? {
29-
_id: bucketId,
30-
studioId,
31-
}
32-
: {
33-
studioId,
34-
},
35-
modifier
36-
)
37-
}
38-
return null
22+
23+
return Buckets.findWithCursor(
24+
bucketId
25+
? {
26+
_id: bucketId,
27+
studioId,
28+
}
29+
: {
30+
studioId,
31+
},
32+
modifier
33+
)
3934
}
4035
)
4136

@@ -46,23 +41,22 @@ meteorPublish(
4641
check(bucketId, String)
4742
check(showStyleVariantIds, Array)
4843

49-
if (isProtectedString(bucketId) && (await BucketSecurity.allowReadAccess(this, bucketId))) {
50-
return BucketAdLibs.findWithCursor(
51-
{
52-
studioId: studioId,
53-
bucketId: bucketId,
54-
showStyleVariantId: {
55-
$in: [null, ...showStyleVariantIds], // null = valid for all variants
56-
},
44+
triggerWriteAccessBecauseNoCheckNecessary()
45+
46+
return BucketAdLibs.findWithCursor(
47+
{
48+
studioId: studioId,
49+
bucketId: bucketId,
50+
showStyleVariantId: {
51+
$in: [null, ...showStyleVariantIds], // null = valid for all variants
5752
},
58-
{
59-
fields: {
60-
ingestInfo: 0, // This is a large blob, and is not of interest to the UI
61-
},
62-
}
63-
)
64-
}
65-
return null
53+
},
54+
{
55+
fields: {
56+
ingestInfo: 0, // This is a large blob, and is not of interest to the UI
57+
},
58+
}
59+
)
6660
}
6761
)
6862

@@ -73,22 +67,21 @@ meteorPublish(
7367
check(bucketId, String)
7468
check(showStyleVariantIds, Array)
7569

76-
if (isProtectedString(bucketId) && (await BucketSecurity.allowReadAccess(this, bucketId))) {
77-
return BucketAdLibActions.findWithCursor(
78-
{
79-
studioId: studioId,
80-
bucketId: bucketId,
81-
showStyleVariantId: {
82-
$in: [null, ...showStyleVariantIds], // null = valid for all variants
83-
},
70+
triggerWriteAccessBecauseNoCheckNecessary()
71+
72+
return BucketAdLibActions.findWithCursor(
73+
{
74+
studioId: studioId,
75+
bucketId: bucketId,
76+
showStyleVariantId: {
77+
$in: [null, ...showStyleVariantIds], // null = valid for all variants
8478
},
85-
{
86-
fields: {
87-
ingestInfo: 0, // This is a large blob, and is not of interest to the UI
88-
},
89-
}
90-
)
91-
}
92-
return null
79+
},
80+
{
81+
fields: {
82+
ingestInfo: 0, // This is a large blob, and is not of interest to the UI
83+
},
84+
}
85+
)
9386
}
9487
)
Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
import { meteorPublish, AutoFillSelector } from './lib'
1+
import { meteorPublish } from './lib'
22
import { MeteorPubSub } from '@sofie-automation/meteor-lib/dist/api/pubsub'
33
import { Blueprint } from '@sofie-automation/corelib/dist/dataModel/Blueprint'
44
import { Evaluation } from '@sofie-automation/meteor-lib/dist/collections/Evaluations'
55
import { SnapshotItem } from '@sofie-automation/meteor-lib/dist/collections/Snapshots'
66
import { UserActionsLogItem } from '@sofie-automation/meteor-lib/dist/collections/UserActionsLog'
7-
import { OrganizationReadAccess } from '../security/organization'
87
import { FindOptions } from '@sofie-automation/meteor-lib/dist/collections/lib'
98
import { DBOrganization } from '@sofie-automation/meteor-lib/dist/collections/Organization'
10-
import { isProtectedString } from '@sofie-automation/corelib/dist/protectedString'
119
import { Blueprints, Evaluations, Organizations, Snapshots, UserActionsLog } from '../collections'
1210
import { MongoQuery } from '@sofie-automation/corelib/dist/mongo'
1311
import { BlueprintId, OrganizationId } from '@sofie-automation/corelib/dist/dataModel/Ids'
1412
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'
1513
import { check, Match } from '../lib/check'
1614
import { getCurrentTime } from '../lib/lib'
15+
import { triggerWriteAccessBecauseNoCheckNecessary } from '../security/lib/securityVerify'
1716

1817
meteorPublish(
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
})
8984
meteorPublish(
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

Comments
 (0)