Skip to content

Commit

Permalink
wip: remove remaining user permissions checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Sep 20, 2024
1 parent a7bc4eb commit 63b1e29
Show file tree
Hide file tree
Showing 11 changed files with 462 additions and 463 deletions.
11 changes: 7 additions & 4 deletions meteor/client/ui/RundownList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react'
import { MeteorPubSub } from '../../lib/api/pubsub'
import { GENESIS_SYSTEM_VERSION } from '../../lib/collections/CoreSystem'
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { getAllowConfigure, getAllowStudio, getHelpMode } from '../lib/localStorage'
import { getHelpMode } from '../lib/localStorage'
import { literal, unprotectString } from '../../lib/lib'
import { useSubscription, useTracker } from '../lib/ReactMeteorData/react-meteor-data'
import { Spinner } from '../lib/Spinner'
Expand All @@ -21,6 +21,7 @@ import { useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'
import { CreateAdlibTestingRundownPanel } from './RundownList/CreateAdlibTestingRundownPanel'
import { UserPermissionsContext } from './UserPermissions'

export enum ToolTipStep {
TOOLTIP_START_HERE = 'TOOLTIP_START_HERE',
Expand All @@ -31,6 +32,8 @@ export enum ToolTipStep {
export function RundownList(): JSX.Element {
const { t } = useTranslation()

const userPermissions = React.useContext(UserPermissionsContext)

const playlistIds = useTracker(
() =>
RundownPlaylists.find(undefined, {
Expand Down Expand Up @@ -114,11 +117,11 @@ export function RundownList(): JSX.Element {
}

if (coreSystem?.version === GENESIS_SYSTEM_VERSION && gotPlaylists === true) {
return getAllowConfigure() ? ToolTipStep.TOOLTIP_RUN_MIGRATIONS : ToolTipStep.TOOLTIP_START_HERE
return userPermissions.configure ? ToolTipStep.TOOLTIP_RUN_MIGRATIONS : ToolTipStep.TOOLTIP_START_HERE
} else {
return ToolTipStep.TOOLTIP_EXTRAS
}
}, [coreSystem, rundownPlaylists])
}, [coreSystem, rundownPlaylists, userPermissions])

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

Expand Down Expand Up @@ -186,7 +189,7 @@ export function RundownList(): JSX.Element {
)}
</section>

{getAllowStudio() && <CreateAdlibTestingRundownPanel />}
{userPermissions.studio && <CreateAdlibTestingRundownPanel />}

<RundownListFooter />
</>
Expand Down
2 changes: 1 addition & 1 deletion meteor/client/ui/RundownList/RundownListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function RundownListItem({
: undefined
}
confirmReSyncRundownHandler={
rundown.orphaned && userPermissions.studio ? () => confirmReSyncRundown(rundown, t) : undefined
rundown.orphaned && userPermissions.studio ? () => confirmReSyncRundown(userPermissions, rundown, t) : undefined
}
/>
)
Expand Down
6 changes: 4 additions & 2 deletions meteor/client/ui/RundownList/RundownListItemView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'
import { Rundown, getRundownNrcsName } from '@sofie-automation/corelib/dist/dataModel/Rundown'
import { getAllowStudio } from '../../lib/localStorage'
import { RundownUtils } from '../../lib/rundown'
import { iconDragHandle, iconRemove, iconResync } from './icons'
import { DisplayFormattedTime } from './DisplayFormattedTime'
Expand All @@ -16,6 +15,7 @@ import { PlaylistTiming } from '@sofie-automation/corelib/dist/playout/rundownTi
import { TOOLTIP_DEFAULT_DELAY } from '../../lib/lib'
import { Meteor } from 'meteor/meteor'
import { RundownPlaylists } from '../../collections'
import { UserPermissionsContext } from '../UserPermissions'

interface IRundownListItemViewProps {
isActive: boolean
Expand Down Expand Up @@ -54,6 +54,8 @@ export default React.memo(function RundownListItemView({
}: IRundownListItemViewProps): JSX.Element | null {
const { t } = useTranslation()

const userPermissions = React.useContext(UserPermissionsContext)

if (!rundown.playlistId) throw new Meteor.Error(500, 'Rundown is not a part of a rundown playlist!')
const playlist = RundownPlaylists.findOne(rundown.playlistId)
if (!playlist) throw new Meteor.Error(404, `Rundown Playlist "${rundown.playlistId}" not found!`)
Expand All @@ -80,7 +82,7 @@ export default React.memo(function RundownListItemView({
>
<span className="rundown-list-item__name" role="rowheader">
<>
{getAllowStudio() ? (
{userPermissions.studio ? (
<span className="draghandle" ref={connectDragSource}>
<Tooltip
overlay={t('Drag to reorder or move out of playlist')}
Expand Down
8 changes: 5 additions & 3 deletions meteor/client/ui/RundownList/RundownPlaylistUi.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from 'react'
import React, { useCallback, useContext, useEffect, useState } from 'react'
import Tooltip from 'rc-tooltip'
import ClassNames from 'classnames'
import { useTranslation } from 'react-i18next'
Expand All @@ -19,13 +19,13 @@ import { MeteorCall } from '../../../lib/api/methods'
import { RundownUtils } from '../../lib/rundown'
import PlaylistRankResetButton from './PlaylistRankResetButton'
import { DisplayFormattedTime } from './DisplayFormattedTime'
import { getAllowStudio } from '../../lib/localStorage'
import { doUserAction, UserAction } from '../../../lib/clientUserAction'
import { RundownViewLayoutSelection } from './RundownViewLayoutSelection'
import { RundownLayoutsAPI } from '../../../lib/api/rundownLayouts'
import { PlaylistTiming } from '@sofie-automation/corelib/dist/playout/rundownTiming'
import { TOOLTIP_DEFAULT_DELAY } from '../../lib/lib'
import { RundownId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { UserPermissionsContext } from '../UserPermissions'

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

const userPermissions = useContext(UserPermissionsContext)

useEffect(() => {
setRundownOrder(playlist.rundowns.map((rundown) => rundown._id))
}, [playlist.rundowns.map((rundown) => rundown._id).join(',')])
Expand Down Expand Up @@ -205,7 +207,7 @@ export function RundownPlaylistUi({
</Link>
</span>
</h2>
{getAllowStudio() ? (
{userPermissions.studio ? (
<PlaylistRankResetButton
manualSortingActive={playlist.rundownRanksAreSetInSofie === true}
nrcsName={getRundownNrcsName(playlist.rundowns[0])}
Expand Down
5 changes: 3 additions & 2 deletions meteor/client/ui/RundownList/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ShowStyleBaseId,
StudioId,
} from '@sofie-automation/corelib/dist/dataModel/Ids'
import { UserLevel } from '../../../lib/userLevel'

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

export function confirmReSyncRundown(rundown: Rundown, t: TFunction): void {
export function confirmReSyncRundown(userPermissions: Readonly<UserLevel>, rundown: Rundown, t: TFunction): void {
doModalDialog({
title: t('Re-Sync rundown?'),
yes: t('Re-Sync'),
Expand All @@ -83,7 +84,7 @@ export function confirmReSyncRundown(rundown: Rundown, t: TFunction): void {
async (e, ts) => MeteorCall.userAction.resyncRundown(e, ts, rundown._id),
(err, res) => {
if (!err && res) {
return handleRundownReloadResponse(t, rundown._id, res)
return handleRundownReloadResponse(t, userPermissions, rundown._id, res)
}
}
)
Expand Down
47 changes: 26 additions & 21 deletions meteor/client/ui/RundownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ interface IRundownHeaderProps {
rundownIds: RundownId[]
firstRundown: Rundown | undefined
onActivate?: (isRehearsal: boolean) => void
studioMode: boolean
inActiveRundownView?: boolean
layout: RundownLayoutRundownHeader | undefined
userPermissions: Readonly<UserLevel>
}

interface IRundownHeaderState {
Expand Down Expand Up @@ -439,7 +439,7 @@ const RundownHeader = withTranslation()(
disableNextPiece = (e: any) => {
const { t } = this.props

if (this.props.studioMode) {
if (this.props.userPermissions.studio) {
doUserAction(
t,
e,
Expand All @@ -453,7 +453,7 @@ const RundownHeader = withTranslation()(
disableNextPieceUndo = (e: any) => {
const { t } = this.props

if (this.props.studioMode) {
if (this.props.userPermissions.studio) {
doUserAction(
t,
e,
Expand All @@ -466,7 +466,7 @@ const RundownHeader = withTranslation()(

take = (e: any) => {
const { t } = this.props
if (this.props.studioMode) {
if (this.props.userPermissions.studio) {
if (!this.props.playlist.activationId) {
const onSuccess = () => {
if (typeof this.props.onActivate === 'function') this.props.onActivate(false)
Expand Down Expand Up @@ -537,7 +537,7 @@ const RundownHeader = withTranslation()(

hold = (e: any) => {
const { t } = this.props
if (this.props.studioMode && this.props.playlist.activationId) {
if (this.props.userPermissions.studio && this.props.playlist.activationId) {
doUserAction(t, e, UserAction.ACTIVATE_HOLD, (e, ts) =>
MeteorCall.userAction.activateHold(e, ts, this.props.playlist._id, false)
)
Expand All @@ -547,7 +547,7 @@ const RundownHeader = withTranslation()(
holdUndo = (e: any) => {
const { t } = this.props
if (
this.props.studioMode &&
this.props.userPermissions.studio &&
this.props.playlist.activationId &&
this.props.playlist.holdState === RundownHoldState.PENDING
) {
Expand Down Expand Up @@ -644,7 +644,7 @@ const RundownHeader = withTranslation()(
if (e.persist) e.persist()

if (
this.props.studioMode &&
this.props.userPermissions.studio &&
(!this.props.playlist.activationId || (this.props.playlist.activationId && this.props.playlist.rehearsal))
) {
const onSuccess = () => {
Expand Down Expand Up @@ -718,7 +718,7 @@ const RundownHeader = withTranslation()(
if (e.persist) e.persist()

if (
this.props.studioMode &&
this.props.userPermissions.studio &&
(!this.props.playlist.activationId || (this.props.playlist.activationId && !this.props.playlist.rehearsal))
) {
const onSuccess = () => {
Expand Down Expand Up @@ -798,7 +798,7 @@ const RundownHeader = withTranslation()(
const { t } = this.props
if (e.persist) e.persist()

if (this.props.studioMode && this.props.playlist.activationId) {
if (this.props.userPermissions.studio && this.props.playlist.activationId) {
if (this.rundownShouldHaveStarted()) {
if (this.props.playlist.rehearsal) {
// We're in rehearsal mode
Expand Down Expand Up @@ -830,7 +830,7 @@ const RundownHeader = withTranslation()(
if (e.persist) e.persist()

if (
this.props.studioMode &&
this.props.userPermissions.studio &&
this.props.studio.settings.allowAdlibTestingSegment &&
this.props.playlist.activationId &&
this.props.currentRundown
Expand Down Expand Up @@ -880,15 +880,15 @@ const RundownHeader = withTranslation()(

reloadRundownPlaylist = (e: any) => {
const { t } = this.props
if (this.props.studioMode) {
if (this.props.userPermissions.studio) {
doUserAction(
t,
e,
UserAction.RELOAD_RUNDOWN_PLAYLIST_DATA,
(e, ts) => MeteorCall.userAction.resyncRundownPlaylist(e, ts, this.props.playlist._id),
(err, reloadResponse) => {
if (!err && reloadResponse) {
if (!handleRundownPlaylistReloadResponse(t, reloadResponse)) {
if (!handleRundownPlaylistReloadResponse(t, this.props.userPermissions, reloadResponse)) {
if (this.props.playlist && this.props.playlist.nextPartInfo) {
scrollToPartInstance(this.props.playlist.nextPartInfo.partInstanceId).catch((error) => {
if (!error.toString().match(/another scroll/)) console.warn(error)
Expand All @@ -903,7 +903,7 @@ const RundownHeader = withTranslation()(

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

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

Expand Down Expand Up @@ -998,7 +998,7 @@ const RundownHeader = withTranslation()(
<Escape to="document">
<ContextMenu id="rundown-context-menu">
<div className="react-contextmenu-label">{this.props.playlist && this.props.playlist.name}</div>
{this.props.studioMode ? (
{this.props.userPermissions.studio ? (
<React.Fragment>
{!(this.props.playlist.activationId && this.props.playlist.rehearsal) ? (
!this.rundownShouldHaveStarted() && !this.props.playlist.activationId ? (
Expand Down Expand Up @@ -1062,7 +1062,7 @@ const RundownHeader = withTranslation()(
holdToDisplay={contextMenuHoldToDisplayTime()}
>
<WarningDisplay
studioMode={this.props.studioMode}
studioMode={this.props.userPermissions.studio}
inActiveRundownView={this.props.inActiveRundownView}
playlist={this.props.playlist}
oneMinuteBeforeAction={this.resetAndActivateRundown}
Expand All @@ -1072,7 +1072,7 @@ const RundownHeader = withTranslation()(
<div className="badge mod">
<Tooltip
overlay={t('Add ?studio=1 to the URL to enter studio mode')}
visible={getHelpMode() && !getAllowStudio()}
visible={getHelpMode() && !this.props.userPermissions.studio}
placement="bottom"
>
<div className="media-elem mrs sofie-logo" />
Expand All @@ -1089,7 +1089,7 @@ const RundownHeader = withTranslation()(
showStyleBase={this.props.showStyleBase}
showStyleVariant={this.props.showStyleVariant}
studio={this.props.studio}
studioMode={this.props.studioMode}
studioMode={this.props.userPermissions.studio}
shouldQueue={this.state.shouldQueue}
onChangeQueueAdLib={this.changeQueueAdLib}
selectedPiece={this.state.selectedPiece}
Expand Down Expand Up @@ -2966,7 +2966,7 @@ const RundownViewContent = translateWithTracker<IPropsWithReady, IState, ITracke
rundownIds={this.props.rundowns.map((r) => r._id)}
firstRundown={this.props.rundowns[0]}
onActivate={this.onActivate}
studioMode={this.props.userPermissions.studio}
userPermissions={this.props.userPermissions}
inActiveRundownView={this.props.inActiveRundownView}
currentRundown={this.state.currentRundown || this.props.rundowns[0]}
layout={this.state.rundownHeaderLayout}
Expand Down Expand Up @@ -3298,7 +3298,11 @@ const RundownViewContent = translateWithTracker<IPropsWithReady, IState, ITracke
}
)

function handleRundownPlaylistReloadResponse(t: i18next.TFunction, result: ReloadRundownPlaylistResponse): boolean {
function handleRundownPlaylistReloadResponse(
t: i18next.TFunction,
userPermissions: Readonly<UserLevel>,
result: ReloadRundownPlaylistResponse
): boolean {
const rundownsInNeedOfHandling = result.rundownsResponses.filter(
(r) => r.response === TriggerReloadDataResponse.MISSING
)
Expand Down Expand Up @@ -3334,7 +3338,7 @@ function handleRundownPlaylistReloadResponse(t: i18next.TFunction, result: Reloa
}

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

export function handleRundownReloadResponse(
t: i18next.TFunction,
userPermissions: Readonly<UserLevel>,
rundownId: RundownId,
result: TriggerReloadDataResponse,
clb?: (action: RundownReloadResponseUserAction) => void
Expand Down
Loading

0 comments on commit 63b1e29

Please sign in to comment.