1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-09 07:45:22 +02:00

feat(config): add base url support EE-506 (#5999)

This commit is contained in:
Prabhat Khera 2021-12-03 14:34:45 +13:00 committed by GitHub
parent 335f951e6b
commit 4aea5690a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 71 additions and 55 deletions

View file

@ -11,9 +11,7 @@ interface InputGroupSubComponents {
NumberInput: typeof NumberInput;
}
const InputGroup: typeof MainComponent &
InputGroupSubComponents = MainComponent as typeof MainComponent &
InputGroupSubComponents;
const InputGroup: typeof MainComponent & InputGroupSubComponents = MainComponent as typeof MainComponent & InputGroupSubComponents;
InputGroup.Addon = InputGroupAddon;
InputGroup.ButtonWrapper = InputGroupButtonWrapper;

View file

@ -2,18 +2,7 @@ import { arrayMove } from './utils';
it('moves items in an array', () => {
expect(arrayMove(['a', 'b', 'c'], 2, 0)).toEqual(['c', 'a', 'b']);
expect(
arrayMove(
[
{ name: 'Fred' },
{ name: 'Barney' },
{ name: 'Wilma' },
{ name: 'Betty' },
],
2,
1
)
).toEqual([
expect(arrayMove([{ name: 'Fred' }, { name: 'Barney' }, { name: 'Wilma' }, { name: 'Betty' }], 2, 1)).toEqual([
{ name: 'Fred' },
{ name: 'Wilma' },
{ name: 'Barney' },

View file

@ -10,23 +10,13 @@ export function arrayMove<T>(array: Array<T>, from: number, to: number) {
if (diff > 0) {
// move left
return [
...array.slice(0, to),
item,
...array.slice(to, from),
...array.slice(from + 1, length),
];
return [...array.slice(0, to), item, ...array.slice(to, from), ...array.slice(from + 1, length)];
}
if (diff < 0) {
// move right
const targetIndex = to + 1;
return [
...array.slice(0, from),
...array.slice(from + 1, targetIndex),
item,
...array.slice(targetIndex, length),
];
return [...array.slice(0, from), ...array.slice(from + 1, targetIndex), item, ...array.slice(targetIndex, length)];
}
return [...array];

View file

@ -0,0 +1,10 @@
/**
* calculates baseHref
*
* return [string]
*
*/
export function baseHref() {
const base = document.getElementById('base');
return base ? base.getAttribute('href') : '/';
}

View file

@ -1,3 +1,5 @@
import { baseHref } from '@/portainer/helpers/pathHelper';
angular.module('portainer.app').factory('WebhookHelper', [
'$location',
'API_ENDPOINT_WEBHOOKS',
@ -11,11 +13,11 @@ angular.module('portainer.app').factory('WebhookHelper', [
const displayPort = (protocol === 'http' && port === 80) || (protocol === 'https' && port === 443) ? '' : ':' + port;
helper.returnWebhookUrl = function (token) {
return `${protocol}://${$location.host()}${displayPort}/${API_ENDPOINT_WEBHOOKS}/${token}`;
return `${protocol}://${$location.host()}${displayPort}${baseHref()}${API_ENDPOINT_WEBHOOKS}/${token}`;
};
helper.returnStackWebhookUrl = function (token) {
return `${protocol}://${$location.host()}${displayPort}/${API_ENDPOINT_STACKS}/webhooks/${token}`;
return `${protocol}://${$location.host()}${displayPort}${baseHref()}${API_ENDPOINT_STACKS}/webhooks/${token}`;
};
return helper;

View file

@ -1,4 +1,5 @@
import { HIDE_INTERNAL_AUTH } from '@/portainer/feature-flags/feature-ids';
import { baseHref } from '@/portainer/helpers/pathHelper';
import providers, { getProviderByUrl } from './providers';
@ -95,7 +96,7 @@ export default class OAuthSettingsController {
}
if (this.settings.RedirectURI === '') {
this.settings.RedirectURI = window.location.origin;
this.settings.RedirectURI = window.location.origin + baseHref();
}
if (this.settings.AuthorizationURI) {

View file

@ -1,9 +1,11 @@
import { baseHref } from '@/portainer/helpers/pathHelper';
export default {
microsoft: {
authUrl: 'https://login.microsoftonline.com/TENANT_ID/oauth2/authorize',
accessTokenUrl: 'https://login.microsoftonline.com/TENANT_ID/oauth2/token',
resourceUrl: 'https://graph.windows.net/TENANT_ID/me?api-version=2013-11-08',
logoutUrl: `https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri=${window.location.origin}/#!/auth`,
logoutUrl: `https://login.microsoftonline.com/common/oauth2/v2.0/logout?post_logout_redirect_uri=${window.location.origin}${baseHref()}#!/auth`,
userIdentifier: 'userPrincipalName',
scopes: 'id,email,name',
},
@ -11,7 +13,7 @@ export default {
authUrl: 'https://accounts.google.com/o/oauth2/auth',
accessTokenUrl: 'https://accounts.google.com/o/oauth2/token',
resourceUrl: 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json',
logoutUrl: `https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=${window.location.origin}/#!/auth`,
logoutUrl: `https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=${window.location.origin}${baseHref()}#!/auth`,
userIdentifier: 'email',
scopes: 'profile email',
},

View file

@ -1,5 +1,6 @@
import { PortainerEndpointCreationTypes, PortainerEndpointTypes } from 'Portainer/models/endpoint/models';
import { getAgentShortVersion } from 'Portainer/views/endpoints/helpers';
import { baseHref } from '@/portainer/helpers/pathHelper';
import { EndpointSecurityFormData } from '../../../components/endpointSecurity/porEndpointSecurityModel';
angular
@ -84,7 +85,8 @@ angular
};
$scope.setDefaultPortainerInstanceURL = function () {
$scope.formValues.URL = window.location.origin;
const baseHREF = baseHref();
$scope.formValues.URL = window.location.origin + (baseHREF !== '/' ? baseHREF : '');
};
$scope.resetEndpointURL = function () {