Skip to content

Commit 63b1e29

Browse files
committed
wip: remove remaining user permissions checks
1 parent a7bc4eb commit 63b1e29

File tree

11 files changed

+462
-463
lines changed

11 files changed

+462
-463
lines changed

meteor/client/ui/RundownList.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react'
33
import { MeteorPubSub } from '../../lib/api/pubsub'
44
import { GENESIS_SYSTEM_VERSION } from '../../lib/collections/CoreSystem'
55
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
6-
import { getAllowConfigure, getAllowStudio, getHelpMode } from '../lib/localStorage'
6+
import { getHelpMode } from '../lib/localStorage'
77
import { literal, unprotectString } from '../../lib/lib'
88
import { useSubscription, useTracker } from '../lib/ReactMeteorData/react-meteor-data'
99
import { Spinner } from '../lib/Spinner'
@@ -21,6 +21,7 @@ import { useEffect, useMemo, useState } from 'react'
2121
import { useTranslation } from 'react-i18next'
2222
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'
2323
import { CreateAdlibTestingRundownPanel } from './RundownList/CreateAdlibTestingRundownPanel'
24+
import { UserPermissionsContext } from './UserPermissions'
2425

2526
export enum ToolTipStep {
2627
TOOLTIP_START_HERE = 'TOOLTIP_START_HERE',
@@ -31,6 +32,8 @@ export enum ToolTipStep {
3132
export function RundownList(): JSX.Element {
3233
const { t } = useTranslation()
3334

35+
const userPermissions = React.useContext(UserPermissionsContext)
36+
3437
const playlistIds = useTracker(
3538
() =>
3639
RundownPlaylists.find(undefined, {
@@ -114,11 +117,11 @@ export function RundownList(): JSX.Element {
114117
}
115118

116119
if (coreSystem?.version === GENESIS_SYSTEM_VERSION && gotPlaylists === true) {
117-
return getAllowConfigure() ? ToolTipStep.TOOLTIP_RUN_MIGRATIONS : ToolTipStep.TOOLTIP_START_HERE
120+
return userPermissions.configure ? ToolTipStep.TOOLTIP_RUN_MIGRATIONS : ToolTipStep.TOOLTIP_START_HERE
118121
} else {
119122
return ToolTipStep.TOOLTIP_EXTRAS
120123
}
121-
}, [coreSystem, rundownPlaylists])
124+
}, [coreSystem, rundownPlaylists, userPermissions])
122125

123126
const showGettingStarted = coreSystem?.version === GENESIS_SYSTEM_VERSION && rundownPlaylists.length === 0
124127

@@ -186,7 +189,7 @@ export function RundownList(): JSX.Element {
186189
)}
187190
</section>
188191

189-
{getAllowStudio() && <CreateAdlibTestingRundownPanel />}
192+
{userPermissions.studio && <CreateAdlibTestingRundownPanel />}
190193

191194
<RundownListFooter />
192195
</>

meteor/client/ui/RundownList/RundownListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function RundownListItem({
127127
: undefined
128128
}
129129
confirmReSyncRundownHandler={
130-
rundown.orphaned && userPermissions.studio ? () => confirmReSyncRundown(rundown, t) : undefined
130+
rundown.orphaned && userPermissions.studio ? () => confirmReSyncRundown(userPermissions, rundown, t) : undefined
131131
}
132132
/>
133133
)

meteor/client/ui/RundownList/RundownListItemView.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React from 'react'
33
import { useTranslation } from 'react-i18next'
44
import { Link } from 'react-router-dom'
55
import { Rundown, getRundownNrcsName } from '@sofie-automation/corelib/dist/dataModel/Rundown'
6-
import { getAllowStudio } from '../../lib/localStorage'
76
import { RundownUtils } from '../../lib/rundown'
87
import { iconDragHandle, iconRemove, iconResync } from './icons'
98
import { DisplayFormattedTime } from './DisplayFormattedTime'
@@ -16,6 +15,7 @@ import { PlaylistTiming } from '@sofie-automation/corelib/dist/playout/rundownTi
1615
import { TOOLTIP_DEFAULT_DELAY } from '../../lib/lib'
1716
import { Meteor } from 'meteor/meteor'
1817
import { RundownPlaylists } from '../../collections'
18+
import { UserPermissionsContext } from '../UserPermissions'
1919

2020
interface IRundownListItemViewProps {
2121
isActive: boolean
@@ -54,6 +54,8 @@ export default React.memo(function RundownListItemView({
5454
}: IRundownListItemViewProps): JSX.Element | null {
5555
const { t } = useTranslation()
5656

57+
const userPermissions = React.useContext(UserPermissionsContext)
58+
5759
if (!rundown.playlistId) throw new Meteor.Error(500, 'Rundown is not a part of a rundown playlist!')
5860
const playlist = RundownPlaylists.findOne(rundown.playlistId)
5961
if (!playlist) throw new Meteor.Error(404, `Rundown Playlist "${rundown.playlistId}" not found!`)
@@ -80,7 +82,7 @@ export default React.memo(function RundownListItemView({
8082
>
8183
<span className="rundown-list-item__name" role="rowheader">
8284
<>
83-
{getAllowStudio() ? (
85+
{userPermissions.studio ? (
8486
<span className="draghandle" ref={connectDragSource}>
8587
<Tooltip
8688
overlay={t('Drag to reorder or move out of playlist')}

meteor/client/ui/RundownList/RundownPlaylistUi.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useState } from 'react'
1+
import React, { useCallback, useContext, useEffect, useState } from 'react'
22
import Tooltip from 'rc-tooltip'
33
import ClassNames from 'classnames'
44
import { useTranslation } from 'react-i18next'
@@ -19,13 +19,13 @@ import { MeteorCall } from '../../../lib/api/methods'
1919
import { RundownUtils } from '../../lib/rundown'
2020
import PlaylistRankResetButton from './PlaylistRankResetButton'
2121
import { DisplayFormattedTime } from './DisplayFormattedTime'
22-
import { getAllowStudio } from '../../lib/localStorage'
2322
import { doUserAction, UserAction } from '../../../lib/clientUserAction'
2423
import { RundownViewLayoutSelection } from './RundownViewLayoutSelection'
2524
import { RundownLayoutsAPI } from '../../../lib/api/rundownLayouts'
2625
import { PlaylistTiming } from '@sofie-automation/corelib/dist/playout/rundownTiming'
2726
import { TOOLTIP_DEFAULT_DELAY } from '../../lib/lib'
2827
import { RundownId } from '@sofie-automation/corelib/dist/dataModel/Ids'
28+
import { UserPermissionsContext } from '../UserPermissions'
2929

3030
export interface RundownPlaylistUi extends DBRundownPlaylist {
3131
rundowns: Rundown[]
@@ -42,6 +42,8 @@ export function RundownPlaylistUi({
4242
const { t } = useTranslation()
4343
const [rundownOrder, setRundownOrder] = useState(playlist.rundowns.map((rundown) => rundown._id))
4444

45+
const userPermissions = useContext(UserPermissionsContext)
46+
4547
useEffect(() => {
4648
setRundownOrder(playlist.rundowns.map((rundown) => rundown._id))
4749
}, [playlist.rundowns.map((rundown) => rundown._id).join(',')])
@@ -205,7 +207,7 @@ export function RundownPlaylistUi({
205207
</Link>
206208
</span>
207209
</h2>
208-
{getAllowStudio() ? (
210+
{userPermissions.studio ? (
209211
<PlaylistRankResetButton
210212
manualSortingActive={playlist.rundownRanksAreSetInSofie === true}
211213
nrcsName={getRundownNrcsName(playlist.rundowns[0])}

meteor/client/ui/RundownList/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ShowStyleBaseId,
1313
StudioId,
1414
} from '@sofie-automation/corelib/dist/dataModel/Ids'
15+
import { UserLevel } from '../../../lib/userLevel'
1516

1617
export function getRundownPlaylistLink(rundownPlaylistId: RundownPlaylistId): string {
1718
// double encoding so that "/" are handled correctly
@@ -70,7 +71,7 @@ export function confirmDeleteRundown(rundown: Rundown, t: TFunction): void {
7071
})
7172
}
7273

73-
export function confirmReSyncRundown(rundown: Rundown, t: TFunction): void {
74+
export function confirmReSyncRundown(userPermissions: Readonly<UserLevel>, rundown: Rundown, t: TFunction): void {
7475
doModalDialog({
7576
title: t('Re-Sync rundown?'),
7677
yes: t('Re-Sync'),
@@ -83,7 +84,7 @@ export function confirmReSyncRundown(rundown: Rundown, t: TFunction): void {
8384
async (e, ts) => MeteorCall.userAction.resyncRundown(e, ts, rundown._id),
8485
(err, res) => {
8586
if (!err && res) {
86-
return handleRundownReloadResponse(t, rundown._id, res)
87+
return handleRundownReloadResponse(t, userPermissions, rundown._id, res)
8788
}
8889
}
8990
)

meteor/client/ui/RundownView.tsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ interface IRundownHeaderProps {
345345
rundownIds: RundownId[]
346346
firstRundown: Rundown | undefined
347347
onActivate?: (isRehearsal: boolean) => void
348-
studioMode: boolean
349348
inActiveRundownView?: boolean
350349
layout: RundownLayoutRundownHeader | undefined
350+
userPermissions: Readonly<UserLevel>
351351
}
352352

353353
interface IRundownHeaderState {
@@ -439,7 +439,7 @@ const RundownHeader = withTranslation()(
439439
disableNextPiece = (e: any) => {
440440
const { t } = this.props
441441

442-
if (this.props.studioMode) {
442+
if (this.props.userPermissions.studio) {
443443
doUserAction(
444444
t,
445445
e,
@@ -453,7 +453,7 @@ const RundownHeader = withTranslation()(
453453
disableNextPieceUndo = (e: any) => {
454454
const { t } = this.props
455455

456-
if (this.props.studioMode) {
456+
if (this.props.userPermissions.studio) {
457457
doUserAction(
458458
t,
459459
e,
@@ -466,7 +466,7 @@ const RundownHeader = withTranslation()(
466466

467467
take = (e: any) => {
468468
const { t } = this.props
469-
if (this.props.studioMode) {
469+
if (this.props.userPermissions.studio) {
470470
if (!this.props.playlist.activationId) {
471471
const onSuccess = () => {
472472
if (typeof this.props.onActivate === 'function') this.props.onActivate(false)
@@ -537,7 +537,7 @@ const RundownHeader = withTranslation()(
537537

538538
hold = (e: any) => {
539539
const { t } = this.props
540-
if (this.props.studioMode && this.props.playlist.activationId) {
540+
if (this.props.userPermissions.studio && this.props.playlist.activationId) {
541541
doUserAction(t, e, UserAction.ACTIVATE_HOLD, (e, ts) =>
542542
MeteorCall.userAction.activateHold(e, ts, this.props.playlist._id, false)
543543
)
@@ -547,7 +547,7 @@ const RundownHeader = withTranslation()(
547547
holdUndo = (e: any) => {
548548
const { t } = this.props
549549
if (
550-
this.props.studioMode &&
550+
this.props.userPermissions.studio &&
551551
this.props.playlist.activationId &&
552552
this.props.playlist.holdState === RundownHoldState.PENDING
553553
) {
@@ -644,7 +644,7 @@ const RundownHeader = withTranslation()(
644644
if (e.persist) e.persist()
645645

646646
if (
647-
this.props.studioMode &&
647+
this.props.userPermissions.studio &&
648648
(!this.props.playlist.activationId || (this.props.playlist.activationId && this.props.playlist.rehearsal))
649649
) {
650650
const onSuccess = () => {
@@ -718,7 +718,7 @@ const RundownHeader = withTranslation()(
718718
if (e.persist) e.persist()
719719

720720
if (
721-
this.props.studioMode &&
721+
this.props.userPermissions.studio &&
722722
(!this.props.playlist.activationId || (this.props.playlist.activationId && !this.props.playlist.rehearsal))
723723
) {
724724
const onSuccess = () => {
@@ -798,7 +798,7 @@ const RundownHeader = withTranslation()(
798798
const { t } = this.props
799799
if (e.persist) e.persist()
800800

801-
if (this.props.studioMode && this.props.playlist.activationId) {
801+
if (this.props.userPermissions.studio && this.props.playlist.activationId) {
802802
if (this.rundownShouldHaveStarted()) {
803803
if (this.props.playlist.rehearsal) {
804804
// We're in rehearsal mode
@@ -830,7 +830,7 @@ const RundownHeader = withTranslation()(
830830
if (e.persist) e.persist()
831831

832832
if (
833-
this.props.studioMode &&
833+
this.props.userPermissions.studio &&
834834
this.props.studio.settings.allowAdlibTestingSegment &&
835835
this.props.playlist.activationId &&
836836
this.props.currentRundown
@@ -880,15 +880,15 @@ const RundownHeader = withTranslation()(
880880

881881
reloadRundownPlaylist = (e: any) => {
882882
const { t } = this.props
883-
if (this.props.studioMode) {
883+
if (this.props.userPermissions.studio) {
884884
doUserAction(
885885
t,
886886
e,
887887
UserAction.RELOAD_RUNDOWN_PLAYLIST_DATA,
888888
(e, ts) => MeteorCall.userAction.resyncRundownPlaylist(e, ts, this.props.playlist._id),
889889
(err, reloadResponse) => {
890890
if (!err && reloadResponse) {
891-
if (!handleRundownPlaylistReloadResponse(t, reloadResponse)) {
891+
if (!handleRundownPlaylistReloadResponse(t, this.props.userPermissions, reloadResponse)) {
892892
if (this.props.playlist && this.props.playlist.nextPartInfo) {
893893
scrollToPartInstance(this.props.playlist.nextPartInfo.partInstanceId).catch((error) => {
894894
if (!error.toString().match(/another scroll/)) console.warn(error)
@@ -903,7 +903,7 @@ const RundownHeader = withTranslation()(
903903

904904
takeRundownSnapshot = (e: any) => {
905905
const { t } = this.props
906-
if (this.props.studioMode) {
906+
if (this.props.userPermissions.studio) {
907907
const doneMessage = t('A snapshot of the current Running\xa0Order has been created for troubleshooting.')
908908
doUserAction(
909909
t,
@@ -946,7 +946,7 @@ const RundownHeader = withTranslation()(
946946

947947
resetAndActivateRundown = (e: any) => {
948948
// Called from the ModalDialog, 1 minute before broadcast starts
949-
if (this.props.studioMode) {
949+
if (this.props.userPermissions.studio) {
950950
const { t } = this.props
951951
this.rewindSegments() // Do a rewind right away
952952

@@ -998,7 +998,7 @@ const RundownHeader = withTranslation()(
998998
<Escape to="document">
999999
<ContextMenu id="rundown-context-menu">
10001000
<div className="react-contextmenu-label">{this.props.playlist && this.props.playlist.name}</div>
1001-
{this.props.studioMode ? (
1001+
{this.props.userPermissions.studio ? (
10021002
<React.Fragment>
10031003
{!(this.props.playlist.activationId && this.props.playlist.rehearsal) ? (
10041004
!this.rundownShouldHaveStarted() && !this.props.playlist.activationId ? (
@@ -1062,7 +1062,7 @@ const RundownHeader = withTranslation()(
10621062
holdToDisplay={contextMenuHoldToDisplayTime()}
10631063
>
10641064
<WarningDisplay
1065-
studioMode={this.props.studioMode}
1065+
studioMode={this.props.userPermissions.studio}
10661066
inActiveRundownView={this.props.inActiveRundownView}
10671067
playlist={this.props.playlist}
10681068
oneMinuteBeforeAction={this.resetAndActivateRundown}
@@ -1072,7 +1072,7 @@ const RundownHeader = withTranslation()(
10721072
<div className="badge mod">
10731073
<Tooltip
10741074
overlay={t('Add ?studio=1 to the URL to enter studio mode')}
1075-
visible={getHelpMode() && !getAllowStudio()}
1075+
visible={getHelpMode() && !this.props.userPermissions.studio}
10761076
placement="bottom"
10771077
>
10781078
<div className="media-elem mrs sofie-logo" />
@@ -1089,7 +1089,7 @@ const RundownHeader = withTranslation()(
10891089
showStyleBase={this.props.showStyleBase}
10901090
showStyleVariant={this.props.showStyleVariant}
10911091
studio={this.props.studio}
1092-
studioMode={this.props.studioMode}
1092+
studioMode={this.props.userPermissions.studio}
10931093
shouldQueue={this.state.shouldQueue}
10941094
onChangeQueueAdLib={this.changeQueueAdLib}
10951095
selectedPiece={this.state.selectedPiece}
@@ -2966,7 +2966,7 @@ const RundownViewContent = translateWithTracker<IPropsWithReady, IState, ITracke
29662966
rundownIds={this.props.rundowns.map((r) => r._id)}
29672967
firstRundown={this.props.rundowns[0]}
29682968
onActivate={this.onActivate}
2969-
studioMode={this.props.userPermissions.studio}
2969+
userPermissions={this.props.userPermissions}
29702970
inActiveRundownView={this.props.inActiveRundownView}
29712971
currentRundown={this.state.currentRundown || this.props.rundowns[0]}
29722972
layout={this.state.rundownHeaderLayout}
@@ -3298,7 +3298,11 @@ const RundownViewContent = translateWithTracker<IPropsWithReady, IState, ITracke
32983298
}
32993299
)
33003300

3301-
function handleRundownPlaylistReloadResponse(t: i18next.TFunction, result: ReloadRundownPlaylistResponse): boolean {
3301+
function handleRundownPlaylistReloadResponse(
3302+
t: i18next.TFunction,
3303+
userPermissions: Readonly<UserLevel>,
3304+
result: ReloadRundownPlaylistResponse
3305+
): boolean {
33023306
const rundownsInNeedOfHandling = result.rundownsResponses.filter(
33033307
(r) => r.response === TriggerReloadDataResponse.MISSING
33043308
)
@@ -3334,7 +3338,7 @@ function handleRundownPlaylistReloadResponse(t: i18next.TFunction, result: Reloa
33343338
}
33353339

33363340
const handled = rundownsInNeedOfHandling.map((r) =>
3337-
handleRundownReloadResponse(t, r.rundownId, r.response, onActionTaken)
3341+
handleRundownReloadResponse(t, userPermissions, r.rundownId, r.response, onActionTaken)
33383342
)
33393343
return handled.reduce((previousValue, value) => previousValue || value, false)
33403344
}
@@ -3343,6 +3347,7 @@ type RundownReloadResponseUserAction = 'removed' | 'unsynced' | 'error'
33433347

33443348
export function handleRundownReloadResponse(
33453349
t: i18next.TFunction,
3350+
userPermissions: Readonly<UserLevel>,
33463351
rundownId: RundownId,
33473352
result: TriggerReloadDataResponse,
33483353
clb?: (action: RundownReloadResponseUserAction) => void

0 commit comments

Comments
 (0)