Просмотр исходного кода

[SP] Prevent rendering of sync section in SP when git disabled (#15647)

GitOrigin-RevId: 0f4c43eeb0182e7288566eff1ceed861bb9c4338
Miguel Serrano 2 лет назад
Родитель
Сommit
42fe453096

+ 1 - 0
services/web/app/src/Features/Project/ProjectController.js

@@ -906,6 +906,7 @@ const ProjectController = {
               brandVariation,
               allowedImageNames,
               gitBridgePublicBaseUrl: Settings.gitBridgePublicBaseUrl,
+              gitBridgeEnabled: Features.hasFeature('git-bridge'),
               wsUrl,
               showSupport: Features.hasFeature('support'),
               showTemplatesServerPro,

+ 1 - 0
services/web/app/views/project/editor/meta.pug

@@ -11,6 +11,7 @@ meta(name="ol-isRestrictedTokenMember" data-type="boolean" content=isRestrictedT
 meta(name="ol-maxDocLength" data-type="json" content=maxDocLength)
 meta(name="ol-wikiEnabled" data-type="boolean" content=settings.proxyLearn)
 meta(name="ol-gitBridgePublicBaseUrl" content=gitBridgePublicBaseUrl)
+meta(name="ol-gitBridgeEnabled" data-type="boolean" content=gitBridgeEnabled)
 meta(name="ol-compilesUserContentDomain" content=settings.compilesUserContentDomain)
 meta(name="ol-fallbackCompileDomain" content=settings.pdfDownloadDomain)
 //- Set base path for Ace scripts loaded on demand/workers and don't use cdn

+ 7 - 0
services/web/frontend/js/features/editor-left-menu/components/sync-menu.tsx

@@ -11,6 +11,7 @@ const components = importOverleafModules('editorLeftMenuSync') as {
 export default function SyncMenu() {
   const { t } = useTranslation()
   const anonymous = getMeta('ol-anonymous') as boolean | undefined
+  const gitBridgeEnabled = getMeta('ol-gitBridgeEnabled', false) as boolean
 
   if (anonymous === true || anonymous === undefined) {
     return null
@@ -20,6 +21,12 @@ export default function SyncMenu() {
     return null
   }
 
+  // This flag can only be false in CE and Server Pro. In this case we skip rendering the
+  // entire sync section, since Dropbox and GitHub are never available in SP
+  if (!gitBridgeEnabled) {
+    return null
+  }
+
   return (
     <>
       <h4>{t('sync')}</h4>

+ 2 - 0
services/web/frontend/stories/editor-left-menu/sync-menu.stories.tsx

@@ -10,6 +10,7 @@ export default {
 
 export const WriteAccess = () => {
   window.metaAttributesCache.set('ol-anonymous', false)
+  window.metaAttributesCache.set('ol-gitBridgeEnabled', true)
   useScope({
     permissionsLevel: 'owner',
   })
@@ -23,6 +24,7 @@ export const WriteAccess = () => {
 
 export const ReadOnlyAccess = () => {
   window.metaAttributesCache.set('ol-anonymous', false)
+  window.metaAttributesCache.set('ol-gitBridgeEnabled', true)
   useScope({
     permissionsLevel: 'readOnly',
   })

+ 9 - 0
services/web/test/frontend/components/editor-left-menu/editor-left-menu.spec.tsx

@@ -43,6 +43,7 @@ describe('<EditorLeftMenu />', function () {
       window.metaAttributesCache.set('ol-overallThemes', overallThemes)
       window.metaAttributesCache.set('ol-allowedImageNames', allowedImageNames)
       window.metaAttributesCache.set('ol-anonymous', false)
+      window.metaAttributesCache.set('ol-gitBridgeEnabled', true)
       window.metaAttributesCache.set('ol-showSupport', true)
       window.metaAttributesCache.set('ol-user', {
         email: 'sherlock@holmes.co.uk',
@@ -319,6 +320,14 @@ describe('<EditorLeftMenu />', function () {
         cy.wait(['@user-status', '@project-status'])
         cy.findByText('Push to GitHub, pull to Overleaf')
       })
+
+      it('hides the entire sync section when git bridge is disabled', function () {
+        window.metaAttributesCache.set('ol-gitBridgeEnabled', false)
+
+        cy.findByRole('button', { name: 'Dropbox' }).should('not.exist')
+        cy.findByRole('button', { name: 'Git' }).should('not.exist')
+        cy.findByRole('button', { name: 'GitHub' }).should('not.exist')
+      })
     })
 
     describe('settings menu', function () {