Skip to content

Commit

Permalink
LUT-28237 : add archive confirmation for published blogs
Browse files Browse the repository at this point in the history
  • Loading branch information
husel-t committed Jan 10, 2025
1 parent 992399f commit 78e1576
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 23 additions & 8 deletions src/java/fr/paris/lutece/plugins/blog/web/BlogJspBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1790,7 +1792,6 @@ private void removeMultipleBlogs( List<Integer> listBlogIds )
}
for ( int blogId : listBlogIds )
{
BlogPublicationHome.getDocPublicationByIdDoc( blogId );
if ( BlogPublicationHome.getDocPublicationByIdDoc( blogId ) != null && BlogPublicationHome.getDocPublicationByIdDoc( blogId ).size( ) > 0 )
{
BlogPublicationHome.removeByBlogId( blogId );
Expand All @@ -1808,7 +1809,7 @@ private void removeMultipleBlogs( List<Integer> 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,
Expand All @@ -1828,17 +1829,31 @@ 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( )
};
return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, messageArgs, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ));
}
else
{
confirmationMessage = publishedBlog ? MESSAGE_CONFIRM_ARCHIVE_PUBLISHED_BLOG : MESSAGE_CONFIRM_ARCHIVE_BLOG;
return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ));
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -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 )
{
Expand Down
9 changes: 6 additions & 3 deletions webapp/WEB-INF/templates/admin/plugins/blog/manage_blogs.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
<option value=1 >#i18n{blog.manage_blogs.labelUnarchive}</option>
<option value=0 selected>#i18n{blog.manage_blogs.labelArchive}</option>
<#if status_filter == 3>
<option value=1 >#i18n{blog.manage_blogs.labelUnarchive}</option>
<#else>
<option value=0 selected>#i18n{blog.manage_blogs.labelArchive}</option>
</#if>
</#if>
<#if permission_manage_delete_blog && status_filter == 3>
<option value=2>#i18n{blog.manage_blogs.delete}</option>
Expand Down Expand Up @@ -154,7 +157,7 @@
</#list>
</@td>
<@td>
<#if permission_manage_publish_blog>
<#if permission_manage_publish_blog && status_filter != 3>
<#assign btnColor><#if blog.blogPublication?size = 0>default<#else>primary</#if></#assign>
<#assign btnTitle><#if blog.blogPublication?size==0>#i18n{blog.manage_blogs.labelPublished}<#else>#i18n{blog.manage_blogs.managePublication}</#if></#assign>
<@btnGroup params='aria-label="Manage"'>
Expand Down

0 comments on commit 78e1576

Please sign in to comment.