Skip to content

Commit

Permalink
LUT-28236 : Delete action: adding a confirmation popup
Browse files Browse the repository at this point in the history
  • Loading branch information
husel-t committed Jan 6, 2025
1 parent 658b5a5 commit 092f202
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ diff_blog.latestVersion=Compare the latest versions

message.confirmRemoveBlog=Are you sure that you want to delete this post?
message.confirmRemoveHistoryBlog=Are you sure that you want to delete this version of the post?
message.errorDocumentIsPublished=This post is still published in the site, please unpublish it before delete it.
message.errorDocumentIsActive=This post is still active in the site, please archive it before deleting it.
message.errorTagIsAffected=This Tag is still atached to a post, please detached it before delete it !
message.errorTagExist=This Tag already exist !
message.errorTagUpdatePosition=The tag position can not be updated !
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ message.mandatory.searchField=Le champs de recherche est obligatoire !
message.notNumericField=Le champs doit \u00e9tre au format num\u00e9rique !
message.confirmRemoveBlog=Voulez-vous supprimer ce billet ?
message.confirmRemoveHistoryBlog=Voulez-vous supprimer cette version du billet ?
message.errorDocumentIsPublished=Ce billet est encore publi\u00e9 sur le site, pour le supprimer d\u00e9publiez-le !
message.errorDocumentIsActive=Ce billet est encore actif sur le site, pour supprimer ce billet merci d'archiver le billet au pr\u00e9alable.
message.errorTagIsAffected=Ce Tag est est attach\u00e9 \u00e0 un billet, pour le supprimer d\u00e9tachez le !
message.errorTagExist=Ce Tag existe d\u00e9j\a !
message.errorTagUpdatePosition=Impossible de mettre \u00e0 jour la position de ce tag !
Expand Down
103 changes: 84 additions & 19 deletions src/java/fr/paris/lutece/plugins/blog/web/BlogJspBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import fr.paris.lutece.util.date.DateUtil;

import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -74,8 +72,6 @@
import org.outerj.daisy.diff.html.TextNodeComparator;
import org.outerj.daisy.diff.html.dom.DomTreeBuilder;
import org.xml.sax.InputSource;
import java.text.MessageFormat;


import fr.paris.lutece.api.user.User;
import fr.paris.lutece.plugins.blog.business.Blog;
Expand All @@ -93,7 +89,6 @@
import fr.paris.lutece.plugins.blog.service.BlogSessionListner;
import fr.paris.lutece.plugins.blog.service.docsearch.BlogSearchService;
import fr.paris.lutece.plugins.blog.utils.BlogLock;
import fr.paris.lutece.plugins.blog.utils.BlogUtils;
import fr.paris.lutece.portal.business.rbac.RBAC;
import fr.paris.lutece.portal.business.user.AdminUser;
import fr.paris.lutece.portal.service.admin.AccessDeniedException;
Expand Down Expand Up @@ -182,7 +177,6 @@ public class BlogJspBean extends ManageBlogJspBean
private static final String PROPERTY_PAGE_TITLE_PREVIEW_BLOG = "blog.preview_blog.pageTitle";
private static final String PROPERTY_PAGE_TITLE_DIFF_BLOG = "blog.diff_blog.pageTitle";
protected static final String PROPERTY_USE_UPLOAD_IMAGE_PLUGIN = "use_upload_image_plugin";
protected static final String PROPERTY_BLOG_ARCHIVE = "blog.manage_blog_archives.labelActionArchive";

// Markers
protected static final String MARK_BLOG_LIST = "blog_list";
Expand Down Expand Up @@ -213,7 +207,7 @@ public class BlogJspBean extends ManageBlogJspBean
// Properties
private static final String PROPERTY_DEFAULT_LIST_ITEM_PER_PAGE = "blog.listItems.itemsPerPage";
private static final String MESSAGE_CONFIRM_REMOVE_BLOG = "blog.message.confirmRemoveBlog";
private static final String MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED = "blog.message.errorDocumentIsPublished";
private static final String MESSAGE_ERROR_DOCUMENT_IS_ACTIVE = "blog.message.errorDocumentIsActive";
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";
Expand All @@ -222,7 +216,6 @@ public class BlogJspBean extends ManageBlogJspBean
private static final String MESSAGE_CONFIRM_UNARCHIVE_BLOG= "blog.message.confirmUnarchiveBlog";
private static final String MESSAGE_CONFIRM_REMOVE_MULTIPE_BLOGS = "blog.message.confirmRemoveMultipleBlogs";

