Bläddra i källkod

HUE-9628 [Deprecation Warning] Using user.is_authenticated() and user.is_anonymous() as a method is deprecated

ayush.goyal 5 år sedan
förälder
incheckning
77c22a3799

+ 1 - 1
apps/about/src/about/templates/admin_wizard.mako

@@ -265,7 +265,7 @@ ${ layout.menubar(section='quick_start') }
           <br/>
           <br/>
           <span class="pull-right muted">${ _('Hue and the Hue logo are trademarks of Cloudera, Inc.') }</span>
-          % if not user.is_authenticated():
+          % if not user.is_authenticated:
             <br/>
             <a href="${ url('desktop_views_home2') }" class="btn btn-primary" style="margin-top: 50px;margin-bottom: 20px">
               <i class="fa fa-sign-in"></i> ${ _('Sign in now!') }

+ 6 - 4
apps/useradmin/src/useradmin/middleware.py

@@ -55,7 +55,7 @@ class LdapSynchronizationMiddleware(object):
     if request.method == "GET":
       server = request.GET.get('server')
 
-    if not user or not user.is_authenticated():
+    if not user or not user.is_authenticated:
       return
 
     if not User.objects.filter(username=user.username, userprofile__creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists():
@@ -83,7 +83,7 @@ class LastActivityMiddleware(object):
   def process_request(self, request):
     user = request.user
 
-    if not user or not user.is_authenticated():
+    if not user or not user.is_authenticated:
       return
 
     profile = get_profile(user)
@@ -128,11 +128,13 @@ class ConcurrentUserSessionMiddleware(object):
     except AttributeError: # When the request does not store user. We care only about the login request which does store the user.
       return response
 
-    if request.user.is_authenticated() and request.session.modified and request.user.id: # request.session.modified checks if a user just logged in
+    # request.session.modified checks if a user just logged in
+    if request.user.is_authenticated and request.session.modified and request.user.id:
       limit = SESSION.CONCURRENT_USER_SESSION_LIMIT.get()
       if limit:
         count = 1
-        for session in Session.objects.filter(~Q(session_key=request.session.session_key), expire_date__gte=datetime.now()).order_by('-expire_date'):
+        for session in Session.objects.filter(~Q(session_key=request.session.session_key),
+            expire_date__gte=datetime.now()).order_by('-expire_date'):
           data = session.get_decoded()
           if data.get('_auth_user_id') == str(request.user.id):
             if count >= limit:

+ 2 - 2
apps/useradmin/src/useradmin/organization.py

@@ -32,7 +32,7 @@ LOG = logging.getLogger(__name__)
 
 def get_user_request_organization():
   request = CrequestMiddleware.get_request()
-  return request.user.organization if request and hasattr(request, 'user') and request.user.is_authenticated() else None
+  return request.user.organization if request and hasattr(request, 'user') and request.user.is_authenticated else None
 
 
 def _fitered_queryset(queryset, by_owner=False):
@@ -41,7 +41,7 @@ def _fitered_queryset(queryset, by_owner=False):
   # Avoid infinite recursion on very first retrieval of the user
   if ENABLE_ORGANIZATIONS.get() and \
       request and hasattr(request, 'user') and hasattr(request.user, '_wrapped') and type(request.user._wrapped) is not object and \
-      request.user.is_authenticated():
+      request.user.is_authenticated:
     if by_owner:
       filters = {'owner__organization': request.user.organization}
     else:

+ 1 - 1
desktop/core/src/desktop/auth/backend.py

@@ -138,7 +138,7 @@ def is_admin(user):
   if hasattr(user, 'is_superuser') and not ENABLE_ORGANIZATIONS.get():
     is_admin = user.is_superuser
 
-  if not is_admin and user.is_authenticated():
+  if not is_admin and user.is_authenticated:
     try:
       user = rewrite_user(user)
       is_admin = user.is_admin if ENABLE_ORGANIZATIONS.get() else user.has_hue_permission(action="superuser", app="useradmin")

+ 4 - 4
desktop/core/src/desktop/auth/views.py

@@ -185,14 +185,14 @@ def dt_login(request, from_modal=False):
     if hasattr(request, 'fs') and (
         'KnoxSpnegoDjangoBackend' in backend_names or 'SpnegoDjangoBackend' in backend_names or 'OIDCBackend' in backend_names or
         'SAML2Backend' in backend_names
-      ) and request.user.is_authenticated():
+      ) and request.user.is_authenticated:
       if request.fs is None:
         request.fs = fsmanager.get_filesystem(request.fs_ref)
       try:
         ensure_home_directory(request.fs, request.user)
       except (IOError, WebHdfsException) as e:
         LOG.error('Could not create home directory for %s user %s.' % ('OIDC' if 'OIDCBackend' in backend_names else 'SAML', request.user))
