From b4fee849b0182c632424a808b265fbe9da1be47f Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 7 Nov 2024 12:44:09 -0300 Subject: [PATCH 01/59] feat: add style for secondary button --- plugin/css/tbk.css | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugin/css/tbk.css b/plugin/css/tbk.css index e15ed8c..1b7673f 100644 --- a/plugin/css/tbk.css +++ b/plugin/css/tbk.css @@ -330,6 +330,21 @@ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } +.button.tbk-button-secondary { + background: white; + border-color: #D5006C; + color: #D5006C; + transition: background-color 0.3s ease; +} + +.button.tbk-button-secondary:hover, +.button.tbk-button-secondary:focus { + background: white; + border-color: #D5006C; + color: #D5006C; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); +} + .log-container { width: calc(100vw - 480px); max-height: 600px; From 36dc248454fd2d519f82814e5ff454847f2f2226 Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 7 Nov 2024 12:46:47 -0300 Subject: [PATCH 02/59] feat: add id for logs elements --- plugin/templates/admin/log.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index d2fbfb9..8dbcf09 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -7,7 +7,7 @@ $lineCountTitle = "Cantidad de líneas que posee el último archivo de registro creado"; ?> -
+

Información de Registros

@@ -35,7 +35,7 @@ - > Date: Thu, 7 Nov 2024 12:47:54 -0300 Subject: [PATCH 03/59] feat: add download button --- plugin/templates/admin/log.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 8dbcf09..61a2634 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -58,6 +58,7 @@ value="Ver"> +
From 2c469993323017ef98914b06a596a8fd81cdee95 Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 7 Nov 2024 12:51:01 -0300 Subject: [PATCH 04/59] feat: add function to check download permission --- plugin/webpay-rest.php | 47 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/plugin/webpay-rest.php b/plugin/webpay-rest.php index dc4aa9e..ece643e 100644 --- a/plugin/webpay-rest.php +++ b/plugin/webpay-rest.php @@ -41,8 +41,7 @@ add_action('wp_loaded', 'woocommerceTransbankInit'); add_action('admin_init', 'on_transbank_rest_webpay_plugins_loaded'); -add_action('wp_ajax_check_connection', ConnectionCheck::class.'::check'); -add_action('wp_ajax_check_exist_tables', TableCheck::class.'::check'); +add_action('wp_ajax_checkCanDownloadLogFile', 'checkCanDownloadLogFile'); add_action('wp_ajax_get_transaction_status', [new TransactionStatusController(), 'getStatus']); add_action('woocommerce_before_cart', 'transbank_rest_before_cart'); @@ -274,3 +273,47 @@ function () { } ); } + +function fileExistsInFolder($fileName, $folderPath) +{ + $filesInFolder = array_filter(scandir($folderPath), function ($file) use ($folderPath) { + return is_file($folderPath . '/' . $file); + }); + + return in_array($fileName, array_values($filesInFolder)); +} + +function checkCanDownloadLogFile() +{ + $response = [ + 'canDownload' => false, + 'downloadUrl' => '', + 'error' => '' + ]; + + if (!is_user_logged_in()) { + $response['error'] = 'Debes iniciar sesión para poder descargar'; + wp_send_json_error($response); + } + + if (!current_user_can('manage_options')) { + $response['error'] = 'No tienes permisos para descargar'; + wp_send_json_error($response); + } + + $baseUploadDir = wp_upload_dir(); + $tbkLogsFolder = '/transbank_webpay_plus_rest/logs/'; + $logName = sanitize_text_field($_POST['file']); + $folderPath = $baseUploadDir['basedir'] . $tbkLogsFolder; + $fileExists = fileExistsInFolder($logName, $folderPath); + + if (!$fileExists) { + $response['error'] = 'No existe el archivo solicitado'; + wp_send_json_error($response); + } + + $response['canDownload'] = true; + $response['downloadUrl'] = $baseUploadDir['baseurl'] . $tbkLogsFolder . $logName; + + wp_send_json_success($response); +} From eccabfcdcb261afec3b5a462aa50ce5ee2050a6a Mon Sep 17 00:00:00 2001 From: Matias Vasquez Date: Thu, 7 Nov 2024 12:52:36 -0300 Subject: [PATCH 05/59] feat: handle download response --- plugin/js/admin.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/plugin/js/admin.js b/plugin/js/admin.js index 14cad5e..ff89a6d 100644 --- a/plugin/js/admin.js +++ b/plugin/js/admin.js @@ -113,4 +113,67 @@ jQuery(function($) { notice_id: noticeId }); }); + + function checkPermission(fileToDownload) { + return $.ajax({ + url: ajaxurl, + type: 'POST', + data: { + action: 'checkCanDownloadLogFile', + file: fileToDownload + } + }).then(function (response) { + console.log(response); + return response.data; + }).catch(function () { + return false; + }); + } + + function showNotice(title, message, type = 'success') { + const notice = $('
') + .addClass(`is-dismissible notice notice-${type}`) + .prepend(`

${title}
${message}

`); + + const dismissButton = $('