From cf0eea55ec9f50a0471b2cbd20a87807bab9bb00 Mon Sep 17 00:00:00 2001 From: Alexander Blanchard Date: Thu, 2 Jan 2025 11:57:56 +0000 Subject: [PATCH 01/11] feat: Add message for template and page save Add a message when saving a grapes template and grapes page. Improve messages when errors occur. --- .../WebBuilder/createTemplatejs.tpl | 11 +- .../themes/responsive/WebBuilder/grapesjs.tpl | 11 +- code/web/services/WebBuilder/AJAX.php | 116 ++++++++++++------ 3 files changed, 100 insertions(+), 38 deletions(-) diff --git a/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl b/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl index c446a9824a..2338ec95b7 100644 --- a/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl +++ b/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl @@ -108,10 +108,19 @@ }), contentType: "application/json", success: function (response) { - console.log('Saved as Template'); + if (response.success) { + AspenDiscovery.showMessage('Success', response.message); + } else { + AspenDiscovery.showMessage('Error', response.message || 'Failed to save template.'); + } }, error: function (xhr, status, error) { console.error('Error saving template: ', error); + let errorMessage = 'Failed to save template. Please try again.'; + if (xhr.responseJSON && xhr.responseJSON.message) { + errorMessage = xhr.responseJSON.message; + } + AspenDiscovery.showMessage('Error', errorMessage); } }); } diff --git a/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl b/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl index c12643102f..ef68102b0a 100644 --- a/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl +++ b/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl @@ -106,10 +106,19 @@ }), contentType: "application/json", success: function (response) { - console.log('Saved as Grapes Page'); + if (response.success) { + AspenDiscovery.showMessage('Success', response.message); + } else { + AspenDiscovery.showMessage('Error', response.message || 'Failed to save page.'); + } }, error: function (xhr, status, error) { console.error('Error saving page: ', error); + let errorMessage = 'Failed to save page. Please try again.'; + if (xhr.responseJSON && xhr.responseJSON.message){ + errorMessage = xhr.responseJSON.message; + } + AspenDiscovery.showMessage('Error', errorMessage); } }); } diff --git a/code/web/services/WebBuilder/AJAX.php b/code/web/services/WebBuilder/AJAX.php index 271ed928ad..36a18bad52 100644 --- a/code/web/services/WebBuilder/AJAX.php +++ b/code/web/services/WebBuilder/AJAX.php @@ -972,43 +972,87 @@ function trackWebResourceUsage() { } function saveAsTemplate(){ require_once ROOT_DIR . '/sys/WebBuilder/GrapesTemplate.php'; - $newGrapesPageContent = json_decode(file_get_contents("php://input"), true); - $templateId = $newGrapesPageContent['templateId']; - $html = $newGrapesPageContent['html']; - $css = $newGrapesPageContent['css']; - $projectData = json_encode($newGrapesPageContent['projectData']); - - $template = new GrapesTemplate(); - $template->id = $templateId; - - if ($template->find(true)) { - $template->templateContent = $projectData; - $template->htmlData = $html; - $template->cssData = $css; - } - $template->update(); - } - - function saveAsPage() { - require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php'; - $newGrapesPageContent = json_decode(file_get_contents("php://input"), true); - $grapesPageId = $newGrapesPageContent['grapesPageId']; - $grapesGenId = $newGrapesPageContent['grapesGenId']; - $templateId = $newGrapesPageContent['templateId']; - $html = $newGrapesPageContent['html']; - $css = $newGrapesPageContent['css']; - $grapesPage = new GrapesPage(); - $grapesPage->id = $grapesPageId; - $projectData = json_encode($newGrapesPageContent['projectData']); + + try { + $newGrapesPageContent = json_decode(file_get_contents("php://input"), true); + $templateId = $newGrapesPageContent['templateId']; + $html = $newGrapesPageContent['html']; + $css = $newGrapesPageContent['css']; + $projectData = json_encode($newGrapesPageContent['projectData']); + + $template = new GrapesTemplate(); + $template->id = $templateId; + + if (!$template->find(true)) { + return [ + 'success' => false, + 'message' => "Template with ID $templateId not found. Unable to update." + ]; + } + $template->templateContent = $projectData; + $template->htmlData = $html; + $template->cssData = $css; + + if(!$template->update()) { + return [ + 'success' => false, + 'message' => 'Failed to update the template.' + ]; + } + return [ + 'success' => true, + 'message' => 'Template saved successfully.' + ]; + } catch (Exception $e) { + return [ + 'success' => false, + 'message' => 'an unexpected error occurred: ' . $e->getMessage() + ]; + } + } - if ($grapesPage->find(true)) { - $grapesPage->grapesGenId = $grapesGenId; - $grapesPage->templateContent = $projectData; - $grapesPage->htmlData = $html; - $grapesPage->cssData = $css; - } - $grapesPage->update(); - } + function saveAsPage() { + require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php'; + + try { + $newGrapesPageContent = json_decode(file_get_contents("php://input"), true); + $grapesPageId = $newGrapesPageContent['grapesPageId']; + $grapesGenId = $newGrapesPageContent['grapesGenId']; + $templateId = $newGrapesPageContent['templateId']; + $html = $newGrapesPageContent['html']; + $css = $newGrapesPageContent['css']; + $grapesPage = new GrapesPage(); + $grapesPage->id = $grapesPageId; + $projectData = json_encode($newGrapesPageContent['projectData']); + + if (!$grapesPage->find(true)) { + return [ + 'success' =>false, + 'message' => "Page with ID $grapesPageId not found. Unable to update." + ]; + } + $grapesPage->grapesGenId = $grapesGenId; + $grapesPage->templateContent = $projectData; + $grapesPage->htmlData = $html; + $grapesPage->cssData = $css; + + if (!$grapesPage->update()) { + return [ + 'success ' => false, + 'message' => 'Failed to update the page.' + ]; + } + return [ + 'success' => true, + 'message' => 'Page saved successfully.' + ]; + } catch (Exception $e) { + return [ + 'success' => false, + 'message' => 'An unexpected error occurred: ' . $e->getMessage() + ]; + } + } function loadGrapesPage() { require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php'; From e510c0f2695a65733eee9030a15f34b3b7f64811 Mon Sep 17 00:00:00 2001 From: Alexander Blanchard Date: Fri, 3 Jan 2025 12:01:10 +0000 Subject: [PATCH 02/11] chore: Update Change Log --- code/web/release_notes/25.01.00.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/code/web/release_notes/25.01.00.MD b/code/web/release_notes/25.01.00.MD index 689a5c7649..18b5e961fd 100644 --- a/code/web/release_notes/25.01.00.MD +++ b/code/web/release_notes/25.01.00.MD @@ -138,6 +138,7 @@ ### Web Builder Updates - When adding a form to a custom page, limit the forms displayed in the dropdown to those from the user's own library if their permissions are Administer Library Custom Forms. (*AB*) +- Add a message when saving a Grapes JS Template or Page to confirm it has been updated successfully. (*AB*) ### Other Updates - Fix linking to library websites for consortia within Web Builder and the Hours and Location dialog. (*MDN*) From c88a6cdb6ff455b28eb2ebab601d168b3729207e Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 14 Jan 2025 17:01:17 +0000 Subject: [PATCH 03/11] chore: Update Release Notes --- code/web/release_notes/25.01.00.MD | 1 - code/web/release_notes/25.02.00.MD | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/code/web/release_notes/25.01.00.MD b/code/web/release_notes/25.01.00.MD index 18b5e961fd..689a5c7649 100644 --- a/code/web/release_notes/25.01.00.MD +++ b/code/web/release_notes/25.01.00.MD @@ -138,7 +138,6 @@ ### Web Builder Updates - When adding a form to a custom page, limit the forms displayed in the dropdown to those from the user's own library if their permissions are Administer Library Custom Forms. (*AB*) -- Add a message when saving a Grapes JS Template or Page to confirm it has been updated successfully. (*AB*) ### Other Updates - Fix linking to library websites for consortia within Web Builder and the Hours and Location dialog. (*MDN*) diff --git a/code/web/release_notes/25.02.00.MD b/code/web/release_notes/25.02.00.MD index 96ae64d902..4020a5ba74 100644 --- a/code/web/release_notes/25.02.00.MD +++ b/code/web/release_notes/25.02.00.MD @@ -57,6 +57,8 @@ //james //alexander +### Web Builder Updates +- Add a message when saving a Grapes JS Template or Page to confirm it has been updated successfully. (*AB*) //chloe From b800113b33bd8f6d29cfb834d0554772edc20b7a Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 15 Jan 2025 21:28:11 +0000 Subject: [PATCH 04/11] refactor: Update success and error save messages Update success and error messages displayed on save to be translatable --- .../WebBuilder/createTemplatejs.tpl | 11 ++- .../themes/responsive/WebBuilder/grapesjs.tpl | 8 +- code/web/services/WebBuilder/AJAX.php | 74 ++++++++++++++++--- 3 files changed, 79 insertions(+), 14 deletions(-) diff --git a/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl b/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl index 2338ec95b7..02bf4d8543 100644 --- a/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl +++ b/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl @@ -108,15 +108,20 @@ }), contentType: "application/json", success: function (response) { + var title = response.title; + var message; + if (response.success) { - AspenDiscovery.showMessage('Success', response.message); + message = response.message || 'Template updated successfully.'; + AspenDiscovery.showMessage(title, message); } else { - AspenDiscovery.showMessage('Error', response.message || 'Failed to save template.'); + message = response.message || 'Failed to save template.' + AspenDiscovery.showMessage(title, message); } }, error: function (xhr, status, error) { console.error('Error saving template: ', error); - let errorMessage = 'Failed to save template. Please try again.'; + var errorMessage = 'Failed to save template. Please try again.'; if (xhr.responseJSON && xhr.responseJSON.message) { errorMessage = xhr.responseJSON.message; } diff --git a/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl b/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl index ef68102b0a..a2dac22a3c 100644 --- a/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl +++ b/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl @@ -106,10 +106,14 @@ }), contentType: "application/json", success: function (response) { + var title = response.title; + var message; if (response.success) { - AspenDiscovery.showMessage('Success', response.message); + message = response.message || 'Page Saved.'; + AspenDiscovery.showMessage(title, message); } else { - AspenDiscovery.showMessage('Error', response.message || 'Failed to save page.'); + message = response.message || 'Failed to save page.'; + AspenDiscovery.showMessage(title, message); } }, error: function (xhr, status, error) { diff --git a/code/web/services/WebBuilder/AJAX.php b/code/web/services/WebBuilder/AJAX.php index 36a18bad52..cea783dac4 100644 --- a/code/web/services/WebBuilder/AJAX.php +++ b/code/web/services/WebBuilder/AJAX.php @@ -986,7 +986,14 @@ function saveAsTemplate(){ if (!$template->find(true)) { return [ 'success' => false, - 'message' => "Template with ID $templateId not found. Unable to update." + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => "Template with ID $templateId not found. Unable to update.", + 'isPublicFacing' => true + ]) ]; } $template->templateContent = $projectData; @@ -996,17 +1003,38 @@ function saveAsTemplate(){ if(!$template->update()) { return [ 'success' => false, - 'message' => 'Failed to update the template.' + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'Failed to update the template.', + 'isPublicFacing' => true + ]) ]; } return [ 'success' => true, - 'message' => 'Template saved successfully.' + 'title' => translate([ + 'text' => 'Success', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'Template saved successfully.', + 'isPublicFacing' => true + ]) ]; } catch (Exception $e) { return [ 'success' => false, - 'message' => 'an unexpected error occurred: ' . $e->getMessage() + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'An unexpected error occurred: ' . $e->getMessage(), + 'isPublicFacing' => true + ]) ]; } } @@ -1028,7 +1056,14 @@ function saveAsPage() { if (!$grapesPage->find(true)) { return [ 'success' =>false, - 'message' => "Page with ID $grapesPageId not found. Unable to update." + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => "Page with ID $grapesPageId not found. Unable to update.", + 'isPublicFacing' => true + ]) ]; } $grapesPage->grapesGenId = $grapesGenId; @@ -1038,18 +1073,39 @@ function saveAsPage() { if (!$grapesPage->update()) { return [ - 'success ' => false, - 'message' => 'Failed to update the page.' + 'success' => false, + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'Failed to update the page.', + 'isPublicFacing' => true + ]) ]; } return [ 'success' => true, - 'message' => 'Page saved successfully.' + 'title' => translate([ + 'text' => 'Success', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'Page saved successfully.', + 'isPublicFacing' => true + ]) ]; } catch (Exception $e) { return [ 'success' => false, - 'message' => 'An unexpected error occurred: ' . $e->getMessage() + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'An unexpected error occurred: ' . $e->getMessage(), + 'isPublicFacing' => true + ]) ]; } } From 7658ba50db6737824604531fe30ebd25239cbdfe Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 15 Jan 2025 21:28:11 +0000 Subject: [PATCH 05/11] refactor: Update success and error save messages Update success and error messages displayed on save to be translatable --- .../WebBuilder/createTemplatejs.tpl | 11 ++- .../themes/responsive/WebBuilder/grapesjs.tpl | 10 ++- code/web/services/WebBuilder/AJAX.php | 74 ++++++++++++++++--- 3 files changed, 80 insertions(+), 15 deletions(-) diff --git a/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl b/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl index 2338ec95b7..02bf4d8543 100644 --- a/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl +++ b/code/web/interface/themes/responsive/WebBuilder/createTemplatejs.tpl @@ -108,15 +108,20 @@ }), contentType: "application/json", success: function (response) { + var title = response.title; + var message; + if (response.success) { - AspenDiscovery.showMessage('Success', response.message); + message = response.message || 'Template updated successfully.'; + AspenDiscovery.showMessage(title, message); } else { - AspenDiscovery.showMessage('Error', response.message || 'Failed to save template.'); + message = response.message || 'Failed to save template.' + AspenDiscovery.showMessage(title, message); } }, error: function (xhr, status, error) { console.error('Error saving template: ', error); - let errorMessage = 'Failed to save template. Please try again.'; + var errorMessage = 'Failed to save template. Please try again.'; if (xhr.responseJSON && xhr.responseJSON.message) { errorMessage = xhr.responseJSON.message; } diff --git a/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl b/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl index ef68102b0a..a7798532a8 100644 --- a/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl +++ b/code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl @@ -106,15 +106,19 @@ }), contentType: "application/json", success: function (response) { + var title = response.title; + var message; if (response.success) { - AspenDiscovery.showMessage('Success', response.message); + message = response.message || 'Page Saved.'; + AspenDiscovery.showMessage(title, message); } else { - AspenDiscovery.showMessage('Error', response.message || 'Failed to save page.'); + message = response.message || 'Failed to save page.'; + AspenDiscovery.showMessage(title, message); } }, error: function (xhr, status, error) { console.error('Error saving page: ', error); - let errorMessage = 'Failed to save page. Please try again.'; + var errorMessage = 'Failed to save page. Please try again.'; if (xhr.responseJSON && xhr.responseJSON.message){ errorMessage = xhr.responseJSON.message; } diff --git a/code/web/services/WebBuilder/AJAX.php b/code/web/services/WebBuilder/AJAX.php index 36a18bad52..cea783dac4 100644 --- a/code/web/services/WebBuilder/AJAX.php +++ b/code/web/services/WebBuilder/AJAX.php @@ -986,7 +986,14 @@ function saveAsTemplate(){ if (!$template->find(true)) { return [ 'success' => false, - 'message' => "Template with ID $templateId not found. Unable to update." + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => "Template with ID $templateId not found. Unable to update.", + 'isPublicFacing' => true + ]) ]; } $template->templateContent = $projectData; @@ -996,17 +1003,38 @@ function saveAsTemplate(){ if(!$template->update()) { return [ 'success' => false, - 'message' => 'Failed to update the template.' + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'Failed to update the template.', + 'isPublicFacing' => true + ]) ]; } return [ 'success' => true, - 'message' => 'Template saved successfully.' + 'title' => translate([ + 'text' => 'Success', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'Template saved successfully.', + 'isPublicFacing' => true + ]) ]; } catch (Exception $e) { return [ 'success' => false, - 'message' => 'an unexpected error occurred: ' . $e->getMessage() + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'An unexpected error occurred: ' . $e->getMessage(), + 'isPublicFacing' => true + ]) ]; } } @@ -1028,7 +1056,14 @@ function saveAsPage() { if (!$grapesPage->find(true)) { return [ 'success' =>false, - 'message' => "Page with ID $grapesPageId not found. Unable to update." + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => "Page with ID $grapesPageId not found. Unable to update.", + 'isPublicFacing' => true + ]) ]; } $grapesPage->grapesGenId = $grapesGenId; @@ -1038,18 +1073,39 @@ function saveAsPage() { if (!$grapesPage->update()) { return [ - 'success ' => false, - 'message' => 'Failed to update the page.' + 'success' => false, + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'Failed to update the page.', + 'isPublicFacing' => true + ]) ]; } return [ 'success' => true, - 'message' => 'Page saved successfully.' + 'title' => translate([ + 'text' => 'Success', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'Page saved successfully.', + 'isPublicFacing' => true + ]) ]; } catch (Exception $e) { return [ 'success' => false, - 'message' => 'An unexpected error occurred: ' . $e->getMessage() + 'title' => translate([ + 'text' => 'Error', + 'isPublicFacing' => true + ]), + 'message' => translate([ + 'text' => 'An unexpected error occurred: ' . $e->getMessage(), + 'isPublicFacing' => true + ]) ]; } } From e6224f9430b4fb572b3acf6a273cea2d8c5e6889 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 17 Jan 2025 15:38:13 +0000 Subject: [PATCH 06/11] refactor: Add User Logged In Check to Grapes Add a check to ensure user is logged in before they can save a grapes template or page. --- code/web/services/WebBuilder/AJAX.php | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/code/web/services/WebBuilder/AJAX.php b/code/web/services/WebBuilder/AJAX.php index cea783dac4..99a373ec15 100644 --- a/code/web/services/WebBuilder/AJAX.php +++ b/code/web/services/WebBuilder/AJAX.php @@ -972,7 +972,20 @@ function trackWebResourceUsage() { } function saveAsTemplate(){ require_once ROOT_DIR . '/sys/WebBuilder/GrapesTemplate.php'; - + + if (!UserAccount::isLoggedIn()) { + return [ + 'success' => false, + 'title' => translate([ + 'text' =>'Error', + 'isPublicFacing' => true, + ]), + 'message' => translate([ + 'text' => 'You must be logged in to save grapes templates.', + 'isPublicFacing' => true + ]) + ]; + } try { $newGrapesPageContent = json_decode(file_get_contents("php://input"), true); $templateId = $newGrapesPageContent['templateId']; @@ -1042,6 +1055,20 @@ function saveAsTemplate(){ function saveAsPage() { require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php'; + if (!UserAccount::isLoggedIn()) { + return [ + 'success' => false, + 'title' => translate([ + 'text' =>'Error', + 'isPublicFacing' => true, + ]), + 'message' => translate([ + 'text' => 'You must be logged in to save grapes pages.', + 'isPublicFacing' => true + ]) + ]; + } + try { $newGrapesPageContent = json_decode(file_get_contents("php://input"), true); $grapesPageId = $newGrapesPageContent['grapesPageId']; From f60b5ab2207bfba3674ebaffa138021a9f025911 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 17 Jan 2025 15:55:44 +0000 Subject: [PATCH 07/11] feat: Check user grapes permissions before saving --- code/web/services/WebBuilder/AJAX.php | 34 +++++++++++++++++++- code/web/services/WebBuilder/GrapesPages.php | 4 +-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/code/web/services/WebBuilder/AJAX.php b/code/web/services/WebBuilder/AJAX.php index 99a373ec15..77d3e2ff86 100644 --- a/code/web/services/WebBuilder/AJAX.php +++ b/code/web/services/WebBuilder/AJAX.php @@ -984,6 +984,22 @@ function saveAsTemplate(){ 'text' => 'You must be logged in to save grapes templates.', 'isPublicFacing' => true ]) + ]; + } + if (!UserAccount::userHasPermission([ + 'Administer All Grapes Pages', + 'Administer Library Custom Pages', + ])) { + return [ + 'success' => false, + 'title' => translate([ + 'text' =>'Error', + 'isPublicFacing' => true, + ]), + 'message' => translate([ + 'text' => 'You do not have the correct permissions to save grapes templates.', + 'isPublicFacing' => true + ]) ]; } try { @@ -1066,7 +1082,23 @@ function saveAsPage() { 'text' => 'You must be logged in to save grapes pages.', 'isPublicFacing' => true ]) - ]; + ]; + } + if (!UserAccount::userHasPermission([ + 'Administer All Grapes Pages', + 'Administer Library Custom Pages', + ])) { + return [ + 'success' => false, + 'title' => translate([ + 'text' =>'Error', + 'isPublicFacing' => true, + ]), + 'message' => translate([ + 'text' => 'You do not have the correct permissions to save grapes templates.', + 'isPublicFacing' => true + ]) + ]; } try { diff --git a/code/web/services/WebBuilder/GrapesPages.php b/code/web/services/WebBuilder/GrapesPages.php index d27071a39a..7d3d75058f 100644 --- a/code/web/services/WebBuilder/GrapesPages.php +++ b/code/web/services/WebBuilder/GrapesPages.php @@ -83,8 +83,8 @@ function getBreadcrumbs(): array { function canView(): bool { return UserAccount::userHasPermission([ - 'Administer All Basic Pages', - 'Administer Library Basic Pages', + 'Administer All Grapes Pages', + 'Administer Library Grapes Pages', ]); } From 14bff62cd2a3a52d13f28a5a34a1c2eed34e5331 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 17 Jan 2025 16:30:55 +0000 Subject: [PATCH 08/11] chore: Update change log --- code/web/release_notes/25.02.00.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/web/release_notes/25.02.00.MD b/code/web/release_notes/25.02.00.MD index 4020a5ba74..2e1106d050 100644 --- a/code/web/release_notes/25.02.00.MD +++ b/code/web/release_notes/25.02.00.MD @@ -58,7 +58,7 @@ //alexander ### Web Builder Updates -- Add a message when saving a Grapes JS Template or Page to confirm it has been updated successfully. (*AB*) +- Add a message when saving a Grapes JS Template or Page to confirm it has been updated successfully. (DIS-92) (*AB*) //chloe From 22f7e9df929ddcb68328251ff2112d7e6a4d89b8 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 17 Jan 2025 15:55:44 +0000 Subject: [PATCH 09/11] feat: Check user grapes permissions before saving --- code/web/services/WebBuilder/AJAX.php | 34 +++++++++++++++++++- code/web/services/WebBuilder/GrapesPages.php | 4 +-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/code/web/services/WebBuilder/AJAX.php b/code/web/services/WebBuilder/AJAX.php index 99a373ec15..b0dab984cc 100644 --- a/code/web/services/WebBuilder/AJAX.php +++ b/code/web/services/WebBuilder/AJAX.php @@ -984,6 +984,22 @@ function saveAsTemplate(){ 'text' => 'You must be logged in to save grapes templates.', 'isPublicFacing' => true ]) + ]; + } + if (!UserAccount::userHasPermission([ + 'Administer All Grapes Pages', + 'Administer Library Custom Pages', + ])) { + return [ + 'success' => false, + 'title' => translate([ + 'text' =>'Error', + 'isPublicFacing' => true, + ]), + 'message' => translate([ + 'text' => 'You do not have the correct permissions to save grapes templates.', + 'isPublicFacing' => true + ]) ]; } try { @@ -1066,7 +1082,23 @@ function saveAsPage() { 'text' => 'You must be logged in to save grapes pages.', 'isPublicFacing' => true ]) - ]; + ]; + } + if (!UserAccount::userHasPermission([ + 'Administer All Grapes Pages', + 'Administer Library Custom Pages', + ])) { + return [ + 'success' => false, + 'title' => translate([ + 'text' =>'Error', + 'isPublicFacing' => true, + ]), + 'message' => translate([ + 'text' => 'You do not have the correct permissions to save grapes pages.', + 'isPublicFacing' => true + ]) + ]; } try { diff --git a/code/web/services/WebBuilder/GrapesPages.php b/code/web/services/WebBuilder/GrapesPages.php index d27071a39a..7d3d75058f 100644 --- a/code/web/services/WebBuilder/GrapesPages.php +++ b/code/web/services/WebBuilder/GrapesPages.php @@ -83,8 +83,8 @@ function getBreadcrumbs(): array { function canView(): bool { return UserAccount::userHasPermission([ - 'Administer All Basic Pages', - 'Administer Library Basic Pages', + 'Administer All Grapes Pages', + 'Administer Library Grapes Pages', ]); } From 8f50bb1940ae60648474bc7e854c5f1f292f27a5 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 17 Jan 2025 16:30:55 +0000 Subject: [PATCH 10/11] chore: Update change log --- code/web/release_notes/25.02.00.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/web/release_notes/25.02.00.MD b/code/web/release_notes/25.02.00.MD index 4020a5ba74..2e1106d050 100644 --- a/code/web/release_notes/25.02.00.MD +++ b/code/web/release_notes/25.02.00.MD @@ -58,7 +58,7 @@ //alexander ### Web Builder Updates -- Add a message when saving a Grapes JS Template or Page to confirm it has been updated successfully. (*AB*) +- Add a message when saving a Grapes JS Template or Page to confirm it has been updated successfully. (DIS-92) (*AB*) //chloe From 9bb9c6030db9dccedf700ba46131f19a299f61e3 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 17 Jan 2025 17:12:22 +0000 Subject: [PATCH 11/11] refactor: Alter check to use active user --- code/web/services/WebBuilder/AJAX.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/web/services/WebBuilder/AJAX.php b/code/web/services/WebBuilder/AJAX.php index b0dab984cc..f7dd6e4740 100644 --- a/code/web/services/WebBuilder/AJAX.php +++ b/code/web/services/WebBuilder/AJAX.php @@ -972,8 +972,10 @@ function trackWebResourceUsage() { } function saveAsTemplate(){ require_once ROOT_DIR . '/sys/WebBuilder/GrapesTemplate.php'; + + $activeUser = UserAccount::getActiveUserObj(); - if (!UserAccount::isLoggedIn()) { + if (!$activeUser) { return [ 'success' => false, 'title' => translate([ @@ -1071,7 +1073,9 @@ function saveAsTemplate(){ function saveAsPage() { require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php'; - if (!UserAccount::isLoggedIn()) { + $activeUser = UserAccount::getActiveUserObj(); + + if (!$activeUser) { return [ 'success' => false, 'title' => translate([