Skip to content

Commit 55d26c4

Browse files
TimotheeHrlseboo
authored andcommitted
LUT-27735 : Add a new admin dashboard for blog plugin
1 parent 8355967 commit 55d26c4

File tree

12 files changed

+148
-3
lines changed

12 files changed

+148
-3
lines changed

src/java/fr/paris/lutece/plugins/blog/resources/blog_messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ adminFeature.ManageBlogs.name=Manage blog posts
77
adminFeature.ManageBlogs.description=Create, edit, publish and remove blog posts
88
adminFeature.ManageBlogsTags.name=Blog - Tags management
99
adminFeature.ManageBlogsTags.description=Create, edit, publish and remove blog tags
10+
# Admin dashboard Dashboard keys
11+
adminDashboard.pageTitle=Blog - Advanced configuration
1012

1113
# Business classes keys
1214
# keys for business classes keys : Blog

src/java/fr/paris/lutece/plugins/blog/resources/blog_messages_fr.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ adminFeature.ManageBlogs.name=Blog - Gestion des billets
77
adminFeature.ManageBlogs.description=Cr\u00e9er, \u00e9diter, publier, supprimer des billets du blog
88
adminFeature.ManageBlogsTags.name=Blog - Gestion des tags
99
adminFeature.ManageBlogsTags.description=Gestion des tags pour le Blog
10+
# Admin dashboard Dashboard keys
11+
adminDashboard.pageTitle=Blog - Configuration avanc\u00e9e
1012

