浏览代码

HUE-7128 [core] Create an ENABLE_DOWNLOAD property in 'desktop' conf and use it for the editor and search dashboards

Ying Chen 8 年之前
父节点
当前提交
ea59bc9

+ 5 - 1
apps/beeswax/src/beeswax/views.py

@@ -32,7 +32,7 @@ from django.utils.translation import ugettext as _
 from django.core.urlresolvers import reverse
 from django.core.urlresolvers import reverse
 
 
 from desktop.appmanager import get_apps_dict
 from desktop.appmanager import get_apps_dict
-from desktop.conf import REDIRECT_WHITELIST
+from desktop.conf import ENABLE_DOWNLOAD, REDIRECT_WHITELIST
 from desktop.context_processors import get_app_name
 from desktop.context_processors import get_app_name
 from desktop.lib.paginator import Paginator
 from desktop.lib.paginator import Paginator
 from desktop.lib.django_util import JsonResponse
 from desktop.lib.django_util import JsonResponse
@@ -41,6 +41,7 @@ from desktop.lib.django_util import login_notrequired, get_desktop_uri_prefix
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.models import Document
 from desktop.models import Document
 from desktop.lib.parameterization import find_variables
 from desktop.lib.parameterization import find_variables
+from desktop.views import serve_403_error
 from notebook.models import escape_rows
 from notebook.models import escape_rows
 
 
 import beeswax.forms
 import beeswax.forms
@@ -369,6 +370,9 @@ def massage_query_history_for_json(app_name, query_history):
 
 
 
 
 def download(request, id, format):
 def download(request, id, format):
+  if not ENABLE_DOWNLOAD.get():
+    return serve_403_error(request)
+
   try:
   try:
     query_history = authorized_get_query_history(request, id, must_exist=True)
     query_history = authorized_get_query_history(request, id, must_exist=True)
     db = dbms.get(request.user, query_history.get_query_server_config())
     db = dbms.get(request.user, query_history.get_query_server_config())

+ 6 - 1
apps/filebrowser/src/filebrowser/conf.py

@@ -17,6 +17,7 @@
 
 
 from django.utils.translation import ugettext_lazy as _
 from django.utils.translation import ugettext_lazy as _
 
 
+from desktop.conf import ENABLE_DOWNLOAD
 from desktop.lib.conf import Config, coerce_bool
 from desktop.lib.conf import Config, coerce_bool
 
 
 
 
@@ -33,11 +34,15 @@ ARCHIVE_UPLOAD_TEMPDIR = Config(
   default=None,
   default=None,
   type=str)
   type=str)
 
 
+def get_desktop_enable_download():
+  """Get desktop enable_download default"""
+  return ENABLE_DOWNLOAD.get()
+
 SHOW_DOWNLOAD_BUTTON = Config(
 SHOW_DOWNLOAD_BUTTON = Config(
   key="show_download_button",
   key="show_download_button",
   help=_("whether to show the download button in hdfs file browser."),
   help=_("whether to show the download button in hdfs file browser."),
   type=coerce_bool,
   type=coerce_bool,
-  default=True)
+  dynamic_default=get_desktop_enable_download)
 
 
 SHOW_UPLOAD_BUTTON = Config(
 SHOW_UPLOAD_BUTTON = Config(
   key="show_upload_button",
   key="show_upload_button",

+ 4 - 0
desktop/conf.dist/hue.ini

@@ -172,6 +172,10 @@
   # Choose whether to show the new SQL editor.
   # Choose whether to show the new SQL editor.
   ## use_new_editor=true
   ## use_new_editor=true
 
 
+  # Global setting to allow or disable end user downloads in all Hue.
+  # e.g. Query result in Editors and Dashboards, file in File Browser...
+  ## enable_download=true
+
   # Choose whether to enable the new global search or not.
   # Choose whether to enable the new global search or not.
   ## use_new_global_search=true
   ## use_new_global_search=true
 
 

+ 4 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -176,6 +176,10 @@
   # Choose whether to show the new SQL editor.
   # Choose whether to show the new SQL editor.
   ## use_new_editor=true
   ## use_new_editor=true
 
 
+  # Global setting to allow or disable end user downloads in all Hue.
+  # e.g. Query result in Editors and Dashboards, file in File Browser...
+  ## enable_download=true
+
   # Choose whether to enable the new global search or not.
   # Choose whether to enable the new global search or not.
   ## use_new_global_search=true
   ## use_new_global_search=true
 
 

+ 6 - 0
desktop/core/src/desktop/conf.py

@@ -1349,6 +1349,12 @@ USE_NEW_EDITOR = Config( # To remove in Hue 4
   help=_('Choose whether to show the new SQL editor.')
   help=_('Choose whether to show the new SQL editor.')
 )
 )
 
 
+ENABLE_DOWNLOAD = Config(
+  key="enable_download",
+  help=_('Global setting to allow or disable end user downloads in all Hue (e.g. Query result in editors and dashboard, file in File Browser browsers...).'),
+  type=coerce_bool,
+  default=True)
+
 def is_hue4():
 def is_hue4():
   """Hue is configured to show version 4."""
   """Hue is configured to show version 4."""
   return IS_HUE_4.get()
   return IS_HUE_4.get()

+ 2 - 0
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1769,7 +1769,9 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
       </a>
       </a>
     </div>
     </div>
 
 
+    % if conf.ENABLE_DOWNLOAD.get():
     <div data-bind="component: { name: 'downloadSnippetResults', params: { snippet: $data, notebook: $parent } }" style="display:inline-block;"></div>
     <div data-bind="component: { name: 'downloadSnippetResults', params: { snippet: $data, notebook: $parent } }" style="display:inline-block;"></div>
+    % endif
   </div>
   </div>
 </script>
 </script>
 
 

+ 4 - 1
desktop/libs/notebook/src/notebook/views.py

@@ -23,7 +23,7 @@ from django.db.models import Q
 from django.shortcuts import redirect
 from django.shortcuts import redirect
 from django.utils.translation import ugettext as _
 from django.utils.translation import ugettext as _
 
 
-from desktop.conf import USE_NEW_EDITOR
+from desktop.conf import ENABLE_DOWNLOAD, USE_NEW_EDITOR
 from desktop.lib.django_util import render, JsonResponse
 from desktop.lib.django_util import render, JsonResponse
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.json_utils import JSONEncoderForHTML
 from desktop.lib.json_utils import JSONEncoderForHTML
@@ -306,6 +306,9 @@ def copy(request):
 
 
 @check_document_access_permission()
 @check_document_access_permission()
 def download(request):
 def download(request):
+  if not ENABLE_DOWNLOAD.get():
+    return serve_403_error(request)
+
   notebook = json.loads(request.POST.get('notebook', '{}'))
   notebook = json.loads(request.POST.get('notebook', '{}'))
   snippet = json.loads(request.POST.get('snippet', '{}'))
   snippet = json.loads(request.POST.get('snippet', '{}'))
   file_format = request.POST.get('format', 'csv')
   file_format = request.POST.get('format', 'csv')