From d1b302c24906d0059d24d1909cc07f007c0541ae Mon Sep 17 00:00:00 2001
From: Bram Wiepjes <bramw@protonmail.com>
Date: Tue, 26 Jul 2022 12:20:09 +0000
Subject: [PATCH] Resolve "Introduce environment variable to disable Google
 docs file preview"

---
 .env.example                                      | 1 +
 changelog.md                                      | 1 +
 docker-compose.local-build.yml                    | 1 +
 docker-compose.no-caddy.yml                       | 1 +
 docker-compose.yml                                | 1 +
 docs/installation/configuration.md                | 1 +
 docs/technical/introduction.md                    | 8 +++++---
 web-frontend/modules/core/module.js               | 4 ++++
 web-frontend/modules/database/filePreviewTypes.js | 4 ++++
 9 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/.env.example b/.env.example
index c47952762..ec7ce1c4c 100644
--- a/.env.example
+++ b/.env.example
@@ -93,6 +93,7 @@ DATABASE_NAME=baserow
 
 # BASEROW_DISABLE_PUBLIC_URL_CHECK=
 # DOWNLOAD_FILE_VIA_XHR=
+# BASEROW_DISABLE_GOOGLE_DOCS_FILE_PREVIEW=
 
 # BASEROW_PLUGIN_GIT_REPOS=
 # BASEROW_PLUGIN_URLS=
