Przeglądaj źródła

HUE-7588 [core] Option to disable Hue 3 switching

Off by default in 4.2.
On by default in 4.3.
Check can't be in middleware as many API calls and static files do not have the /hue prefix.
Romain Rigaux 8 lat temu
rodzic
commit
cd0e726

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

@@ -31,6 +31,9 @@
   # Choose whether to enable the new Hue 4 interface.
   ## is_hue_4=true
 
+  # Choose whether to still allow users to enable the old Hue 3 interface.
+  ## disable_hue_3=false
+
   # A comma-separated list of available Hue load balancers
   ## hue_load_balancer=
 

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

@@ -35,6 +35,9 @@
   # Choose whether to enable the new Hue 4 interface.
   ## is_hue_4=true
 
+  # Choose whether to still allow users to enable the old Hue 3 interface.
+  ## disable_hue_3=false
+
   # A comma-separated list of available Hue load balancers
   ## hue_load_balancer=
 

+ 0 - 1
desktop/core/src/desktop/api2.py

@@ -18,7 +18,6 @@
 import logging
 import json
 import StringIO
-import re
 import tempfile
 import zipfile
 

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

@@ -1409,6 +1409,13 @@ IS_HUE_4 = Config( # To remove in Hue 5
   help=_('Choose whether to enable the new Hue 4 interface.')
 )
 
+DISABLE_HUE_3 = Config( # To remove in Hue 5
+  key='disable_hue_3',
+  default=False,
+  type=coerce_bool,
+  help=_('Choose whether to still allow users to enable the old Hue 3 interface.')
+)
+
 
 def get_clusters():
   if CLUSTERS.get():

+ 6 - 0
desktop/core/src/desktop/templates/common_header.mako

@@ -222,6 +222,12 @@ if USE_NEW_EDITOR.get():
 
 ${ hueIcons.symbols() }
 
+% if conf.DISABLE_HUE_3.get() and conf.IS_HUE_4.get() and request.environ.get("PATH_INFO").find("/hue/") < 0:
+  <script>
+    window.location.replace("/");
+  </script>
+% endif
+
 % if banner_message or conf.CUSTOM.BANNER_TOP_HTML.get():
   <div class="banner">
     ${ banner_message or conf.CUSTOM.BANNER_TOP_HTML.get() | n,unicode }

+ 1 - 1
desktop/core/src/desktop/templates/common_header_footer_components.mako

@@ -521,7 +521,7 @@ from metadata.conf import has_optimizer, OPTIMIZER
       set: version
     }, function (data) {
       if (data && data.status == 0) {
-        location.href = version === 3 ? window.location.pathname.substr(4) + window.location.search : '/hue' + window.location.pathname + window.location.search
+        location.href = version === 3 && '${ conf.DISABLE_HUE_3.get() }' == 'False' ? window.location.pathname.substr(4) + window.location.search : '/hue' + window.location.pathname + window.location.search
       }
       else {
         $.jHueNotify.error("${ _('An error occurred while saving your default Hue preference. Please try again...') }");

+ 2 - 0
desktop/core/src/desktop/templates/hue.mako

@@ -221,7 +221,9 @@ ${ hueIcons.symbols() }
             % if user.is_superuser:
             <li data-bind="hueLink: '/useradmin/users/'"><a href="javascript: void(0);"><i class="fa fa-fw fa-group"></i> ${_('Manage Users')}</a></li>
             % endif
+            % if not conf.DISABLE_HUE_3.get():
             <li><a href="javascript:void(0)" onclick="huePubSub.publish('set.hue.version', 3)"><i class="fa fa-fw fa-exchange"></i> ${_('Switch to Hue 3')}</a></li>
+            % endif
             <li><a href="http://gethue.com" target="_blank"><span class="dropdown-no-icon">${_('Help')}</span></a></li>
             <li><a href="javascript:void(0)" onclick="huePubSub.publish('show.welcome.tour')"><span class="dropdown-no-icon">${_('Welcome Tour')}</span></a></li>
             % if user.is_superuser:

+ 3 - 3
desktop/core/src/desktop/views.py

@@ -46,7 +46,7 @@ import desktop.log.log_buffer
 from desktop import appmanager
 from desktop.api import massaged_tags_for_json, massaged_documents_for_json, _get_docs
 
-from desktop.conf import USE_NEW_EDITOR, IS_HUE_4, HUE_LOAD_BALANCER, get_clusters
+from desktop.conf import USE_NEW_EDITOR, IS_HUE_4, HUE_LOAD_BALANCER, get_clusters, DISABLE_HUE_3
 from desktop.lib import django_mako
 from desktop.lib.conf import GLOBAL_CONFIG, BoundConfig
 from desktop.lib.django_util import JsonResponse, login_notrequired, render
@@ -347,11 +347,11 @@ def unsupported(request):
   return render('unsupported.mako', request, None)
 
 def index(request):
-  is_hue_4 = IS_HUE_4.get()
+  is_hue_4 = IS_HUE_4.get() or DISABLE_HUE_3.get()
   if is_hue_4:
     try:
       user_hue_version = json.loads(UserPreferences.objects.get(user=request.user, key='hue_version').value)
-      is_hue_4 = user_hue_version >= 4
+      is_hue_4 = user_hue_version >= 4 or DISABLE_HUE_3.get()
     except UserPreferences.DoesNotExist:
       pass