d13n PathProvider (#38505) (#38574)

* d13n PathProvider
This commit is contained in:
Matthew Kime 2019-06-10 13:43:08 -05:00 committed by GitHub
parent d976a2423c
commit 7d3b5564af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 57 deletions

View file

@ -12,7 +12,7 @@ import { get } from 'lodash';
import { jobQueueClient } from 'plugins/reporting/lib/job_queue_client';
import { jobCompletionNotifications } from 'plugins/reporting/lib/job_completion_notifications';
import { JobStatuses } from '../constants/job_statuses';
import { PathProvider } from 'plugins/xpack_main/services/path';
import { Path } from 'plugins/xpack_main/services/path';
import { XPackInfoProvider } from 'plugins/xpack_main/services/xpack_info';
import { Poller } from '../../../../common/poller';
import {
@ -27,7 +27,7 @@ import { npStart } from 'ui/new_platform';
uiModules.get('kibana')
.run((Private, reportingPollConfig) => {
// Don't show users any reporting toasts until they're logged in.
if (Private(PathProvider).isUnauthenticated()) {
if (Path.isUnauthenticated()) {
return;
}

View file

@ -9,7 +9,7 @@ import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { uiModules } from 'ui/modules';
import { isSystemApiRequest } from 'ui/system_api';
import { PathProvider } from 'plugins/xpack_main/services/path';
import { Path } from 'plugins/xpack_main/services/path';
import { toastNotifications } from 'ui/notify';
import 'plugins/security/services/auto_logout';
import { SessionExpirationWarning } from '../components/session_expiration_warning';
@ -39,7 +39,7 @@ module.config(($httpProvider) => {
clearNotifications();
}
const isUnauthenticated = Private(PathProvider).isUnauthenticated();
const isUnauthenticated = Path.isUnauthenticated();
const notificationLifetime = 60 * 1000;
const notificationOptions = {
color: 'warning',

View file

@ -6,7 +6,7 @@
import { identity } from 'lodash';
import { uiModules } from 'ui/modules';
import { PathProvider } from 'plugins/xpack_main/services/path';
import { Path } from 'plugins/xpack_main/services/path';
import 'plugins/security/services/auto_logout';
function isUnauthorizedResponseAllowed(response) {
@ -20,8 +20,8 @@ function isUnauthorizedResponseAllowed(response) {
}
const module = uiModules.get('security');
module.factory('onUnauthorizedResponse', ($q, Private, autoLogout) => {
const isUnauthenticated = Private(PathProvider).isUnauthenticated();
module.factory('onUnauthorizedResponse', ($q, autoLogout) => {
const isUnauthenticated = Path.isUnauthenticated();
function interceptorFactory(responseHandler) {
return function interceptor(response) {
if (response.status === 401 && !isUnauthorizedResponseAllowed(response) && !isUnauthenticated) return autoLogout();

View file

@ -17,7 +17,7 @@ import { chromeNavControlsRegistry } from 'ui/registry/chrome_nav_controls';
import template from 'plugins/security/views/nav_control/nav_control.html';
import 'plugins/security/services/shield_user';
import '../account/account';
import { PathProvider } from 'plugins/xpack_main/services/path';
import { Path } from 'plugins/xpack_main/services/path';
import { XPackInfoProvider } from 'plugins/xpack_main/services/xpack_info';
import { chromeHeaderNavControlsRegistry } from 'ui/registry/chrome_header_nav_controls';
@ -34,7 +34,7 @@ const module = uiModules.get('security', ['kibana']);
module.controller('securityNavController', ($scope, ShieldUser, globalNavState, kbnBaseUrl, Private) => {
const xpackInfo = Private(XPackInfoProvider);
const showSecurityLinks = xpackInfo.get('features.security.showLinks');
if (Private(PathProvider).isUnauthenticated() || !showSecurityLinks) return;
if (Path.isUnauthenticated() || !showSecurityLinks) return;
$scope.user = ShieldUser.getCurrent();
$scope.route = `${kbnBaseUrl}#/account`;
@ -61,7 +61,7 @@ chromeHeaderNavControlsRegistry.register((ShieldUser, kbnBaseUrl, Private) => ({
render(el) {
const xpackInfo = Private(XPackInfoProvider);
const showSecurityLinks = xpackInfo.get('features.security.showLinks');
if (Private(PathProvider).isUnauthenticated() || !showSecurityLinks) return null;
if (Path.isUnauthenticated() || !showSecurityLinks) return null;
const props = {
user: ShieldUser.getCurrent(),

View file

@ -10,7 +10,7 @@ import { SpacesManager } from 'plugins/spaces/lib/spaces_manager';
import template from 'plugins/spaces/views/nav_control/nav_control.html';
import { NavControlPopover } from 'plugins/spaces/views/nav_control/nav_control_popover';
// @ts-ignore
import { PathProvider } from 'plugins/xpack_main/services/path';
import { Path } from 'plugins/xpack_main/services/path';
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import ReactDOM from 'react-dom';
@ -44,9 +44,7 @@ let spacesManager: SpacesManager;
module.controller(
'spacesNavController',
($scope: any, $http: any, chrome: any, Private: any, activeSpace: any) => {
const pathProvider = Private(PathProvider);
($scope: any, $http: any, chrome: any, activeSpace: any) => {
const domNode = document.getElementById(`spacesNavReactRoot`);
const spaceSelectorURL = chrome.getInjected('spaceSelectorURL');
@ -55,7 +53,7 @@ module.controller(
let mounted = false;
$scope.$parent.$watch('isVisible', function isVisibleWatcher(isVisible: boolean) {
if (isVisible && !mounted && !pathProvider.isUnauthenticated()) {
if (isVisible && !mounted && !Path.isUnauthenticated()) {
render(
<I18nContext>
<NavControlPopover
@ -94,33 +92,29 @@ module.service('spacesNavState', (activeSpace: any) => {
} as SpacesNavState;
});
chromeHeaderNavControlsRegistry.register(
($http: any, chrome: any, Private: any, activeSpace: any) => ({
name: 'spaces',
order: 1000,
side: NavControlSide.Left,
render(el: HTMLElement) {
const pathProvider = Private(PathProvider);
chromeHeaderNavControlsRegistry.register(($http: any, chrome: any, activeSpace: any) => ({
name: 'spaces',
order: 1000,
side: NavControlSide.Left,
render(el: HTMLElement) {
if (Path.isUnauthenticated()) {
return;
}
if (pathProvider.isUnauthenticated()) {
return;
}
const spaceSelectorURL = chrome.getInjected('spaceSelectorURL');
const spaceSelectorURL = chrome.getInjected('spaceSelectorURL');
spacesManager = new SpacesManager($http, chrome, spaceSelectorURL);
spacesManager = new SpacesManager($http, chrome, spaceSelectorURL);
ReactDOM.render(
<I18nContext>
<NavControlPopover
spacesManager={spacesManager}
activeSpace={activeSpace}
anchorPosition="downLeft"
buttonClass={SpacesHeaderNavButton}
/>
</I18nContext>,
el
);
},
})
);
ReactDOM.render(
<I18nContext>
<NavControlPopover
spacesManager={spacesManager}
activeSpace={activeSpace}
anchorPosition="downLeft"
buttonClass={SpacesHeaderNavButton}
/>
</I18nContext>,
el
);
},
}));

View file

@ -11,7 +11,7 @@ import { uiModules } from 'ui/modules';
import chrome from 'ui/chrome';
import { banners } from 'ui/notify';
import { DebounceProvider } from 'ui/debounce';
import { PathProvider } from 'plugins/xpack_main/services/path';
import { Path } from 'plugins/xpack_main/services/path';
import { XPackInfoProvider } from 'plugins/xpack_main/services/xpack_info';
import { xpackInfoSignature } from 'plugins/xpack_main/services/xpack_info_signature';
import { FormattedMessage } from '@kbn/i18n/react';
@ -21,7 +21,7 @@ const module = uiModules.get('xpack_main', []);
module.factory('checkXPackInfoChange', ($q, Private) => {
const xpackInfo = Private(XPackInfoProvider);
const debounce = Private(DebounceProvider);
const isUnauthenticated = Private(PathProvider).isUnauthenticated();
const isUnauthenticated = Path.isUnauthenticated();
let isLicenseExpirationBannerShown = false;
const notifyIfLicenseIsExpired = debounce(() => {

View file

@ -5,7 +5,7 @@
*/
import { uiModules } from 'ui/modules';
import { PathProvider } from 'plugins/xpack_main/services/path';
import { Path } from 'plugins/xpack_main/services/path';
import { Telemetry } from './telemetry';
import { fetchTelemetry } from './fetch_telemetry';
@ -13,9 +13,8 @@ function telemetryStart($injector) {
const telemetryEnabled = $injector.get('telemetryEnabled');
if (telemetryEnabled) {
const Private = $injector.get('Private');
// no telemetry for non-logged in users
if (Private(PathProvider).isUnauthenticated()) { return; }
if (Path.isUnauthenticated()) { return; }
const $http = $injector.get('$http');
const sender = new Telemetry($injector, () => fetchTelemetry($http));

View file

@ -5,7 +5,7 @@
*/
import chrome from 'ui/chrome';
import { PathProvider } from 'plugins/xpack_main/services/path';
import { Path } from 'plugins/xpack_main/services/path';
import { fetchTelemetry } from '../fetch_telemetry';
import { renderBanner } from './render_banner';
import { shouldShowBanner } from './should_show_banner';
@ -31,7 +31,7 @@ async function asyncInjectBanner($injector) {
}
// and no banner for non-logged in users
if (Private(PathProvider).isUnauthenticated()) {
if (Path.isUnauthenticated()) {
return;
}

View file

@ -6,11 +6,9 @@
import chrome from 'ui/chrome';
export function PathProvider($window) {
const path = chrome.removeBasePath($window.location.pathname);
return {
isUnauthenticated() {
return path === '/login' || path === '/logout' || path === '/logged_out' || path === '/status';
}
};
}
export const Path = {
isUnauthenticated() {
const path = chrome.removeBasePath(window.location.pathname);
return path === '/login' || path === '/logout' || path === '/logged_out' || path === '/status';
}
};