protected static final String MARK_BLOG_ACTION_LIST = "selection_action_list";
private static final String INFO_BLOG_UNARCHIVED = "blog.info.blog.blogUnarchived";
private static final String INFO_MULTIPLE_BLOGS_UNARCHIVED = "blog.info.blog.multipleBlogsUnarchived";
private static final String INFO_BLOG_ARCHIVED = "blog.info.blog.blogArchived";
Expand Down Expand Up @@ -256,8 +249,7 @@ public class BlogJspBean extends ManageBlogJspBean
private static final String ACTION_UPDATE_ARCHIVE_MULTIPLE_BLOGS = "updateArchiveMultipleBlogs";
private static final String ACTION_REMOVE_MULTIPLE_BLOGS = "removeMultipleBlogs";
private static final String ACTION_EXECUTE_SELECTED_ACTION = "form_checkbox_action";
private static final String ACTION_CONFIRM_ARCHIVE_BLOG = "confirmArchiveBlog";
private static final String ACTION_ARCHIVE_BLOG = "archiveBlog";
private static final String ACTION_CONFIRM_REMOVE_MULTIPLE_BLOGS = "confirmRemoveMultipleBlogs";
private static final String ACTION_CONFIRM_ARCHIVE_BLOGS = "confirmArchiveBlogs";
private static final String ACTION_CONFIRM_UNARCHIVE_BLOGS = "confirmUnarchiveBlogs";

Expand All @@ -267,6 +259,7 @@ public class BlogJspBean extends ManageBlogJspBean
private static final String INFO_BLOG_REMOVED = "blog.info.blog.removed";
private static final String BLOG_LOCKED = "blog.message.blogLocked";
private static final String INFO_HISTORY_BLOG_REMOVED = "blog.info.history.blog.removed";
private static final String INFO_MULTIPLE_BLOGS_REMOVED = "blog.info.blog.multipleBlogsRemoved";

// Errors
private static final String ERROR_HISTORY_BLOG_CANT_REMOVE_ORIGINAL = "blog.error.history.blog.cantRemoveOriginal";
Expand Down Expand Up @@ -309,7 +302,6 @@ public class BlogJspBean extends ManageBlogJspBean
protected String _strSortedAttributeName;
protected Boolean _bIsAscSort;
protected String [ ] _strTag;
private ReferenceList _listBlogActionsList;
private List<Integer> _listSelectedBlogIds = new ArrayList<>( );


Expand Down Expand Up @@ -620,12 +612,12 @@ public String doRemoveHistoryBlog( HttpServletRequest request )
}
// Check if this blog is currently published
List<BlogPublication> docPublication = BlogPublicationHome.getDocPublicationByIdDoc( nBlogId );
if ( CollectionUtils.isNotEmpty( docPublication ) )
if ( CollectionUtils.isNotEmpty( docPublication ) || BlogHome.findByPrimaryKey( nBlogId ).isArchived() )
{
// Inform the user that the blog is currently published and redirect to the blog's history view
UrlItem url = new UrlItem( getViewFullUrl( VIEW_HISTORY_BLOG ) );
url.addParameter( PARAMETER_ID_BLOG, nBlogId );
String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED, url.getUrl( ),
String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_ACTIVE, url.getUrl( ),
AdminMessage.TYPE_STOP );
return redirect( request, strMessageUrl );
}
Expand Down Expand Up @@ -953,9 +945,9 @@ public String doRemoveBlog( HttpServletRequest request )

List<BlogPublication> docPublication = BlogPublicationHome.getDocPublicationByIdDoc( nId );

if ( CollectionUtils.isNotEmpty( docPublication ) )
if ( CollectionUtils.isNotEmpty( docPublication ) || BlogHome.findByPrimaryKey( nId ).isArchived() )
{
String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_PUBLISHED, AdminMessage.TYPE_STOP );
String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_ACTIVE, AdminMessage.TYPE_STOP );

return redirect( request, strMessageUrl );
}
Expand All @@ -965,7 +957,8 @@ public String doRemoveBlog( HttpServletRequest request )

ExtendableResourceRemovalListenerService.doRemoveResourceExtentions( Blog.PROPERTY_RESOURCE_TYPE, String.valueOf( nId ) );

addInfo( INFO_BLOG_REMOVED, getLocale( ) );
HttpSession session = request.getSession();
session.setAttribute( PARAMETER_INFO_MESSAGE, INFO_BLOG_REMOVED);
}
return redirectView( request, VIEW_MANAGE_BLOGS );
}
Expand Down Expand Up @@ -1673,6 +1666,51 @@ private static boolean checkLockBlog( int nIdBlog, String strIdSession )
}