-    if request.user.is_authenticated() and not from_modal:
+    if request.user.is_authenticated and not from_modal:
       return HttpResponseRedirect(redirect_to)
 
   if is_active_directory and not is_ldap_option_selected and \
@@ -220,7 +220,7 @@ def dt_login(request, from_modal=False):
     'user': request.user
   })
 
-  if not request.user.is_authenticated():
+  if not request.user.is_authenticated:
     response.delete_cookie(LOAD_BALANCER_COOKIE) # Note: might be re-balanced to another Hue on login.
 
   return response
@@ -325,7 +325,7 @@ def oauth_authenticated(request):
 
 @login_notrequired
 def oidc_failed(request):
-  if request.user.is_authenticated():
+  if request.user.is_authenticated:
     return HttpResponseRedirect('/')
   access_warn(request, "401 Unauthorized by oidc")
   return render("oidc_failed.mako", request, dict(uri=request.build_absolute_uri()), status=401)

+ 1 - 1
desktop/core/src/desktop/conf.py

@@ -2367,4 +2367,4 @@ def is_gs_enabled():
 
 def has_gs_access(user):
   from desktop.auth.backend import is_admin
-  return user.is_authenticated() and user.is_active and (is_admin(user) or user.has_hue_permission(action="gs_access", app="filebrowser"))
+  return user.is_authenticated and user.is_active and (is_admin(user) or user.has_hue_permission(action="gs_access", app="filebrowser"))

+ 3 - 1
desktop/core/src/desktop/lib/fs/proxyfs.py

@@ -79,7 +79,9 @@ class ProxyFS(object):
       if not filebrowser_action:
         return True
       user = rewrite_user(User.objects.get(username=self.getuser()))
-      return user.is_authenticated() and user.is_active and (is_admin(user) or not filebrowser_action or user.has_hue_permission(action=filebrowser_action, app="filebrowser"))
+      return user.is_authenticated() and user.is_active and \
+        (is_admin(user) or not filebrowser_action or user.has_hue_permission(action=filebrowser_action, app="filebrowser"))
+
     except User.DoesNotExist:
       LOG.exception('proxyfs.has_access()')
       return False

+ 5 - 5
desktop/core/src/desktop/middleware.py

@@ -132,7 +132,7 @@ class ClusterMiddleware(object):
 
     request.fs = None
 
-    if request.user.is_authenticated():
+    if request.user.is_authenticated:
       request.fs = fsmanager.get_filesystem(request.fs_ref)
 
       if request.fs is not None:
@@ -308,7 +308,7 @@ class LoginAndPermissionMiddleware(object):
       return None
 
     # If user is logged in, check that he has permissions to access the app
-    if request.user.is_active and request.user.is_authenticated():
+    if request.user.is_active and request.user.is_authenticated:
       AppSpecificMiddleware.augment_request_with_app(request, view_func)
 
       # Until Django 1.3 which resolves returning the URL name, just do a match of the name of the view
@@ -429,7 +429,7 @@ class AuditLoggingMiddleware(object):
     username = 'anonymous'
     if request.audit.get('username', None):
       username = request.audit.get('username')
-    elif hasattr(request, 'user') and not request.user.is_anonymous():
+    elif hasattr(request, 'user') and not request.user.is_anonymous:
       username = request.user.get_username()
     return username
 
@@ -706,7 +706,7 @@ class SpnegoMiddleware(object):
               request.META['Return-401'] = ''
               return
 
-          if request.user.is_authenticated():
+          if request.user.is_authenticated:
             if request.user.username == self.clean_username(username, request):
               return
 
