Commit 376d9199 authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Daniel Goerz
Browse files

[BUGFIX] Handle URLs withouth a path

If the AJAX API receives a pre-composed URL with a path in front, the
current location of the document is now prepended.

Resolves: #90198
Releases: master
Change-Id: I94dcd12f83016ad1604e64f0e3d9bc6e61be5605
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63030


Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent 271a42de
......@@ -143,19 +143,29 @@ class AjaxRequest {
* @return {Promise<Response>}
*/
private async send(init: RequestInit = {}): Promise<Response> {
// Sanitize URL into a generic format, e.g. ensure a domain only url contains a trailing slash
let url = new URL(this.url, window.location.origin).toString();
if (this.queryArguments !== '') {
const delimiter = !this.url.includes('?') ? '?' : '&';
url += delimiter + this.queryArguments;
}
const response = await fetch(url, this.getMergedOptions(init));
const response = await fetch(this.composeRequestUrl(), this.getMergedOptions(init));
if (!response.ok) {
throw new ResponseError(response);
}
return response;
}
private composeRequestUrl(): string {
let url = this.url;
if (url.charAt(0) === '?') {
// URL is a search string only, prepend current location
url = window.location.origin + window.location.pathname + url;
}
url = new URL(url, window.location.origin).toString();
if (this.queryArguments !== '') {
const delimiter = !this.url.includes('?') ? '?' : '&';
url += delimiter + this.queryArguments;
}
return url;
}
/**
* Merge the incoming RequestInit object with the pre-defined default options
*
......
......@@ -160,6 +160,12 @@ describe('TYPO3/CMS/Core/Ajax/AjaxRequest', (): void => {
{foo: 'bar', bar: {baz: 'bencer'}},
window.location.origin + '/foo/bar?foo=bar&bar[baz]=bencer',
];
yield [
'fallback to current script if not defined',
'?foo=bar&baz=bencer',
{},
window.location.origin + window.location.pathname + '?foo=bar&baz=bencer',
];
}
for (let providedData of urlInputDataProvider()) {
......
......@@ -90,8 +90,8 @@ class Router {
if (typeof TYPO3.settings === 'undefined') {
TYPO3.settings = {
ajaxUrls: {
icons: '?install[controller]=icon&install[action]=getIcon',
icons_cache: '?install[controller]=icon&install[action]=getCacheIdentifier',
icons: window.location.origin + window.location.pathname + '?install[controller]=icon&install[action]=getIcon',
icons_cache: window.location.origin + window.location.pathname + '?install[controller]=icon&install[action]=getCacheIdentifier',
},
};
}
......
......@@ -10,4 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/
var __awaiter=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(s,o){function i(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,a)}c((r=r.apply(t,e||[])).next())}))};define(["require","exports","../BackwardCompat/JQueryNativePromises","./AjaxResponse","./ResponseError","./InputTransformer"],(function(t,e,n,r,s,o){"use strict";class i{constructor(t){this.queryArguments="",this.url=t,this.abortController=new AbortController,n.default.support()}withQueryArguments(t){const e=this.clone();return e.queryArguments=(""!==e.queryArguments?"&":"")+o.InputTransformer.toSearchParams(t),e}get(t={}){return __awaiter(this,void 0,void 0,(function*(){const e=yield this.send(Object.assign(Object.assign({},{method:"GET"}),t));return new r.AjaxResponse(e)}))}post(t,e={}){return __awaiter(this,void 0,void 0,(function*(){const n={body:"string"==typeof t?t:o.InputTransformer.toFormData(t),cache:"no-cache",method:"POST"},s=yield this.send(Object.assign(Object.assign({},n),e));return new r.AjaxResponse(s)}))}put(t,e={}){return __awaiter(this,void 0,void 0,(function*(){const n={body:"string"==typeof t?t:o.InputTransformer.toFormData(t),cache:"no-cache",method:"PUT"},s=yield this.send(Object.assign(Object.assign({},n),e));return new r.AjaxResponse(s)}))}delete(t={},e={}){return __awaiter(this,void 0,void 0,(function*(){const n={cache:"no-cache",method:"DELETE"};"object"==typeof t&&Object.keys(t).length>0?n.body=o.InputTransformer.toFormData(t):"string"==typeof t&&(n.body=t);const s=yield this.send(Object.assign(Object.assign({},n),e));return new r.AjaxResponse(s)}))}getAbort(){return this.abortController}clone(){return Object.assign(Object.create(this),this)}send(t={}){return __awaiter(this,void 0,void 0,(function*(){let e=new URL(this.url,window.location.origin).toString();if(""!==this.queryArguments){e+=(this.url.includes("?")?"&":"?")+this.queryArguments}const n=yield fetch(e,this.getMergedOptions(t));if(!n.ok)throw new s.ResponseError(n);return n}))}getMergedOptions(t){return Object.assign(Object.assign(Object.assign({},i.defaultOptions),t),{signal:this.abortController.signal})}}return i.defaultOptions={credentials:"same-origin"},i}));
\ No newline at end of file
var __awaiter=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(s,o){function i(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,a)}c((r=r.apply(t,e||[])).next())}))};define(["require","exports","../BackwardCompat/JQueryNativePromises","./AjaxResponse","./ResponseError","./InputTransformer"],(function(t,e,n,r,s,o){"use strict";class i{constructor(t){this.queryArguments="",this.url=t,this.abortController=new AbortController,n.default.support()}withQueryArguments(t){const e=this.clone();return e.queryArguments=(""!==e.queryArguments?"&":"")+o.InputTransformer.toSearchParams(t),e}get(t={}){return __awaiter(this,void 0,void 0,(function*(){const e=yield this.send(Object.assign(Object.assign({},{method:"GET"}),t));return new r.AjaxResponse(e)}))}post(t,e={}){return __awaiter(this,void 0,void 0,(function*(){const n={body:"string"==typeof t?t:o.InputTransformer.toFormData(t),cache:"no-cache",method:"POST"},s=yield this.send(Object.assign(Object.assign({},n),e));return new r.AjaxResponse(s)}))}put(t,e={}){return __awaiter(this,void 0,void 0,(function*(){const n={body:"string"==typeof t?t:o.InputTransformer.toFormData(t),cache:"no-cache",method:"PUT"},s=yield this.send(Object.assign(Object.assign({},n),e));return new r.AjaxResponse(s)}))}delete(t={},e={}){return __awaiter(this,void 0,void 0,(function*(){const n={cache:"no-cache",method:"DELETE"};"object"==typeof t&&Object.keys(t).length>0?n.body=o.InputTransformer.toFormData(t):"string"==typeof t&&(n.body=t);const s=yield this.send(Object.assign(Object.assign({},n),e));return new r.AjaxResponse(s)}))}getAbort(){return this.abortController}clone(){return Object.assign(Object.create(this),this)}send(t={}){return __awaiter(this,void 0,void 0,(function*(){const e=yield fetch(this.composeRequestUrl(),this.getMergedOptions(t));if(!e.ok)throw new s.ResponseError(e);return e}))}composeRequestUrl(){let t=this.url;if("?"===t.charAt(0)&&(t=window.location.origin+window.location.pathname+t),t=new URL(t,window.location.origin).toString(),""!==this.queryArguments){t+=(this.url.includes("?")?"&":"?")+this.queryArguments}return t}getMergedOptions(t){return Object.assign(Object.assign(Object.assign({},i.defaultOptions),t),{signal:this.abortController.signal})}}return i.defaultOptions={credentials:"same-origin"},i}));
\ No newline at end of file
......@@ -10,4 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/
var __awaiter=this&&this.__awaiter||function(e,t,o,a){return new(o||(o=Promise))((function(n,r){function s(e){try{l(a.next(e))}catch(e){r(e)}}function i(e){try{l(a.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,i)}l((a=a.apply(e,t||[])).next())}))};define(["require","exports","TYPO3/CMS/Core/Ajax/AjaxRequest"],(function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),describe("TYPO3/CMS/Core/Ajax/AjaxRequest",()=>{let e;beforeEach(()=>{const t=new Promise((t,o)=>{e={resolve:t,reject:o}});spyOn(window,"fetch").and.returnValue(t)}),it("sends GET request",()=>{new o("https://example.com").get(),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"GET"}))}),it("sends POST request with object as payload",()=>{const e=new FormData;e.set("foo","bar"),e.set("bar","baz"),e.set("nested[works]","yes"),new o("https://example.com").post({foo:"bar",bar:"baz",nested:{works:"yes"}}),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"POST",body:e}))}),it("sends POST request with string as payload",()=>{const e=JSON.stringify({foo:"bar",bar:"baz",nested:{works:"yes"}});new o("https://example.com").post(e),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"POST",body:e}))}),it("sends PUT request with object as payload",()=>{const e=new FormData;e.set("foo","bar"),e.set("bar","baz"),e.set("nested[works]","yes"),new o("https://example.com").put({foo:"bar",bar:"baz",nested:{works:"yes"}}),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"PUT",body:e}))}),it("sends PUT request with string as payload",()=>{const e=JSON.stringify({foo:"bar",bar:"baz",nested:{works:"yes"}});new o("https://example.com").put(e),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"PUT",body:e}))}),it("sends DELETE request",()=>{new o("https://example.com").delete(),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"DELETE"}))}),it("sends DELETE request with string as payload",()=>{const e=JSON.stringify({foo:"bar",bar:"baz",nested:{works:"yes"}});new o("https://example.com").delete(e),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"DELETE",body:e}))}),describe("send GET requests",()=>{for(let t of function*(){yield["plaintext","foobar huselpusel",{},(e,t)=>{expect("string"==typeof e).toBeTruthy(),expect(e).toEqual(t)}],yield["JSON",JSON.stringify({foo:"bar",baz:"bencer"}),{"Content-Type":"application/json"},(e,t)=>{expect("object"==typeof e).toBeTruthy(),expect(JSON.stringify(e)).toEqual(t)}],yield["JSON with utf-8",JSON.stringify({foo:"bar",baz:"bencer"}),{"Content-Type":"application/json; charset=utf-8"},(e,t)=>{expect("object"==typeof e).toBeTruthy(),expect(JSON.stringify(e)).toEqual(t)}]}()){let[a,n,r,s]=t;it("receives a "+a+" response",t=>{const a=new Response(n,{headers:r});e.resolve(a),new o("https://example.com").get().then(e=>__awaiter(void 0,void 0,void 0,(function*(){const o=yield e.resolve();expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"GET"})),s(o,n),t()})))})}}),describe("send requests with different input urls",()=>{for(let e of function*(){yield["absolute url with domain","https://example.com",{},"https://example.com/"],yield["absolute url with domain, with query parameter","https://example.com",{foo:"bar",bar:{baz:"bencer"}},"https://example.com/?foo=bar&bar[baz]=bencer"],yield["absolute url without domain","/foo/bar",{},window.location.origin+"/foo/bar"],yield["absolute url without domain, with query parameter","/foo/bar",{foo:"bar",bar:{baz:"bencer"}},window.location.origin+"/foo/bar?foo=bar&bar[baz]=bencer"],yield["relative url without domain","foo/bar",{},window.location.origin+"/foo/bar"],yield["relative url without domain, with query parameter","foo/bar",{foo:"bar",bar:{baz:"bencer"}},window.location.origin+"/foo/bar?foo=bar&bar[baz]=bencer"]}()){let[t,a,n,r]=e;it("with "+t,()=>{new o(a).withQueryArguments(n).get(),expect(window.fetch).toHaveBeenCalledWith(r,jasmine.objectContaining({method:"GET"}))})}}),describe("send requests with query arguments",()=>{for(let e of function*(){yield["single level of arguments",{foo:"bar",bar:"baz"},"https://example.com/?foo=bar&bar=baz"],yield["nested arguments",{foo:"bar",bar:{baz:"bencer"}},"https://example.com/?foo=bar&bar[baz]=bencer"],yield["string argument","hello=world&foo=bar","https://example.com/?hello=world&foo=bar"],yield["array of arguments",["foo=bar","husel=pusel"],"https://example.com/?foo=bar&husel=pusel"],yield["object with array",{foo:["bar","baz"]},"https://example.com/?foo[0]=bar&foo[1]=baz"],yield["complex object",{foo:"bar",nested:{husel:"pusel",bar:"baz",array:["5","6"]},array:["1","2"]},"https://example.com/?foo=bar&nested[husel]=pusel&nested[bar]=baz&nested[array][0]=5&nested[array][1]=6&array[0]=1&array[1]=2"],yield["complex, deeply nested object",{foo:"bar",nested:{husel:"pusel",bar:"baz",array:["5","6"],deep_nested:{husel:"pusel",bar:"baz",array:["5","6"]}},array:["1","2"]},"https://example.com/?foo=bar&nested[husel]=pusel&nested[bar]=baz&nested[array][0]=5&nested[array][1]=6&nested[deep_nested][husel]=pusel&nested[deep_nested][bar]=baz&nested[deep_nested][array][0]=5&nested[deep_nested][array][1]=6&array[0]=1&array[1]=2"]}()){let[t,a,n]=e;it("with "+t,()=>{new o("https://example.com/").withQueryArguments(a).get(),expect(window.fetch).toHaveBeenCalledWith(n,jasmine.objectContaining({method:"GET"}))})}})})}));
\ No newline at end of file
var __awaiter=this&&this.__awaiter||function(e,t,o,a){return new(o||(o=Promise))((function(n,r){function s(e){try{l(a.next(e))}catch(e){r(e)}}function i(e){try{l(a.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,i)}l((a=a.apply(e,t||[])).next())}))};define(["require","exports","TYPO3/CMS/Core/Ajax/AjaxRequest"],(function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),describe("TYPO3/CMS/Core/Ajax/AjaxRequest",()=>{let e;beforeEach(()=>{const t=new Promise((t,o)=>{e={resolve:t,reject:o}});spyOn(window,"fetch").and.returnValue(t)}),it("sends GET request",()=>{new o("https://example.com").get(),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"GET"}))}),it("sends POST request with object as payload",()=>{const e=new FormData;e.set("foo","bar"),e.set("bar","baz"),e.set("nested[works]","yes"),new o("https://example.com").post({foo:"bar",bar:"baz",nested:{works:"yes"}}),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"POST",body:e}))}),it("sends POST request with string as payload",()=>{const e=JSON.stringify({foo:"bar",bar:"baz",nested:{works:"yes"}});new o("https://example.com").post(e),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"POST",body:e}))}),it("sends PUT request with object as payload",()=>{const e=new FormData;e.set("foo","bar"),e.set("bar","baz"),e.set("nested[works]","yes"),new o("https://example.com").put({foo:"bar",bar:"baz",nested:{works:"yes"}}),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"PUT",body:e}))}),it("sends PUT request with string as payload",()=>{const e=JSON.stringify({foo:"bar",bar:"baz",nested:{works:"yes"}});new o("https://example.com").put(e),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"PUT",body:e}))}),it("sends DELETE request",()=>{new o("https://example.com").delete(),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"DELETE"}))}),it("sends DELETE request with string as payload",()=>{const e=JSON.stringify({foo:"bar",bar:"baz",nested:{works:"yes"}});new o("https://example.com").delete(e),expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"DELETE",body:e}))}),describe("send GET requests",()=>{for(let t of function*(){yield["plaintext","foobar huselpusel",{},(e,t)=>{expect("string"==typeof e).toBeTruthy(),expect(e).toEqual(t)}],yield["JSON",JSON.stringify({foo:"bar",baz:"bencer"}),{"Content-Type":"application/json"},(e,t)=>{expect("object"==typeof e).toBeTruthy(),expect(JSON.stringify(e)).toEqual(t)}],yield["JSON with utf-8",JSON.stringify({foo:"bar",baz:"bencer"}),{"Content-Type":"application/json; charset=utf-8"},(e,t)=>{expect("object"==typeof e).toBeTruthy(),expect(JSON.stringify(e)).toEqual(t)}]}()){let[a,n,r,s]=t;it("receives a "+a+" response",t=>{const a=new Response(n,{headers:r});e.resolve(a),new o("https://example.com").get().then(e=>__awaiter(void 0,void 0,void 0,(function*(){const o=yield e.resolve();expect(window.fetch).toHaveBeenCalledWith("https://example.com/",jasmine.objectContaining({method:"GET"})),s(o,n),t()})))})}}),describe("send requests with different input urls",()=>{for(let e of function*(){yield["absolute url with domain","https://example.com",{},"https://example.com/"],yield["absolute url with domain, with query parameter","https://example.com",{foo:"bar",bar:{baz:"bencer"}},"https://example.com/?foo=bar&bar[baz]=bencer"],yield["absolute url without domain","/foo/bar",{},window.location.origin+"/foo/bar"],yield["absolute url without domain, with query parameter","/foo/bar",{foo:"bar",bar:{baz:"bencer"}},window.location.origin+"/foo/bar?foo=bar&bar[baz]=bencer"],yield["relative url without domain","foo/bar",{},window.location.origin+"/foo/bar"],yield["relative url without domain, with query parameter","foo/bar",{foo:"bar",bar:{baz:"bencer"}},window.location.origin+"/foo/bar?foo=bar&bar[baz]=bencer"],yield["fallback to current script if not defined","?foo=bar&baz=bencer",{},window.location.origin+window.location.pathname+"?foo=bar&baz=bencer"]}()){let[t,a,n,r]=e;it("with "+t,()=>{new o(a).withQueryArguments(n).get(),expect(window.fetch).toHaveBeenCalledWith(r,jasmine.objectContaining({method:"GET"}))})}}),describe("send requests with query arguments",()=>{for(let e of function*(){yield["single level of arguments",{foo:"bar",bar:"baz"},"https://example.com/?foo=bar&bar=baz"],yield["nested arguments",{foo:"bar",bar:{baz:"bencer"}},"https://example.com/?foo=bar&bar[baz]=bencer"],yield["string argument","hello=world&foo=bar","https://example.com/?hello=world&foo=bar"],yield["array of arguments",["foo=bar","husel=pusel"],"https://example.com/?foo=bar&husel=pusel"],yield["object with array",{foo:["bar","baz"]},"https://example.com/?foo[0]=bar&foo[1]=baz"],yield["complex object",{foo:"bar",nested:{husel:"pusel",bar:"baz",array:["5","6"]},array:["1","2"]},"https://example.com/?foo=bar&nested[husel]=pusel&nested[bar]=baz&nested[array][0]=5&nested[array][1]=6&array[0]=1&array[1]=2"],yield["complex, deeply nested object",{foo:"bar",nested:{husel:"pusel",bar:"baz",array:["5","6"],deep_nested:{husel:"pusel",bar:"baz",array:["5","6"]}},array:["1","2"]},"https://example.com/?foo=bar&nested[husel]=pusel&nested[bar]=baz&nested[array][0]=5&nested[array][1]=6&nested[deep_nested][husel]=pusel&nested[deep_nested][bar]=baz&nested[deep_nested][array][0]=5&nested[deep_nested][array][1]=6&array[0]=1&array[1]=2"]}()){let[t,a,n]=e;it("with "+t,()=>{new o("https://example.com/").withQueryArguments(a).get(),expect(window.fetch).toHaveBeenCalledWith(n,jasmine.objectContaining({method:"GET"}))})}})})}));
\ No newline at end of file
......@@ -10,4 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/
var __awaiter=this&&this.__awaiter||function(e,t,o,n){return new(o||(o=Promise))((function(i,a){function s(e){try{r(n.next(e))}catch(e){a(e)}}function l(e){try{r(n.throw(e))}catch(e){a(e)}}function r(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,l)}r((n=n.apply(e,t||[])).next())}))};define(["require","exports","jquery","TYPO3/CMS/Core/Ajax/AjaxRequest","TYPO3/CMS/Backend/Icons","TYPO3/CMS/Backend/Modal","./Renderable/InfoBox","./Renderable/ProgressBar","./Renderable/Severity"],(function(e,t,o,n,i,a,s,l,r){"use strict";return new class{constructor(){this.selectorBody=".t3js-body",this.selectorMainContent=".t3js-module-body"}initialize(){this.registerInstallToolRoutes(),o(document).on("click",".t3js-login-lockInstallTool",e=>{e.preventDefault(),this.logout()}),o(document).on("click",".t3js-login-login",e=>{e.preventDefault(),this.login()}),o(document).on("keydown","#t3-install-form-password",e=>{13===e.keyCode&&(e.preventDefault(),o(".t3js-login-login").click())}),o(document).on("click",".card .btn",t=>{t.preventDefault();const n=o(t.currentTarget),s=n.data("require"),l=n.data("inline");if(void 0!==l&&1===parseInt(l,10))e([s],e=>{e.initialize(n)});else{const t=n.closest(".card").find(".card-title").html(),l=n.data("modalSize")||a.sizes.large;i.getIcon("spinner-circle",i.sizes.default,null,null,i.markupIdentifiers.inline).then(n=>{const i={type:a.types.default,title:t,size:l,content:o('<div class="modal-loading">').append(n),additionalCssClasses:["install-tool-modal"],callback:t=>{e([s],e=>{e.initialize(t)})}};a.advanced(i)})}}),"backend"===o(this.selectorBody).data("context")?this.executeSilentConfigurationUpdate():this.preAccessCheck()}registerInstallToolRoutes(){void 0===TYPO3.settings&&(TYPO3.settings={ajaxUrls:{icons:"?install[controller]=icon&install[action]=getIcon",icons_cache:"?install[controller]=icon&install[action]=getCacheIdentifier"}})}getUrl(e,t){const n=o(this.selectorBody).data("context");let i=location.href;return i=i.replace(location.search,""),void 0===t&&(t=o(this.selectorBody).data("controller")),i=i+"?install[controller]="+t,void 0!==n&&""!==n&&(i=i+"&install[context]="+n),void 0!==e&&(i=i+"&install[action]="+e),i}executeSilentConfigurationUpdate(){this.updateLoadingInfo("Checking session and executing silent configuration update"),new n(this.getUrl("executeSilentConfigurationUpdate","layout")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){!0===(yield e.resolve()).success?this.executeSilentExtensionConfigurationSynchronization():this.executeSilentConfigurationUpdate()})),e=>{this.handleAjaxError(e)})}executeSilentExtensionConfigurationSynchronization(){const e=o(this.selectorBody);this.updateLoadingInfo("Executing silent extension configuration synchronization"),new n(this.getUrl("executeSilentExtensionConfigurationSynchronization","layout")).get({cache:"no-cache"}).then(t=>__awaiter(this,void 0,void 0,(function*(){if(!0===(yield t.resolve()).success)this.loadMainLayout();else{const t=s.render(r.error,"Something went wrong","");e.empty().append(t)}})),e=>{this.handleAjaxError(e)})}loadMainLayout(){const e=o(this.selectorBody);this.updateLoadingInfo("Loading main layout"),new n(this.getUrl("mainLayout","layout")).get({cache:"no-cache"}).then(t=>__awaiter(this,void 0,void 0,(function*(){const n=yield t.resolve();if(!0===n.success&&"undefined"!==n.html&&n.html.length>0){if(e.empty().append(n.html),"backend"!==o(this.selectorBody).data("context")){const t=e.data("controller");e.find('.t3js-mainmodule[data-controller="'+t+'"]').addClass("active")}this.loadCards()}else{const t=s.render(r.error,"Something went wrong","");e.empty().append(t)}})),e=>{this.handleAjaxError(e)})}handleAjaxError(e,t){return __awaiter(this,void 0,void 0,(function*(){let n;if(403===e.response.status){"backend"===o(this.selectorBody).data("context")?(n=s.render(r.error,"The install tool session expired. Please reload the backend and try again."),o(this.selectorBody).empty().append(n)):this.checkEnableInstallToolFile()}else{const i=this.getUrl(void 0,"upgrade");n=o('<div class="t3js-infobox callout callout-sm callout-danger"><div class="callout-body"><p>Something went wrong. Please use <b><a href="'+i+'">Check for broken extensions</a></b> to see if a loaded extension breaks this part of the install tool and unload it.</p><p>The box below may additionally reveal further details on what went wrong depending on your debug settings. It may help to temporarily switch to debug mode using <b>Settings > Configuration Presets > Debug settings.</b></p><p>If this error happens at an early state and no full exception back trace is shown, it may also help to manually increase debugging output in <code>typo3conf/LocalConfiguration.php</code>:<code>[\'BE\'][\'debug\'] => true</code>, <code>[\'SYS\'][\'devIPmask\'] => \'*\'</code>, <code>[\'SYS\'][\'displayErrors\'] => 1</code>,<code>[\'SYS\'][\'systemLogLevel\'] => 0</code>, <code>[\'SYS\'][\'exceptionalErrors\'] => 12290</code></p></div></div><div class="panel-group" role="tablist" aria-multiselectable="true"><div class="panel panel-default panel-flat searchhit"><div class="panel-heading" role="tab" id="heading-error"><h3 class="panel-title"><a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-error" aria-expanded="true" aria-controls="collapse-error" class="collapsed"><span class="caret"></span><strong>Ajax error</strong></a></h3></div><div id="collapse-error" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-error"><div class="panel-body">'+(yield e.response.text())+"</div></div></div></div>"),void 0!==t?o(t).empty().html(n):o(this.selectorBody).empty().html(n)}}))}checkEnableInstallToolFile(){new n(this.getUrl("checkEnableInstallToolFile")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){!0===(yield e.resolve()).success?this.checkLogin():this.showEnableInstallTool()})),e=>{this.handleAjaxError(e)})}showEnableInstallTool(){new n(this.getUrl("showEnableInstallToolFile")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){const t=yield e.resolve();!0===t.success&&o(this.selectorBody).empty().append(t.html)})),e=>{this.handleAjaxError(e)})}checkLogin(){new n(this.getUrl("checkLogin")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){!0===(yield e.resolve()).success?this.loadMainLayout():this.showLogin()})),e=>{this.handleAjaxError(e)})}showLogin(){new n(this.getUrl("showLogin")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){const t=yield e.resolve();!0===t.success&&o(this.selectorBody).empty().append(t.html)})),e=>{this.handleAjaxError(e)})}login(){const e=o(".t3js-login-output"),t=l.render(r.loading,"Loading...","");e.empty().html(t),new n(this.getUrl()).post({install:{action:"login",token:o("[data-login-token]").data("login-token"),password:o(".t3-install-form-input-text").val()}}).then(t=>__awaiter(this,void 0,void 0,(function*(){const o=yield t.resolve();!0===o.success?this.executeSilentConfigurationUpdate():o.status.forEach(t=>{const o=s.render(t.severity,t.title,t.message);e.empty().html(o)})})),e=>{this.handleAjaxError(e)})}logout(){new n(this.getUrl("logout")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){!0===(yield e.resolve()).success&&this.showEnableInstallTool()})),e=>{this.handleAjaxError(e)})}loadCards(){const e=o(this.selectorMainContent);new n(this.getUrl("cards")).get({cache:"no-cache"}).then(t=>__awaiter(this,void 0,void 0,(function*(){const o=yield t.resolve();if(!0===o.success&&"undefined"!==o.html&&o.html.length>0)e.empty().append(o.html);else{const t=s.render(r.error,"Something went wrong","");e.empty().append(t)}})),e=>{this.handleAjaxError(e)})}updateLoadingInfo(e){o(this.selectorBody).find("#t3js-ui-block-detail").text(e)}preAccessCheck(){this.updateLoadingInfo("Execute pre access check"),new n(this.getUrl("preAccessCheck","layout")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){const t=yield e.resolve();t.installToolLocked?this.checkEnableInstallToolFile():t.isAuthorized?this.executeSilentConfigurationUpdate():this.showLogin()})),e=>{this.handleAjaxError(e)})}}}));
\ No newline at end of file
var __awaiter=this&&this.__awaiter||function(e,t,o,n){return new(o||(o=Promise))((function(i,a){function s(e){try{r(n.next(e))}catch(e){a(e)}}function l(e){try{r(n.throw(e))}catch(e){a(e)}}function r(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,l)}r((n=n.apply(e,t||[])).next())}))};define(["require","exports","jquery","TYPO3/CMS/Core/Ajax/AjaxRequest","TYPO3/CMS/Backend/Icons","TYPO3/CMS/Backend/Modal","./Renderable/InfoBox","./Renderable/ProgressBar","./Renderable/Severity"],(function(e,t,o,n,i,a,s,l,r){"use strict";return new class{constructor(){this.selectorBody=".t3js-body",this.selectorMainContent=".t3js-module-body"}initialize(){this.registerInstallToolRoutes(),o(document).on("click",".t3js-login-lockInstallTool",e=>{e.preventDefault(),this.logout()}),o(document).on("click",".t3js-login-login",e=>{e.preventDefault(),this.login()}),o(document).on("keydown","#t3-install-form-password",e=>{13===e.keyCode&&(e.preventDefault(),o(".t3js-login-login").click())}),o(document).on("click",".card .btn",t=>{t.preventDefault();const n=o(t.currentTarget),s=n.data("require"),l=n.data("inline");if(void 0!==l&&1===parseInt(l,10))e([s],e=>{e.initialize(n)});else{const t=n.closest(".card").find(".card-title").html(),l=n.data("modalSize")||a.sizes.large;i.getIcon("spinner-circle",i.sizes.default,null,null,i.markupIdentifiers.inline).then(n=>{const i={type:a.types.default,title:t,size:l,content:o('<div class="modal-loading">').append(n),additionalCssClasses:["install-tool-modal"],callback:t=>{e([s],e=>{e.initialize(t)})}};a.advanced(i)})}}),"backend"===o(this.selectorBody).data("context")?this.executeSilentConfigurationUpdate():this.preAccessCheck()}registerInstallToolRoutes(){void 0===TYPO3.settings&&(TYPO3.settings={ajaxUrls:{icons:window.location.origin+window.location.pathname+"?install[controller]=icon&install[action]=getIcon",icons_cache:window.location.origin+window.location.pathname+"?install[controller]=icon&install[action]=getCacheIdentifier"}})}getUrl(e,t){const n=o(this.selectorBody).data("context");let i=location.href;return i=i.replace(location.search,""),void 0===t&&(t=o(this.selectorBody).data("controller")),i=i+"?install[controller]="+t,void 0!==n&&""!==n&&(i=i+"&install[context]="+n),void 0!==e&&(i=i+"&install[action]="+e),i}executeSilentConfigurationUpdate(){this.updateLoadingInfo("Checking session and executing silent configuration update"),new n(this.getUrl("executeSilentConfigurationUpdate","layout")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){!0===(yield e.resolve()).success?this.executeSilentExtensionConfigurationSynchronization():this.executeSilentConfigurationUpdate()})),e=>{this.handleAjaxError(e)})}executeSilentExtensionConfigurationSynchronization(){const e=o(this.selectorBody);this.updateLoadingInfo("Executing silent extension configuration synchronization"),new n(this.getUrl("executeSilentExtensionConfigurationSynchronization","layout")).get({cache:"no-cache"}).then(t=>__awaiter(this,void 0,void 0,(function*(){if(!0===(yield t.resolve()).success)this.loadMainLayout();else{const t=s.render(r.error,"Something went wrong","");e.empty().append(t)}})),e=>{this.handleAjaxError(e)})}loadMainLayout(){const e=o(this.selectorBody);this.updateLoadingInfo("Loading main layout"),new n(this.getUrl("mainLayout","layout")).get({cache:"no-cache"}).then(t=>__awaiter(this,void 0,void 0,(function*(){const n=yield t.resolve();if(!0===n.success&&"undefined"!==n.html&&n.html.length>0){if(e.empty().append(n.html),"backend"!==o(this.selectorBody).data("context")){const t=e.data("controller");e.find('.t3js-mainmodule[data-controller="'+t+'"]').addClass("active")}this.loadCards()}else{const t=s.render(r.error,"Something went wrong","");e.empty().append(t)}})),e=>{this.handleAjaxError(e)})}handleAjaxError(e,t){return __awaiter(this,void 0,void 0,(function*(){let n;if(403===e.response.status){"backend"===o(this.selectorBody).data("context")?(n=s.render(r.error,"The install tool session expired. Please reload the backend and try again."),o(this.selectorBody).empty().append(n)):this.checkEnableInstallToolFile()}else{const i=this.getUrl(void 0,"upgrade");n=o('<div class="t3js-infobox callout callout-sm callout-danger"><div class="callout-body"><p>Something went wrong. Please use <b><a href="'+i+'">Check for broken extensions</a></b> to see if a loaded extension breaks this part of the install tool and unload it.</p><p>The box below may additionally reveal further details on what went wrong depending on your debug settings. It may help to temporarily switch to debug mode using <b>Settings > Configuration Presets > Debug settings.</b></p><p>If this error happens at an early state and no full exception back trace is shown, it may also help to manually increase debugging output in <code>typo3conf/LocalConfiguration.php</code>:<code>[\'BE\'][\'debug\'] => true</code>, <code>[\'SYS\'][\'devIPmask\'] => \'*\'</code>, <code>[\'SYS\'][\'displayErrors\'] => 1</code>,<code>[\'SYS\'][\'systemLogLevel\'] => 0</code>, <code>[\'SYS\'][\'exceptionalErrors\'] => 12290</code></p></div></div><div class="panel-group" role="tablist" aria-multiselectable="true"><div class="panel panel-default panel-flat searchhit"><div class="panel-heading" role="tab" id="heading-error"><h3 class="panel-title"><a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-error" aria-expanded="true" aria-controls="collapse-error" class="collapsed"><span class="caret"></span><strong>Ajax error</strong></a></h3></div><div id="collapse-error" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-error"><div class="panel-body">'+(yield e.response.text())+"</div></div></div></div>"),void 0!==t?o(t).empty().html(n):o(this.selectorBody).empty().html(n)}}))}checkEnableInstallToolFile(){new n(this.getUrl("checkEnableInstallToolFile")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){!0===(yield e.resolve()).success?this.checkLogin():this.showEnableInstallTool()})),e=>{this.handleAjaxError(e)})}showEnableInstallTool(){new n(this.getUrl("showEnableInstallToolFile")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){const t=yield e.resolve();!0===t.success&&o(this.selectorBody).empty().append(t.html)})),e=>{this.handleAjaxError(e)})}checkLogin(){new n(this.getUrl("checkLogin")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){!0===(yield e.resolve()).success?this.loadMainLayout():this.showLogin()})),e=>{this.handleAjaxError(e)})}showLogin(){new n(this.getUrl("showLogin")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){const t=yield e.resolve();!0===t.success&&o(this.selectorBody).empty().append(t.html)})),e=>{this.handleAjaxError(e)})}login(){const e=o(".t3js-login-output"),t=l.render(r.loading,"Loading...","");e.empty().html(t),new n(this.getUrl()).post({install:{action:"login",token:o("[data-login-token]").data("login-token"),password:o(".t3-install-form-input-text").val()}}).then(t=>__awaiter(this,void 0,void 0,(function*(){const o=yield t.resolve();!0===o.success?this.executeSilentConfigurationUpdate():o.status.forEach(t=>{const o=s.render(t.severity,t.title,t.message);e.empty().html(o)})})),e=>{this.handleAjaxError(e)})}logout(){new n(this.getUrl("logout")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){!0===(yield e.resolve()).success&&this.showEnableInstallTool()})),e=>{this.handleAjaxError(e)})}loadCards(){const e=o(this.selectorMainContent);new n(this.getUrl("cards")).get({cache:"no-cache"}).then(t=>__awaiter(this,void 0,void 0,(function*(){const o=yield t.resolve();if(!0===o.success&&"undefined"!==o.html&&o.html.length>0)e.empty().append(o.html);else{const t=s.render(r.error,"Something went wrong","");e.empty().append(t)}})),e=>{this.handleAjaxError(e)})}updateLoadingInfo(e){o(this.selectorBody).find("#t3js-ui-block-detail").text(e)}preAccessCheck(){this.updateLoadingInfo("Execute pre access check"),new n(this.getUrl("preAccessCheck","layout")).get({cache:"no-cache"}).then(e=>__awaiter(this,void 0,void 0,(function*(){const t=yield e.resolve();t.installToolLocked?this.checkEnableInstallToolFile():t.isAuthorized?this.executeSilentConfigurationUpdate():this.showLogin()})),e=>{this.handleAjaxError(e)})}}}));
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment