From 4c9c0641b252a3ff7e6bd9d925cd696964a489fe Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 24 Mar 2023 12:09:14 +0000 Subject: [PATCH] Avoid reading some variables directly from `window` (#12280) GitOrigin-RevId: 93af19498470fd7903db9d55d7468f0298097cc4 --- .../web/frontend/js/shared/context/editor-context.js | 11 +++++++---- .../components/share-project-modal.test.js | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/shared/context/editor-context.js b/services/web/frontend/js/shared/context/editor-context.js index 6ed16eecc9..49e6880d13 100644 --- a/services/web/frontend/js/shared/context/editor-context.js +++ b/services/web/frontend/js/shared/context/editor-context.js @@ -11,6 +11,8 @@ import useBrowserWindow from '../hooks/use-browser-window' import { useIdeContext } from './ide-context' import { useProjectContext } from './project-context' import { useDetachContext } from './detach-context' +import getMeta from '../../utils/meta' +import { useUserContext } from './user-context' export const EditorContext = createContext() @@ -47,7 +49,7 @@ EditorContext.Provider.propTypes = { export function EditorProvider({ children, settings }) { const ide = useIdeContext() - + const { id: userId } = useUserContext() const { role } = useDetachContext() const { owner, features } = useProjectContext({ @@ -170,8 +172,8 @@ export function EditorProvider({ children, settings }) { loading, renameProject, permissionsLevel, - isProjectOwner: owner?._id === window.user.id, - isRestrictedTokenMember: window.isRestrictedTokenMember, + isProjectOwner: owner?._id === userId, + isRestrictedTokenMember: getMeta('ol-isRestrictedTokenMember'), showSymbolPalette, toggleSymbolPalette, insertSymbol, @@ -185,10 +187,11 @@ export function EditorProvider({ children, settings }) { [ cobranding, features?.compileGroup, + owner, + userId, loading, renameProject, permissionsLevel, - owner?._id, showSymbolPalette, toggleSymbolPalette, insertSymbol, diff --git a/services/web/test/frontend/features/share-project-modal/components/share-project-modal.test.js b/services/web/test/frontend/features/share-project-modal/components/share-project-modal.test.js index 5c03d91796..430a4f4ab3 100644 --- a/services/web/test/frontend/features/share-project-modal/components/share-project-modal.test.js +++ b/services/web/test/frontend/features/share-project-modal/components/share-project-modal.test.js @@ -268,6 +268,8 @@ describe('', function () { }) it('only shows read-only token link to restricted token members', async function () { + window.metaAttributesCache.set('ol-isRestrictedTokenMember', true) + renderWithEditorContext(, { isRestrictedTokenMember: true, scope: { project: { ...project, publicAccesLevel: 'tokenBased' } },