@@ -155,7 +155,7 @@ public class BlogJspBean extends ManageBlogJspBean
155
155
protected static final String PARAMETER_PRIORITY = "tag_priority" ;
156
156
protected static final String PARAMETER_TAG_ACTION = "tagAction" ;
157
157
protected static final String PARAMETER_ACTION_BUTTON = "button" ;
158
- protected static final String PARAMETER_APPLY = "apply " ;
158
+ protected static final String PARAMETER_UPDATE = "update " ;
159
159
protected static final String PARAMETER_TYPE_ID = "idType" ;
160
160
protected static final String PARAMETER_CONTENT_ID = "idContent" ;
161
161
protected static final String PARAMETER_CONTENT_ACTION = "contentAction" ;
@@ -250,6 +250,7 @@ public class BlogJspBean extends ManageBlogJspBean
250
250
protected static final String MARK_DATE_UPDATE_BLOG_BEFOR = "dateUpdateBlogBefor" ;
251
251
protected static final String MARK_UNPUBLISHED = "unpublished" ;
252
252
protected static final String MARK_LIST_BLOG_CONTRIBUTORS = "list_blog_contributors" ;
253
+ protected static final String MARK_ACTUAL_BLOG_VERSION = "actual_blog_version" ;
253
254
254
255
public static final String CONSTANT_DUPLICATE_BLOG_NAME = "Copie de " ;
255
256
@@ -656,7 +657,7 @@ public String doCreateBlog( HttpServletRequest request )
656
657
BlogService .getInstance ( ).createBlog ( _blog , _blog .getDocContent ( ) );
657
658
_blogServiceSession .removeDocContentFromSession ( request .getSession ( ), user );
658
659
659
- if ( strAction != null && strAction .equals ( PARAMETER_APPLY ) )
660
+ if ( strAction != null && strAction .equals ( PARAMETER_UPDATE ) )
660
661
{
661
662
662
663
return redirect ( request , VIEW_MODIFY_BLOG , PARAMETER_ID_BLOG , _blog .getId ( ) );
@@ -952,22 +953,29 @@ public String getModifyBlog( HttpServletRequest request ) throws AccessDeniedExc
952
953
String strResetVersion = request .getParameter ( PARAMETER_VERSION_BLOG );
953
954
String useCropImage = DatastoreService .getDataValue ( PROPERTY_USE_UPLOAD_IMAGE_PLUGIN , "false" );
954
955
String sessionId = request .getSession ( ).getId ( );
956
+ Map <String , Object > model = getModel ( );
955
957
956
958
int nVersion = -1 ;
957
959
if ( strResetVersion != null )
958
960
{
959
961
nVersion = Integer .parseInt ( strResetVersion );
960
- }
961
-
962
- if ( strResetVersion != null )
963
- {
964
-
965
962
_blog = BlogHome .findVersion ( nId , nVersion );
966
963
_blogServiceSession .saveBlogInSession ( request .getSession ( ), _blog );
967
964
}
968
965
else
969
966
{
970
- _blog = BlogService .getInstance ( ).loadBlog ( nId );
967
+ Blog actualBlog = BlogService .getInstance ( ).loadBlog ( nId );
968
+ Blog lastVersion = BlogHome .getLastBlogVersionsList ( nId , 1 ).get ( 0 );
969
+
970
+ // compare if content title, description or content are differents from the last version and actual version (the version that visitors could see if the blog is published)
971
+ if ( !actualBlog .getContentLabel ( ).equals ( lastVersion .getContentLabel ( ) ) || !actualBlog .getDescription ( ).equals ( lastVersion .getDescription ( ) ) )
972
+ {
973
+ // get the actual version number that visitors could see so that the user can choose to reset to this version
974
+ Timestamp actualVersionUpdateDate = actualBlog .getUpdateDate ();
975
+ int actualVersion = BlogHome .getActualVersionNumber ( actualVersionUpdateDate ,nId );
976
+ model .put ( MARK_ACTUAL_BLOG_VERSION , actualVersion );
977
+ }
978
+ _blog = lastVersion ;
971
979
_blogServiceSession .saveBlogInSession ( request .getSession ( ), _blog );
972
980
973
981
}
@@ -993,13 +1001,15 @@ public String getModifyBlog( HttpServletRequest request ) throws AccessDeniedExc
993
1001
994
1002
_blog .getTag ( ).sort ( ( tg1 , tg2 ) -> tg1 .getPriority ( ) - tg2 .getPriority ( ) );
995
1003
_blog .getDocContent ( ).sort ( ( dc1 , dc2 ) -> dc1 .getPriority ( ) - dc2 .getPriority ( ) );
996
- Map <String , Object > model = getModel ( );
997
1004
998
1005
boolean bPermissionCreate = RBACService .isAuthorized ( Tag .PROPERTY_RESOURCE_TYPE , RBAC .WILDCARD_RESOURCES_ID , Tag .PERMISSION_CREATE ,
999
1006
(User ) getUser ( ) );
1007
+ boolean bPermissionToPublish = RBACService .isAuthorized ( Blog .PROPERTY_RESOURCE_TYPE , RBAC .WILDCARD_RESOURCES_ID , Blog .PERMISSION_PUBLISH ,
1008
+ (User ) getUser ( ) );
1000
1009
1001
1010
model .put ( MARK_LIST_IMAGE_TYPE , DocContentHome .getListContentType ( ) );
1002
1011
model .put ( MARK_PERMISSION_CREATE_TAG , bPermissionCreate );
1012
+ model .put ( MARK_PERMISSION_PUBLISH_BLOG , bPermissionToPublish );
1003
1013
model .put ( MARK_BLOG , _blog );
1004
1014
model .put ( MARK_LIST_TAG , getTageList ( ) );
1005
1015
model .put ( MARK_USE_UPLOAD_IMAGE_PLUGIN , Boolean .parseBoolean ( useCropImage ) );
@@ -1057,23 +1067,25 @@ public String doModifyBlog( HttpServletRequest request )
1057
1067
{
1058
1068
return redirect ( request , VIEW_MODIFY_BLOG , PARAMETER_ID_BLOG , _blog .getId ( ) );
1059
1069
}
1060
-
1061
- if ( strAction != null && strAction .equals ( PARAMETER_APPLY ) )
1070
+ if ( strAction != null && strAction .equals ( PARAMETER_UPDATE ) && RBACService .isAuthorized ( Blog .PROPERTY_RESOURCE_TYPE , strId , Blog .PERMISSION_PUBLISH , (User ) getUser ( ) ) )
1062
1071
{
1063
- BlogService .getInstance ( ).updateBlogWithoutVersion ( _blog , _blog .getDocContent ( ) );
1072
+ _blog .setVersion ( latestVersionBlog .getVersion ( ) + 1 );
1073
+ BlogHome .update ( _blog );
1074
+ BlogService .getInstance ( ).updateBlog ( _blog , _blog .getDocContent ( ) );
1064
1075
_blogServiceSession .removeBlogFromSession ( request .getSession ( ), nId );
1065
1076
unLockBlog ( nId );
1066
-
1067
- return redirect ( request , VIEW_MODIFY_BLOG , PARAMETER_ID_BLOG , _blog .getId ( ) );
1068
-
1077
+ addInfo ( INFO_BLOG_UPDATED , getLocale ( ) );
1069
1078
}
1070
1079
else
1071
1080
{
1072
1081
_blog .setVersion ( latestVersionBlog .getVersion ( ) + 1 );
1073
1082
BlogService .getInstance ( ).updateBlog ( _blog , _blog .getDocContent ( ) );
1083
+ _blog = latestVersionBlog ;
1084
+ _blog .setVersion ( latestVersionBlog .getVersion ( ) + 1 );
1085
+ BlogHome .update ( _blog );
1074
1086
_blogServiceSession .removeBlogFromSession ( request .getSession ( ), nId );
1075
1087
unLockBlog ( nId );
1076
- addInfo ( INFO_BLOG_UPDATED , getLocale ( ) );
1088
+ return redirect ( request , VIEW_MODIFY_BLOG , PARAMETER_ID_BLOG , _blog . getId ( ) );
1077
1089
}
1078
1090
}
1079
1091
return redirectView ( request , VIEW_MANAGE_BLOGS );
0 commit comments