diff --git a/changelog.md b/changelog.md
index 0c0d0f1ed..8933acf53 100644
--- a/changelog.md
+++ b/changelog.md
@@ -21,6 +21,7 @@ For example:
 * Added option to use view's filters and sorting when listing rows. [#190](https://gitlab.com/bramw/baserow/-/issues/190)
 * Fixed bug with 404 middleware returning different 404 error messages based on the endpoint.
 * Made it possible to import data into an existing table. [#342](https://gitlab.com/bramw/baserow/-/issues/342)
+* Introduced environment variable to disable Google docs file preview. [#1074](https://gitlab.com/bramw/baserow/-/issues/1074)
 
 ### Bug Fixes
 
diff --git a/docker-compose.local-build.yml b/docker-compose.local-build.yml
index 80f5c0e30..72b0265cb 100644
--- a/docker-compose.local-build.yml
+++ b/docker-compose.local-build.yml
@@ -153,6 +153,7 @@ services:
       BASEROW_DISABLE_PUBLIC_URL_CHECK:
       INITIAL_TABLE_DATA_LIMIT:
       DOWNLOAD_FILE_VIA_XHR:
+      BASEROW_DISABLE_GOOGLE_DOCS_FILE_PREVIEW:
       HOURS_UNTIL_TRASH_PERMANENTLY_DELETED:
       DISABLE_ANONYMOUS_PUBLIC_VIEW_WS_CONNECTIONS:
       FEATURE_FLAGS:
diff --git a/docker-compose.no-caddy.yml b/docker-compose.no-caddy.yml
index f820168a6..690e578c8 100644
--- a/docker-compose.no-caddy.yml
+++ b/docker-compose.no-caddy.yml
@@ -143,6 +143,7 @@ services:
       BASEROW_DISABLE_PUBLIC_URL_CHECK:
       INITIAL_TABLE_DATA_LIMIT:
       DOWNLOAD_FILE_VIA_XHR:
+      BASEROW_DISABLE_GOOGLE_DOCS_FILE_PREVIEW:
       HOURS_UNTIL_TRASH_PERMANENTLY_DELETED:
       DISABLE_ANONYMOUS_PUBLIC_VIEW_WS_CONNECTIONS:
       FEATURE_FLAGS:
diff --git a/docker-compose.yml b/docker-compose.yml
index 9cbd8b0b2..7eacdc562 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -164,6 +164,7 @@ services:
       BASEROW_DISABLE_PUBLIC_URL_CHECK:
       INITIAL_TABLE_DATA_LIMIT:
       DOWNLOAD_FILE_VIA_XHR:
+      BASEROW_DISABLE_GOOGLE_DOCS_FILE_PREVIEW:
       HOURS_UNTIL_TRASH_PERMANENTLY_DELETED:
       DISABLE_ANONYMOUS_PUBLIC_VIEW_WS_CONNECTIONS:
       FEATURE_FLAGS:
diff --git a/docs/installation/configuration.md b/docs/installation/configuration.md
index 4045850b8..155c9f660 100644
--- a/docs/installation/configuration.md
+++ b/docs/installation/configuration.md
@@ -143,6 +143,7 @@ The installation methods referred to in the variable descriptions are:
 | DOWNLOAD\_FILE\_VIA\_XHR                          | Set to \`1\` to force download links to download files via XHR query to bypass \`Content-Disposition: inline\` that can't be overridden in another way. If your files are stored under another origin, you also must add CORS headers to your server.                                                                                                                                                                                                                                                                                                                                                                                                                                  | 0                                                                                                                                                                                      |
 | BASEROW\_DISABLE\_PUBLIC\_URL\_CHECK              | When opening the Baserow login page a check is run to ensure the PUBLIC\_BACKEND\_URL/BASEROW\_PUBLIC\_URL variables are set correctly and your browser can correctly connect to the backend. If misconfigured an error is shown. If you wish to disable this check and warning set this to any non empty value.                                                                                                                                                                                                                                                                                                                                                                       |                                                                                                                                                                                       |
 | ADDITIONAL\_MODULES                               | **Internal** A list of file paths to Nuxt module.js files to load as additional Nuxt modules into Baserow on startup. | |
+| BASEROW\_DISABLE\_GOOGLE\_DOCS\_FILE\_PREVIEW     | Set to \`true\` or \`1\` to disable Google docs file preview.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | |
 
 ### `baserow/baserow` Image only Configuration
 
diff --git a/docs/technical/introduction.md b/docs/technical/introduction.md
index 493257320..c50410b88 100644
--- a/docs/technical/introduction.md
+++ b/docs/technical/introduction.md
@@ -94,10 +94,12 @@ are accepted.
   download files via XHR query to bypass `Content-Disposition: inline` that
   can't be overridden in another way. If your files are stored under another
   origin, you also must add CORS headers to your server.
+* `BASEROW_DISABLE_GOOGLE_DOCS_FILE_PREVIEW` (default ``): Set to `true` or `1` to
+  disable Google docs file preview in the web-frontend.
 * `PUBLIC_BACKEND_URL` (default `http://localhost:8000`): The publicly accessible URL of
-  the backend. For the development environment this is `http://localhost:8000`, but if
-  you change the port to 9000 it will be `http://localhost:9000`. You should be able to
-  lookup this url with your browser.
+ the backend. For the development environment this is `http://localhost:8000`, but if
+ you change the port to 9000 it will be `http://localhost:9000`. You should be able to
+ lookup this url with your browser.
 * `PRIVATE_BACKEND_URL` (default `http://backend:8000`): Not only the browser, but also
   the web-frontend server should be able to make HTTP requests to the backend. It might
   not have access to the `PUBLIC_BACKEND_URL` or there could be a more direct route,
diff --git a/web-frontend/modules/core/module.js b/web-frontend/modules/core/module.js
index eaa3fa19a..0e17358ca 100644
--- a/web-frontend/modules/core/module.js
+++ b/web-frontend/modules/core/module.js
@@ -93,6 +93,10 @@ export default function CoreModule(options) {
           key: 'FEATURE_FLAGS',
           default: '',
         },
+        {
+          key: 'BASEROW_DISABLE_GOOGLE_DOCS_FILE_PREVIEW',
+          default: '',
+        },
       ],
     },
   ])
diff --git a/web-frontend/modules/database/filePreviewTypes.js b/web-frontend/modules/database/filePreviewTypes.js
index c02b2d89c..aee05d9d7 100644
--- a/web-frontend/modules/database/filePreviewTypes.js
+++ b/web-frontend/modules/database/filePreviewTypes.js
@@ -125,6 +125,10 @@ export class GoogleDocFilePreview extends FilePreviewType {
   }
 
   isCompatible(mimeType, fileName) {
+    if (this.app.$env.BASEROW_DISABLE_GOOGLE_DOCS_FILE_PREVIEW) {
+      return false
+    }
+
     const conds = [
       'application/pdf',