@@ -731,7 +731,7 @@ class SpnegoMiddleware(object):
         request.META['Return-401'] = ''
         return
     else:
-      if not request.user.is_authenticated():
+      if not request.user.is_authenticated:
         request.META['Return-401'] = ''
       return
 

+ 2 - 2
desktop/core/src/desktop/models.py

@@ -1941,7 +1941,7 @@ class ClusterConfig(object):
         'buttonName': _('Browse'),
         'tooltip': hdfs_connector,
         'page': '/filebrowser/' + (
-          not self.user.is_anonymous() and
+          not self.user.is_anonymous and
           'view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS) or ''
         )
       })
@@ -2169,7 +2169,7 @@ class Cluster(object):
 def _get_apps(user, section=None):
   current_app = None
   other_apps = []
-  if user.is_authenticated():
+  if user.is_authenticated:
     apps_list = appmanager.get_apps_dict(user)
     apps = list(apps_list.values())
     for app in apps:

+ 5 - 5
desktop/core/src/desktop/templates/common_header.mako

@@ -135,7 +135,7 @@ if USE_NEW_EDITOR.get():
 
   ${ commonHeaderFooterComponents.header_i18n_redirection() }
 
-  % if user.is_authenticated():
+  % if user.is_authenticated:
   <%
     global_constants_url = '/desktop/globalJsConstants.js?v=' + hue_version()
   %>
@@ -158,13 +158,13 @@ if USE_NEW_EDITOR.get():
   <script src="${ static('desktop/ext/js/moment-timezone-with-data.min.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/ext/js/tzdetect.js') }" type="text/javascript" charset="utf-8"></script>
 
-% if user.is_authenticated():
+% if user.is_authenticated:
   ${ hueAceAutocompleter.hueAceAutocompleter() }
 %endif
 
   ${ commonHeaderFooterComponents.header_pollers(user, is_s3_enabled, apps) }
 
-% if user.is_authenticated():
+% if user.is_authenticated:
   <script src="${ static('desktop/ext/js/localforage.min.js') }"></script>
 
   <script type="text/javascript">
@@ -223,7 +223,7 @@ ${ hueIcons.symbols() }
 <div class="navigator">
   <div class="pull-right">
 
-  % if user.is_authenticated() and section != 'login':
+  % if user.is_authenticated and section != 'login':
   <ul class="nav nav-pills">
     <li class="divider-vertical"></li>
     % if 'filebrowser' in apps:
@@ -329,7 +329,7 @@ ${ hueIcons.symbols() }
         <use xlink:href="#hi-logo"></use>
       </svg>
     </a>
-    % if user.is_authenticated() and section != 'login':
+    % if user.is_authenticated and section != 'login':
      <ul class="nav nav-pills pull-left">
        <li><a title="${_('My documents')}" data-rel="navigator-tooltip" data-bind="hueLink: '${ home_url }'" style="padding-bottom:2px!important"><i class="fa fa-home" style="font-size: 19px"></i></a></li>
        <%

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

@@ -83,7 +83,7 @@
   window.HAS_SQL_DASHBOARD = '${ HAS_SQL_ENABLED.get() }' === 'True';
   window.CUSTOM_DASHBOARD_URL = '${ CUSTOM_DASHBOARD_URL.get() }';
 
-  window.DROPZONE_HOME_DIR = '${ user.get_home_directory() if not user.is_anonymous() else "" }';
+  window.DROPZONE_HOME_DIR = '${ user.get_home_directory() if not user.is_anonymous else "" }';
 
   window.DOWNLOAD_ROW_LIMIT = ${ DOWNLOAD_ROW_LIMIT.get() if hasattr(DOWNLOAD_ROW_LIMIT, 'get') and DOWNLOAD_ROW_LIMIT.get() >= 0 else 'undefined' };
   window.DOWNLOAD_BYTES_LIMIT = ${ DOWNLOAD_BYTES_LIMIT.get() if hasattr(DOWNLOAD_BYTES_LIMIT, 'get') and DOWNLOAD_BYTES_LIMIT.get() >= 0 else 'undefined' };

+ 1 - 1
desktop/libs/aws/src/aws/conf.py

@@ -317,7 +317,7 @@ def has_iam_metadata():
 
 def has_s3_access(user):
   from desktop.auth.backend import is_admin