1113
# Business classes keys
1214
# keys for business classes keys : Blog
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package fr.paris.lutece.plugins.blog.service;
2+
3+
/**
4+
* Blog parameter service.
5+
*/
6+
public class BlogParameterService
7+
{
8+
private static BlogParameterService _singleton = new BlogParameterService( );
9+
10+
/**
11+
* Get the unique instance of the service
12+
*
13+
* @return The unique instance
14+
*/
15+
public static BlogParameterService getInstance( )
16+
{
17+
return _singleton;
18+
}
19+
20+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package fr.paris.lutece.plugins.blog.web.admindashboard;
2+
3+
import fr.paris.lutece.api.user.User;
4+
import fr.paris.lutece.plugins.blog.business.Blog;
5+
import fr.paris.lutece.portal.business.rbac.RBAC;
6+
import fr.paris.lutece.portal.business.user.AdminUser;
7+
import fr.paris.lutece.portal.service.dashboard.admin.AdminDashboardComponent;
8+
import fr.paris.lutece.portal.service.rbac.RBACService;
9+
import fr.paris.lutece.portal.service.security.SecurityTokenService;
10+
import fr.paris.lutece.portal.service.template.AppTemplateService;
11+
import fr.paris.lutece.portal.service.user.AdminUserResourceIdService;
12+
import fr.paris.lutece.portal.web.dashboard.AdminDashboardJspBean;
13+
import fr.paris.lutece.util.html.HtmlTemplate;
14+
import org.apache.commons.lang3.StringUtils;
15+
16+
import javax.servlet.http.HttpServletRequest;
17+
import java.util.HashMap;
18+
import java.util.Map;
19+
20+
public class BlogAdminDashboardComponent extends AdminDashboardComponent
21+
{
22+
public static final String ANCHOR_ADMIN_DASHBOARDS = "blogAdminDashboard";
23+
private static final String TEMPLATE_ADMIN_DASHBOARD = "admin/plugins/blog/dashboard/blog_adminDashboard.html";
24+
25+
/**
26+
* {@inheritDoc}
27+
*/
28+
@Override
29+
public String getDashboardData( AdminUser user, HttpServletRequest request )
30+
{
31+
if ( !RBACService.isAuthorized( Blog.PROPERTY_RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
32+
AdminUserResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS, (User) user ) )
33+
{
34+
return StringUtils.EMPTY;
35+
}
36+
37+
Map<String, Object> model = new HashMap<>( );
38+
model.put( SecurityTokenService.PARAMETER_TOKEN,
39+
SecurityTokenService.getInstance( ).getToken( request, AdminDashboardJspBean.TEMPLATE_MANAGE_DASHBOARDS ) );
40+
HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_ADMIN_DASHBOARD, user.getLocale( ), model );
41+
42+
return template.getHtml( );
43+
}
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package fr.paris.lutece.plugins.blog.web.admindashboard;
2+
3+
import fr.paris.lutece.portal.business.rbac.RBAC;
4+
import fr.paris.lutece.portal.service.rbac.RBACService;
5+
import fr.paris.lutece.portal.service.security.SecurityTokenService;
6+
import fr.paris.lutece.portal.service.user.AdminUserResourceIdService;
7+
import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
8+
import javax.servlet.http.HttpServletRequest;
9+
import fr.paris.lutece.portal.util.mvc.admin.MVCAdminJspBean;
10+
import fr.paris.lutece.portal.business.user.AdminUser;
11+
import fr.paris.lutece.portal.service.admin.AccessDeniedException;
12+
import fr.paris.lutece.portal.web.dashboard.AdminDashboardJspBean;
13+
14+
/**
15+
* This class provides the user interface to manage general Blog feature in the site admin dashboard ( modify mandatory tag number )
16+
*/
17+
@Controller( controllerJsp = "ManageAdminDashboard.jsp", controllerPath = "jsp/admin/plugins/blog/", right = "BLOG_ADVANCED_CONFIGURATION" )
18+
public class BlogAdminDashboardJspBean extends MVCAdminJspBean
19+
{
20+
private static final long serialVersionUID = 3045411044102177294L;
21+
private static final String UNAUTHORIZED = "Unauthorized";
22+
23+
public String doModifyBlogAdvancedParameters( HttpServletRequest request ) throws AccessDeniedException
24+
{
25+
if ( !SecurityTokenService.getInstance( ).validate( request, AdminDashboardJspBean.TEMPLATE_MANAGE_DASHBOARDS ) )
26+
{
27+
throw new AccessDeniedException( ERROR_INVALID_TOKEN );
28+
}
29+
if ( !RBACService.isAuthorized( AdminUser.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, AdminUserResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS,
30+
getUser( ) ) )
31+
{
32+
throw new AccessDeniedException( UNAUTHORIZED );
33+
}
34+
35+
return getAdminDashboardsUrl( request, BlogAdminDashboardComponent.ANCHOR_ADMIN_DASHBOARDS );
36+
}
37+
}

src/sql/plugins/blog/core/init_core_blog.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ INSERT INTO core_admin_right (id_right,name,level_right,admin_url,description,is
1515
INSERT INTO core_admin_right (id_right,name,level_right,admin_url,description,is_updatable,plugin_name,id_feature_group,icon_url,documentation_url, id_order ) VALUES
1616
('BLOG_TAGS_MANAGEMENT','blog.adminFeature.ManageBlogsTags.name',2,'jsp/admin/plugins/blog/ManageTags.jsp','blog.adminFeature.ManageBlogsTags.description',0,'blog','APPLICATIONS','ti ti-tags',NULL,4);
1717

18-
1918
--
2019
-- Data for table core_user_right
2120
--
2221
DELETE FROM core_user_right WHERE id_right = 'BLOG_MANAGEMENT';
22+
DELETE FROM core_user_right WHERE id_right = 'MANAGE_ADVANCED_PARAMETERS';
2323
INSERT INTO core_user_right (id_right,id_user) VALUES ('BLOG_MANAGEMENT',1);
24+
INSERT INTO core_user_right (id_right,id_user) VALUES ('MANAGE_ADVANCED_PARAMETERS',1);
2425

2526
INSERT INTO core_datastore(entity_key, entity_value) VALUES ('number.documents.to.be.loaded', '10');
2627
INSERT INTO core_datastore(entity_key, entity_value) VALUES ('use_upload_image_plugin', 'false');
@@ -30,6 +31,8 @@ INSERT INTO core_datastore(entity_key, entity_value) VALUES ('blog.duration.lock
3031
-- Set blog resources management rights for admin account
3132
--
3233
INSERT INTO core_admin_role (role_key, role_description) VALUES('blog_resources', 'Blog resources administrator');
33-
INSERT INTO core_admin_role_resource (role_key,resource_type,resource_id,permission) VALUES ('blog_resources','TAG','*','*'),
34+
INSERT INTO core_admin_role_resource (role_key,resource_type,resource_id,permission) VALUES ('blog_resources','TAG','*','*');
3435
INSERT INTO core_admin_role_resource (role_key,resource_type,resource_id,permission) VALUES ('blog_resources','BLOG','*','*');
3536
INSERT INTO core_user_role (role_key, id_user) VALUES('blog_resources', 1);
37+
38+
INSERT INTO core_admin_dashboard(dashboard_name, dashboard_column, dashboard_order) VALUES('blogAdminDashboardComponent', 1, 7);

src/sql/plugins/blog/upgrade/update_db_blog_3.0.2-3.0.3.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ INSERT INTO core_admin_role (role_key, role_description) VALUES('blog_resources'
22
INSERT INTO core_admin_role_resource (role_key,resource_type,resource_id,permission) VALUES ('blog_resources','TAG','*','*'),
33
INSERT INTO core_admin_role_resource (role_key,resource_type,resource_id,permission) VALUES ('blog_resources','BLOG','*','*');
44
INSERT INTO core_user_role (role_key, id_user) VALUES('blog_resources', 1);
5+
6+
INSERT INTO core_user_right (id_right,id_user) VALUES ('MANAGE_ADVANCED_PARAMETERS',1);
7+
INSERT INTO core_admin_dashboard(dashboard_name, dashboard_column, dashboard_order) VALUES('blogAdminDashboardComponent', 1, 7);

webapp/WEB-INF/plugins/blog.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@
9191
<dashboard-feature-right>BLOG_MANAGEMENT</dashboard-feature-right>
9292
</dashboard-component>
9393
</dashboard-components>
94-
94+
<admindashboard-components>
95+
<admindashboard-component>
96+
<dashboard-component-name>blogAdminDashboardComponent</dashboard-component-name>
97+
<dashboard-component-class>fr.paris.lutece.plugins.blog.web.admindashboard.BlogAdminDashboardComponent
98+
</dashboard-component-class>
99+
</admindashboard-component>
100+
</admindashboard-components>
95101
<!-- Portlet parameters -->
96102
<portlets>
97103
<portlet>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<@tform method='post' name='blog_advanced_parameters' action='jsp/admin/plugins/blog/admindashboard/DoModifyAdvancedParameters.jsp' boxed=true>
2+
<@input type='hidden' name='token' value='${token}' />
3+
<@formGroup>
4+
<@button type='submit' buttonIcon='check' title='#i18n{portal.util.labelModify}' color='primary' />
5+
</@formGroup>
6+
</@tform>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<@adminDashboardPanel title='#i18n{blog.adminDashboard.pageTitle}' icon='signal' parentId='technical_settings' childId='blogAdminDashboard' >
2+
<#include "advanced_parameters.html" />
3+
</@adminDashboardPanel>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
<jsp:useBean id="manageAdminDashboard" scope="session" class="fr.paris.lutece.plugins.blog.web.adminDashboard.BlogAdminDashboardJspBean" />
3+
<% String strContent = manageAdminDashboard.processController ( request , response ); %>
4+
5+
<%@ page errorPage="../../ErrorPage.jsp" %>
6+
<jsp:include page="../../AdminHeader.jsp" />
7+
8+
<%= strContent %>
9+
10+
<%@ include file="../../AdminFooter.jsp" %>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<%@ page errorPage="../ErrorPage.jsp" %>
2+
3+
<jsp:useBean id="blogAdminDashboard" scope="session" class="fr.paris.lutece.plugins.blog.web.admindashboard.BlogAdminDashboardJspBean" />
4+
5+
<%
6+
blogAdminDashboard.init( request, "CORE_USERS_MANAGEMENT" ) ;
7+
response.sendRedirect( blogAdminDashboard.doModifyBlogAdvancedParameters( request ) );
8+
%>
9+

0 commit comments

Comments
 (0)