/**
* Display the confirmation message before one or multiple selected blog posts are deleted
*
* @param request
* The Http request
* @return the html code to confirm the action
* @throws AccessDeniedException
*/
@Action( ACTION_CONFIRM_REMOVE_MULTIPLE_BLOGS )
public String getConfirmRemoveMultipleBlogs( HttpServletRequest request ) throws AccessDeniedException
{
// Check if the user has the permission to archive a blog
AdminUser adminUser = AdminUserService.getAdminUser( request );
User user = AdminUserService.getAdminUser( request );
if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, Blog.PERMISSION_DELETE, user ) )
{
String strMessage = I18nService.getLocalizedString( ACCESS_DENIED_MESSAGE, request.getLocale( ) );
throw new AccessDeniedException( strMessage );
}

// Check if one of the blog selected is currently locked. Display a message and redirect the user if it's the case
if ( checkLockMultipleBlogs( request.getSession( ).getId( ) ) )
{
UrlItem url = new UrlItem( getActionUrl( VIEW_MANAGE_BLOGS ) );
String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
return redirect( request, strMessageUrl );
}

UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_MULTIPLE_BLOGS ) );
url.addParameter( PARAMETER_SELECTED_BLOGS, _listSelectedBlogIds.stream( ).map( String::valueOf ).collect( Collectors.joining( "," ) ) );
// Check if there's 1 or multiple posts to be removed, to adapt the content of the displayed message
String confirmationMessage = _listSelectedBlogIds.size( ) > 1 ? MESSAGE_CONFIRM_REMOVE_MULTIPE_BLOGS : MESSAGE_CONFIRM_REMOVE_BLOG;
if( _listSelectedBlogIds.size( ) > 1 )
{
Object [ ] messageArgs = {
_listSelectedBlogIds.size( )
};
return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, messageArgs, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ));
}
else
{
return redirect( request, AdminMessageService.getMessageUrl( request, confirmationMessage, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ));
}
}

/**
* Handles the manual delete of multiple blog posts
*
Expand All @@ -1693,7 +1731,7 @@ public String doRemoveMultipleBlog( HttpServletRequest request ) throws AccessDe
throw new AccessDeniedException( strMessage );
}
// Get a List of the selected posts' IDs, from the current session
_listSelectedBlogIds = getSelectedBlogPostsIds( request );
_listSelectedBlogIds = (List<Integer>) request.getSession( ).getAttribute( PARAMETER_SELECTED_BLOG_IDS_LIST );

// Check if any of the selected post is being modified by another user
if ( checkLockMultipleBlogs( request.getSession( ).getId( ) ) )
Expand All @@ -1702,7 +1740,18 @@ public String doRemoveMultipleBlog( HttpServletRequest request ) throws AccessDe
String strMessageUrl = AdminMessageService.getMessageUrl( request, BLOG_LOCKED, url.getUrl( ), AdminMessage.TYPE_STOP );
return redirect( request, strMessageUrl );
}
for ( int docPublicationId : _listSelectedBlogIds )
{
if ( CollectionUtils.isNotEmpty( BlogPublicationHome.getDocPublicationByIdDoc( docPublicationId ) ) )
{
String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DOCUMENT_IS_ACTIVE, AdminMessage.TYPE_STOP );

return redirect( request, strMessageUrl );
}
}
removeMultipleBlogs( _listSelectedBlogIds );
HttpSession session = request.getSession();
session.setAttribute( PARAMETER_INFO_MESSAGE, getRemovedResultMessageKey( _listSelectedBlogIds ));
return redirectView( request, VIEW_MANAGE_BLOGS );
}
private void removeMultipleBlogs( List<Integer> listBlogIds )
Expand Down Expand Up @@ -1877,6 +1926,22 @@ private String getArchivedResultMessageKey(Boolean toArchived, List<Integer> lis
}
}
}
/**
* Get the key of the message to display after the removing of multiple blog posts
* @param listBlogIds
* @return the key of the message to display
*/
private String getRemovedResultMessageKey(List<Integer> listBlogIds)
{
if(listBlogIds.size() == 1)
{
return INFO_BLOG_REMOVED;
}
else
{
return INFO_MULTIPLE_BLOGS_REMOVED;
}
};

/**
* Process a specific action on a selection of multiple blog post elements
Expand Down Expand Up @@ -1917,7 +1982,7 @@ else if ( selectedActionId == 1 )
}
else if ( selectedActionId == 2 )
{
return doRemoveMultipleBlog( request );
return getConfirmRemoveMultipleBlogs( request );
}
else
{
Expand Down Expand Up @@ -1975,7 +2040,7 @@ private List<Integer> getSelectedBlogPostsIds( HttpServletRequest request )
*/
private synchronized boolean checkLockMultipleBlogs( String strIdSession )
{
if(_listBlogActionsList == null || CollectionUtils.isEmpty( _listSelectedBlogIds ))
if( CollectionUtils.isEmpty( _listSelectedBlogIds ))
{
return false;
}
Expand Down

0 comments on commit 092f202

Please sign in to comment.