-  return user.is_authenticated() and user.is_active and (is_admin(user) or user.has_hue_permission(action="s3_access", app="filebrowser"))
+  return user.is_authenticated and user.is_active and (is_admin(user) or user.has_hue_permission(action="s3_access", app="filebrowser"))
 
 
 def config_validator(user):

+ 7 - 5
desktop/libs/azure/src/azure/conf.py

@@ -146,18 +146,20 @@ ABFS_CLUSTERS = UnspecifiedConfigSection(
 )
 
 def is_adls_enabled():
-  return ('default' in list(AZURE_ACCOUNTS.keys()) and AZURE_ACCOUNTS['default'].get_raw() and AZURE_ACCOUNTS['default'].CLIENT_ID.get() or (conf_idbroker.is_idbroker_enabled('azure') and has_azure_metadata())) and 'default' in list(ADLS_CLUSTERS.keys())
+  return ('default' in list(AZURE_ACCOUNTS.keys()) and AZURE_ACCOUNTS['default'].get_raw() and AZURE_ACCOUNTS['default'].CLIENT_ID.get() \
+    or (conf_idbroker.is_idbroker_enabled('azure') and has_azure_metadata())) and 'default' in list(ADLS_CLUSTERS.keys())
 
 def is_abfs_enabled():
-  return ('default' in list(AZURE_ACCOUNTS.keys()) and AZURE_ACCOUNTS['default'].get_raw() and AZURE_ACCOUNTS['default'].CLIENT_ID.get() or (conf_idbroker.is_idbroker_enabled('azure') and has_azure_metadata())) and 'default' in list(ABFS_CLUSTERS.keys())
+  return ('default' in list(AZURE_ACCOUNTS.keys()) and AZURE_ACCOUNTS['default'].get_raw() and AZURE_ACCOUNTS['default'].CLIENT_ID.get() \
+    or (conf_idbroker.is_idbroker_enabled('azure') and has_azure_metadata())) and 'default' in list(ABFS_CLUSTERS.keys())
 
 def has_adls_access(user):
   from desktop.auth.backend import is_admin
-  return user.is_authenticated() and user.is_active and (is_admin(user) or user.has_hue_permission(action="adls_access", app="filebrowser"))
+  return user.is_authenticated and user.is_active and (is_admin(user) or user.has_hue_permission(action="adls_access", app="filebrowser"))
 
 def has_abfs_access(user):
   from desktop.auth.backend import is_admin
-  return user.is_authenticated() and user.is_active and (is_admin(user) or user.has_hue_permission(action="abfs_access", app="filebrowser"))
+  return user.is_authenticated and user.is_active and (is_admin(user) or user.has_hue_permission(action="abfs_access", app="filebrowser"))
 
 def azure_metadata():
   global AZURE_METADATA
@@ -166,7 +168,7 @@ def azure_metadata():
     client = http_client.HttpClient(META_DATA_URL, logger=LOG)
     root = resource.Resource(client)
     try:
-      AZURE_METADATA = root.get('/compute', params={'api-version':'2019-06-04', 'format':'json'}, headers={'Metadata': 'true'})
+      AZURE_METADATA = root.get('/compute', params={'api-version': '2019-06-04', 'format': 'json'}, headers={'Metadata': 'true'})
     except Exception as e:
       AZURE_METADATA = False
   return AZURE_METADATA

+ 1 - 1
desktop/libs/notebook/src/notebook/conf.py

@@ -375,7 +375,7 @@ def config_validator(user, interpreters=None):
   client = Client()
   client.force_login(user=user)
 
-  if not user.is_authenticated():
+  if not user.is_authenticated:
     res.append(('Editor', _('Could not authenticate with user %s to validate interpreters') % user))
 
   if interpreters is None:

+ 1 - 1
docs/gethue/content/en/posts/2013-10-01-group-synchronization-backends-in-hue.md

@@ -74,7 +74,7 @@ categories:
   def sync(self, request):
     user = request.user
 
-    if not user or not user.is_authenticated():
+    if not user or not user.is_authenticated:
       return
 
     if not User.objects.filter(username=user.username, userprofile__creation_method=str(UserProfile.CreationMethod.EXTERNAL)).exists():