From 78e1576ae850d4e989eeb76e22f8eb023d163f28 Mon Sep 17 00:00:00 2001 From: Thusel Date: Fri, 10 Jan 2025 17:32:08 +0100 Subject: [PATCH] LUT-28237 : add archive confirmation for published blogs --- .../blog/resources/blog_messages.properties | 12 ++++--- .../resources/blog_messages_fr.properties | 6 ++-- .../lutece/plugins/blog/web/BlogJspBean.java | 31 ++++++++++++++----- .../admin/plugins/blog/manage_blogs.html | 9 ++++-- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/java/fr/paris/lutece/plugins/blog/resources/blog_messages.properties b/src/java/fr/paris/lutece/plugins/blog/resources/blog_messages.properties index f2979e2c..e1dc927a 100644 --- a/src/java/fr/paris/lutece/plugins/blog/resources/blog_messages.properties +++ b/src/java/fr/paris/lutece/plugins/blog/resources/blog_messages.properties @@ -196,11 +196,13 @@ message.errorTagUpdatePosition=The tag position can not be updated ! message.errorTagDeletion=The tag can not be deleted ! message.errorTagTitleNotEmpty=The tag title can not be empty ! message.errorTagNotSet=Can not set the tag ! -message.confirmArchiveBlog=Are you sure you want to archive this blog post ? Please note that publications of this post will be removed. -message.confirmArchiveMultipleBlogs=Are you sure you want to archive these blog posts ? Please note that publications of these posts will be removed. -message.confirmUnarchiveMultipleBlogs=Are you sure you want to unarchive these blog posts ? -message.confirmUnarchiveBlog=Are you sure you want to unarchive this blog post ? -message.confirmRemoveMultipleBlogs=Are you sure you want to delete these blog posts ? Please note that contents associated with these posts will be removed. +message.confirmArchiveBlog=Do you want to archive this blog ? +message.confirmArchivePublishedBlog=This blog is still assigned to a portlet. Do you want to unpublish and archive this blog ? +message.confirmArchiveMultipleBlogs=Do you want to archive these {0} blogs ? +message.confirmArchiveMultiplePublishedBlogs=At least one of these blogs is assigned to a portlet. Do you want to unpublish and archive these {0} blogs ? +message.confirmUnarchiveMultipleBlogs=Do you want to unarchive these {0} blogs ? +message.confirmUnarchiveBlog=Do you want to unarchive this blog ? +message.confirmRemoveMultipleBlogs=Are you sure you want to delete these {0} blog ? Please note that contents associated with these posts will be removed. publication_blog.pageTitle=Posts Publication diff --git a/src/java/fr/paris/lutece/plugins/blog/resources/blog_messages_fr.properties b/src/java/fr/paris/lutece/plugins/blog/resources/blog_messages_fr.properties index 98e217f8..ded89723 100644 --- a/src/java/fr/paris/lutece/plugins/blog/resources/blog_messages_fr.properties +++ b/src/java/fr/paris/lutece/plugins/blog/resources/blog_messages_fr.properties @@ -361,8 +361,10 @@ message.errorTagUpdatePosition=Impossible de mettre \u00e0 jour la position de c message.errorTagDeletion=Le tag ne peut \u00e9tre supprim\u00e9 ! message.errorTagTitleNotEmpty=Le titre du tag peut \u00e9tre vide ! message.errorTagNotSet=Impossible d'ajouter ce tag ! -message.confirmArchiveBlog=Voulez-vous archiver ce billet ? Les publications associ\u00e9es de ce billet seront supprim\u00e9es. -message.confirmArchiveMultipleBlogs=Voulez-vous archiver ces {0} billets ? Les publications associ\u00e9es \u00e0 ces billets seront supprim\u00e9es. +message.confirmArchiveBlog=Voulez-vous archiver ce billet ? +message.confirmArchivePublishedBlog=Ce billet est assign\u00e9 \u00e0 une rubrique du site. Souhaitez-vous d\u00e9publier ce billet et l'archiver ? +message.confirmArchiveMultipleBlogs=Voulez-vous archiver ces {0} billets ? +message.confirmArchiveMultiplePublishedBlogs=Au moins un de ces billet est assign\u00e9 \u00e0 une rubrique du site. Souhaitez-vous d\u00e9publier et archiver ces {0} billets ? message.confirmUnarchiveMultipleBlogs=Voulez-vous d\u00e9sarchiver ces {0} billets ? message.confirmUnarchiveBlog=Voulez-vous d\u00e9sarchiver ce billet ? message.confirmRemoveMultipleBlogs=Voulez-vous supprimer ces {0} billets ? Les contenus associ\u00e9s \u00e0 ces billets seront supprim\u00e9s. diff --git a/src/java/fr/paris/lutece/plugins/blog/web/BlogJspBean.java b/src/java/fr/paris/lutece/plugins/blog/web/BlogJspBean.java index 40951943..0cf5a9ce 100644 --- a/src/java/fr/paris/lutece/plugins/blog/web/BlogJspBean.java +++ b/src/java/fr/paris/lutece/plugins/blog/web/BlogJspBean.java @@ -212,7 +212,9 @@ public class BlogJspBean extends ManageBlogJspBean private static final String MESSAGE_CONFIRM_REMOVE_HISTORY_BLOG = "blog.message.confirmRemoveHistoryBlog"; private static final String ACCESS_DENIED_MESSAGE = "portal.message.user.accessDenied"; private static final String MESSAGE_CONFIRM_ARCHIVE_BLOG = "blog.message.confirmArchiveBlog"; + private static final String MESSAGE_CONFIRM_ARCHIVE_PUBLISHED_BLOG = "blog.message.confirmArchivePublishedBlog"; private static final String MESSAGE_CONFIRM_ARCHIVE_MULTIPLE_BLOGS = "blog.message.confirmArchiveMultipleBlogs"; + private static final String MESSAGE_CONFIRM_ARCHIVE_MULTIPLE_PUBLISHED_BLOGS = "blog.message.confirmArchiveMultiplePublishedBlogs"; private static final String MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED = "blog.message.errorDocumentIsPublished"; private static final String MESSAGE_CONFIRM_UNARCHIVE_MULTIPLE_BLOGS = "blog.message.confirmUnarchiveMultipleBlogs"; private static final String MESSAGE_CONFIRM_UNARCHIVE_BLOG= "blog.message.confirmUnarchiveBlog"; @@ -1790,7 +1792,6 @@ private void removeMultipleBlogs( List listBlogIds ) } for ( int blogId : listBlogIds ) { - BlogPublicationHome.getDocPublicationByIdDoc( blogId ); if ( BlogPublicationHome.getDocPublicationByIdDoc( blogId ) != null && BlogPublicationHome.getDocPublicationByIdDoc( blogId ).size( ) > 0 ) { BlogPublicationHome.removeByBlogId( blogId ); @@ -1808,7 +1809,7 @@ private void removeMultipleBlogs( List listBlogIds ) * @throws AccessDeniedException */ @Action( ACTION_CONFIRM_ARCHIVE_BLOGS ) - public String getconfirmArchiveBlogs( HttpServletRequest request ) throws AccessDeniedException + public String getConfirmArchiveBlogs( HttpServletRequest request ) throws AccessDeniedException { // Check if the user has the permission to archive a blog if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_ARCHIVE, @@ -1828,10 +1829,23 @@ public String getconfirmArchiveBlogs( HttpServletRequest request ) throws Access UrlItem url = new UrlItem( getActionUrl( ACTION_UPDATE_ARCHIVE_MULTIPLE_BLOGS ) ); url.addParameter( PARAMETER_SELECTED_BLOGS, _listSelectedBlogIds.stream( ).map( String::valueOf ).collect( Collectors.joining( "," ) ) ); url.addParameter( PARAMETER_TO_ARCHIVE, String.valueOf( true )); - // Check if there's 1 or multiple posts being archived, to adapt the content of the displayed message - String confirmationMessage = _listSelectedBlogIds.size( ) > 1 ? MESSAGE_CONFIRM_ARCHIVE_MULTIPLE_BLOGS : MESSAGE_CONFIRM_ARCHIVE_BLOG; - if( _listSelectedBlogIds.size( ) > 1 ) + String confirmationMessage; + Boolean publishedBlog = false; + + // Check if there is published blogs + for ( int blogId : _listSelectedBlogIds ) { + if ( BlogPublicationHome.getDocPublicationByIdDoc( blogId ) != null && !BlogPublicationHome.getDocPublicationByIdDoc( blogId ).isEmpty( ) ) + { + publishedBlog = true; + break; + } + } + + if ( _listSelectedBlogIds.size( ) > 1 ) + { + confirmationMessage = publishedBlog ? MESSAGE_CONFIRM_ARCHIVE_MULTIPLE_PUBLISHED_BLOGS : MESSAGE_CONFIRM_ARCHIVE_MULTIPLE_BLOGS; + Object [ ] messageArgs = { _listSelectedBlogIds.size( ) }; @@ -1839,6 +1853,7 @@ public String getconfirmArchiveBlogs( HttpServletRequest request ) throws Access } else { + confirmationMessage = publishedBlog ? MESSAGE_CONFIRM_ARCHIVE_PUBLISHED_BLOG : MESSAGE_CONFIRM_ARCHIVE_BLOG; return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION )); } } @@ -1851,7 +1866,7 @@ public String getconfirmArchiveBlogs( HttpServletRequest request ) throws Access * @throws AccessDeniedException */ @Action( ACTION_CONFIRM_UNARCHIVE_BLOGS ) - public String getconfirmUnarchiveBlogs( HttpServletRequest request ) throws AccessDeniedException + public String getConfirmUnarchiveBlogs( HttpServletRequest request ) throws AccessDeniedException { // Check if the user has the permission to archive a blog if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_ARCHIVE, @@ -2002,11 +2017,11 @@ public String doExecuteSelectedAction( HttpServletRequest request ) throws Acces // Execute the action selected by the user if ( selectedActionId == 0 ) { - return getconfirmArchiveBlogs( request ); + return getConfirmArchiveBlogs( request ); } else if ( selectedActionId == 1 ) { - return getconfirmUnarchiveBlogs( request ); + return getConfirmUnarchiveBlogs( request ); } else if ( selectedActionId == 2 ) { diff --git a/webapp/WEB-INF/templates/admin/plugins/blog/manage_blogs.html b/webapp/WEB-INF/templates/admin/plugins/blog/manage_blogs.html index 112b9a3f..bc03433c 100644 --- a/webapp/WEB-INF/templates/admin/plugins/blog/manage_blogs.html +++ b/webapp/WEB-INF/templates/admin/plugins/blog/manage_blogs.html @@ -76,8 +76,11 @@ <@inputGroup class='p-2'> <@select id='select_blog_action' name='select_blog_action' title='#i18n{blog.manage_blogs.selectActionToApply}' class='p-2' disabled=true> <#if permission_manage_archive_blog> - - + <#if status_filter == 3> + + <#else> + + <#if permission_manage_delete_blog && status_filter == 3> @@ -154,7 +157,7 @@ <@td> - <#if permission_manage_publish_blog> + <#if permission_manage_publish_blog && status_filter != 3> <#assign btnColor><#if blog.blogPublication?size = 0>default<#else>primary <#assign btnTitle><#if blog.blogPublication?size==0>#i18n{blog.manage_blogs.labelPublished}<#else>#i18n{blog.manage_blogs.managePublication} <@btnGroup params='aria-label="Manage"'>