Skip to content

Commit

Permalink
Merge pull request PrestaShop#828 from M0rgan01/Js-format
Browse files Browse the repository at this point in the history
Standardization of the JS format
  • Loading branch information
M0rgan01 authored Aug 8, 2024
2 parents ba83b5f + bc07a32 commit 961e3c8
Show file tree
Hide file tree
Showing 3 changed files with 381 additions and 273 deletions.
9 changes: 3 additions & 6 deletions js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
$(document).ready(function(){
$(document).ready(function () {
var autoUpgradePanel = $("#autoupgradePhpWarn");

$(".list-toolbar-btn", autoUpgradePanel).click(function(event) {

$(".list-toolbar-btn", autoUpgradePanel).click(function (event) {
event.preventDefault();
autoUpgradePanel.fadeOut();

$.post(
$(this).attr("href")
);
$.post($(this).attr("href"));
});
});
93 changes: 49 additions & 44 deletions js/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,67 +24,72 @@
*/

Sentry.init({
dsn: "https://[email protected]/4507254110552064",
release: 'v' + input.autoupgrade.version,
beforeSend(event, hint) {
// Only the one we handle via the feedback modal must be sent.
if (!event.tags?.source || event.tags.source !== 'feedbackModal') {
return null;
}
event.request.url = maskSensitiveInfoInUrl(event.request.url, input.adminUrl);
dsn: "https://[email protected]/4507254110552064",
release: "v" + input.autoupgrade.version,
beforeSend(event, hint) {
// Only the one we handle via the feedback modal must be sent.
if (!event.tags?.source || event.tags.source !== "feedbackModal") {
return null;
}
event.request.url = maskSensitiveInfoInUrl(
event.request.url,
input.adminUrl,
);

hint.attachments = [
{ filename: "log.txt", data: readLogPanel('quickInfo') },
{ filename: "error.txt", data: readLogPanel('infoError') },
];
hint.attachments = [
{ filename: "log.txt", data: readLogPanel("quickInfo") },
{ filename: "error.txt", data: readLogPanel("infoError") },
];

return event;
},
return event;
},
});

document.getElementById("submitErrorReport").addEventListener("click", function () {
document
.getElementById("submitErrorReport")
.addEventListener("click", function () {
const errorsElements = document.getElementById("infoError");
if (errorsElements) {
const childNodes = errorsElements.childNodes;
let messages = '';
childNodes.forEach((node) => {
if (node.nodeType === Node.TEXT_NODE) {
messages += node.textContent.trim() + '\n';
}
});
const childNodes = errorsElements.childNodes;
let messages = "";
childNodes.forEach((node) => {
if (node.nodeType === Node.TEXT_NODE) {
messages += node.textContent.trim() + "\n";
}
});

const url = maskSensitiveInfoInUrl(window.location.href, input.adminUrl);
const url = maskSensitiveInfoInUrl(window.location.href, input.adminUrl);

Sentry.setTag("url", url);
Sentry.setTag('source', 'feedbackModal');
Sentry.setTag("url", url);
Sentry.setTag("source", "feedbackModal");

const eventId = Sentry.captureMessage(messages, "error");
const userEmail = document.getElementById("userEmail");
const errorDescription = document.getElementById("errorDescription");
const eventId = Sentry.captureMessage(messages, "error");
const userEmail = document.getElementById("userEmail");
const errorDescription = document.getElementById("errorDescription");

Sentry.captureUserFeedback({
event_id: eventId,
email: userEmail.value,
comments: errorDescription.value,
});
Sentry.captureUserFeedback({
event_id: eventId,
email: userEmail.value,
comments: errorDescription.value,
});

// Clean-up
userEmail.value = "";
errorDescription.value = "";
Sentry.setTag('source', '');
// Clean-up
userEmail.value = "";
errorDescription.value = "";
Sentry.setTag("source", "");

$('#errorModal').modal('hide')
$("#errorModal").modal("hide");
}
});
});

function maskSensitiveInfoInUrl(url, adminFolder) {
let regex = new RegExp(adminFolder, "g");
url = url.replace(regex, '/********');
let regex = new RegExp(adminFolder, "g");
url = url.replace(regex, "/********");

regex = new RegExp( "token=[^&]*", "i");
return url.replace(regex, 'token=********');
regex = new RegExp("token=[^&]*", "i");
return url.replace(regex, "token=********");
}

function readLogPanel(targetPanel) {
return document.getElementById(targetPanel).innerText;
return document.getElementById(targetPanel).innerText;
}
Loading

0 comments on commit 961e3c8

Please sign in to comment.