Commit d5aaa400 authored by oughdi's avatar oughdi
Browse files

Add all sites permissions for the RBAC

parent ae125226
......@@ -42,6 +42,7 @@ import fr.paris.lutece.portal.service.rbac.RBACResource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
// TODO: Auto-generated Javadoc
......@@ -53,6 +54,7 @@ public class Site extends AbstractReleaserResource implements RBACResource, Seri
// RBAC management
public static final String RESOURCE_TYPE = "site";
//public static HashMap<String, Boolean> permissions;
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
......
......@@ -5,10 +5,10 @@ plugin.description=Releaser components, sites and clusters
#RBAC Resources
rbac.site.resourceType=site
rbac.site.permission.create=Add sites
rbac.site.permission.view=View sites
rbac.site.permission.create=Add sites
rbac.site.permission.modify=Modify sites
rbac.site.permission.delete=Delete sites
# Admin features keys
......
......@@ -11,10 +11,10 @@ adminFeature.ManageReleaser.description=Mont\u00e9e de version des composants Lu
#RBAC Resources
rbac.site.resourceType=sites
rbac.site.permission.create=Ajouter des sites
rbac.site.permission.view=Visualiser les sites
rbac.site.permission.create=Ajouter des sites
rbac.site.permission.modify=Modifier les sites
rbac.site.permission.delete=Supprimer des sites
# Business classes keys
......
......@@ -7,7 +7,8 @@ import fr.paris.lutece.plugins.releaser.business.Cluster;
import fr.paris.lutece.plugins.releaser.business.ClusterHome;
import fr.paris.lutece.plugins.releaser.business.Site;
import fr.paris.lutece.plugins.releaser.business.SiteHome;
import fr.paris.lutece.portal.business.user.AdminUser;import fr.paris.lutece.portal.service.rbac.RBACService;
import fr.paris.lutece.portal.business.user.AdminUser;
import fr.paris.lutece.portal.service.rbac.RBACService;
/**
* ClusterService.
......@@ -56,14 +57,15 @@ public class ClusterService
if ( RBACService.isAuthorized( Site.RESOURCE_TYPE, site.getResourceId(),
SiteResourceIdService.PERMISSION_VIEW, adminUser ) )
{
listPermissedSites.add( site );
}
listPermissedSites.add( site );
}
}
if ( listPermissedSites != null && !listPermissedSites.isEmpty( ) )
{
clusterWithPermissedList.setSites( listPermissedSites );
listClusterWithPermissedSites.add( clusterWithPermissedList );
listClusterWithPermissedSites.add( clusterWithPermissedList );
}
}
......
......@@ -22,6 +22,7 @@ public final class SiteResourceIdService extends ResourceIdService
private static final String PROPERTY_LABEL_RESOURCE_TYPE = "releaser.rbac.site.resourceType";
private static final String PROPERTY_LABEL_CREATE = "releaser.rbac.site.permission.create";
private static final String PROPERTY_LABEL_VIEW = "releaser.rbac.site.permission.view";
private static final String PROPERTY_LABEL_MODIFY = "releaser.rbac.site.permission.modify";
private static final String PROPERTY_LABEL_DELETE = "releaser.rbac.site.permission.delete";
private static final String PLUGIN_NAME = "releaser";
......@@ -62,6 +63,11 @@ public final class SiteResourceIdService extends ResourceIdService
p.setPermissionTitleKey( PROPERTY_LABEL_VIEW );
rt.registerPermission( p );
p = new Permission( );
p.setPermissionKey( PERMISSION_MODIFY );
p.setPermissionTitleKey( PROPERTY_LABEL_MODIFY );
rt.registerPermission( p );
p = new Permission( );
p.setPermissionKey( PERMISSION_DELETE );
p.setPermissionTitleKey( PROPERTY_LABEL_DELETE );
......
......@@ -40,17 +40,22 @@ import fr.paris.lutece.plugins.releaser.business.RepositoryType;
import fr.paris.lutece.plugins.releaser.business.Site;
import fr.paris.lutece.plugins.releaser.business.SiteHome;
import fr.paris.lutece.plugins.releaser.service.ClusterService;
import fr.paris.lutece.plugins.releaser.service.SiteResourceIdService;
import fr.paris.lutece.plugins.releaser.service.SiteService;
import fr.paris.lutece.plugins.releaser.util.ConstanteUtils;
import fr.paris.lutece.plugins.releaser.util.ReleaserUtils;
import fr.paris.lutece.portal.business.user.AdminUser;
import fr.paris.lutece.portal.service.admin.AdminUserService;
import fr.paris.lutece.portal.service.message.AdminMessage;
import fr.paris.lutece.portal.service.message.AdminMessageService;
import fr.paris.lutece.portal.service.rbac.RBACResource;
import fr.paris.lutece.portal.service.rbac.RBACService;
import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
import fr.paris.lutece.util.url.UrlItem;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
......@@ -138,7 +143,7 @@ public class ClusterJspBean extends ManageSitesJspBean
// Session variable to store working values
private Cluster _cluster;
private Site _site;
private Site _site;
/**
* Build the Manage View
......@@ -153,10 +158,33 @@ public class ClusterJspBean extends ManageSitesJspBean
_cluster = null;
_site = null;
//List<Cluster> listClusters = ClusterHome.getClustersList( );
List<Cluster> listClusters = ClusterService.getClustersListWithPermissedSites(AdminUserService.getAdminUser(request));
Map<String, Object> model = getPaginatedListModel( request, MARK_CLUSTER_LIST, listClusters, JSP_MANAGE_CLUSTERS );
// Add site permissions
model.put("addSitePermission", false);
model.put("modifySitePermission", false);
model.put("deleteSitePermission", false);
if ( !listClusters.isEmpty( ) && !listClusters.get( 0 ).getSites( ).isEmpty( ) )
{
if (RBACService.isAuthorized( listClusters.get( 0 ).getSites( ).get( 0 ), SiteResourceIdService.PERMISSION_ADD, AdminUserService.getAdminUser(request) ))
{
model.put("addSitePermission", true);
}
if (RBACService.isAuthorized( listClusters.get( 0 ).getSites( ).get( 0 ), SiteResourceIdService.PERMISSION_MODIFY, AdminUserService.getAdminUser(request) ))
{
model.put("modifySitePermission", true);
}
if (RBACService.isAuthorized( listClusters.get( 0 ).getSites( ).get( 0 ), SiteResourceIdService.PERMISSION_DELETE, AdminUserService.getAdminUser(request) ))
{
model.put("deleteSitePermission", true);
}
}
model.put( ConstanteUtils.MARK_USER, ReleaserUtils.getReleaserUser( request, getLocale( ) ) );
model.put( MARK_IS_APPLICATION_ACCOUNT, ReleaserUtils.isApplicationAccountEnable( ) );
model.put( ConstanteUtils.MARK_REPO_TYPE_GITHUB, RepositoryType.GITHUB );
......@@ -167,13 +195,12 @@ public class ClusterJspBean extends ManageSitesJspBean
// Load information site after authentication error
int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE_ERROR ) );
model.put( MARK_SITE, SiteHome.findByPrimaryKey( nId ) );
}
return getPage( PROPERTY_PAGE_TITLE_MANAGE_CLUSTERS, TEMPLATE_MANAGE_CLUSTERS, model );
}
/**
/**
* Returns the form to create a cluster
*
* @param request
......@@ -237,7 +264,6 @@ public class ClusterJspBean extends ManageSitesJspBean
// Check constraints
if ( !validateBean( user, VALIDATION_ATTRIBUTES_USER_PREFIX ) )
{
redirectView( request, VIEW_MANAGE_CLUSTERS );
}
......@@ -486,5 +512,4 @@ public class ClusterJspBean extends ManageSitesJspBean
return redirectView( request, VIEW_MANAGE_SITES );
}
}
<#include "releaser_util.html" /> <@tform class='form-inline pull-right' name='manage_cluster' action='jsp/admin/plugins/releaser/ManageClusters.jsp'> <button class="floating-button" name="view_createCluster" type="submit" title="#i18n{releaser.manage_clusters.buttonAdd}"> <i class="fa fa-plus"></i> </button></@tform><#if !is_application_account> <button class="floating-button btn-release-site btn-release-site-bg" title="Releaser un composant" data-toggle="modal" data-target="#modalReleaseComponentGITHUB"> <i class="fa fa-cog" aria-hidden="true"></i> <span class="hidden hidden-xs">Releaser un composant</span> </button><#else> <a class="floating-button btn-release-site btn-release-site-bg" href="jsp/admin/plugins/releaser/ManageComponent.jsp" title="Modifier"> <i class="fa fa-cog" aria-hidden="true"></i> <span class="hidden hidden-xs">Releaser un composant</span> </a></#if><div class="app-wrapper app-cluster"><@messages infos=infos /><@messages errors=errors /><#if errors?? && site??> <#list errors as error> <#if error.message == "AUTHENTICATION_ERROR"> <script> $( function(){ var pathElem="#modalRelease${site.getRepoType().name()!} .release-id"; $(pathElem).val(${site.id}); $("#modalRelease${site.getRepoType().name()!}").modal(); }); </script> </#if> </#list></#if><#list cluster_list as cluster> <a name="cluster${cluster.id}" ></a> <!-- widget-app --> <div class="box box-widget widget-app collapsed-box"> <div class="info-box" > <span class="info-box-icon bg-green"><i class="fa fa-cubes"></i></span> <div class="info-box-content"> <div class="col-xs-12 col-sm-11 col-md-11" > <span class="hidden"></span> <h4>${cluster.name} <span class="info-box-number hidden-xs"><#if cluster.sites?size &gt; 0 >${cluster.sites?size} sites <#else> <span class="text-warning"><i class="fa fa-warning"></i> Aucun site ajout&eacute;</span> </#if></span> <@tform class='form-inline' name='manage_site' action='jsp/admin/plugins/releaser/ManageClusters.jsp'> <input type="hidden" name="id" value="${cluster.id}"> <a class="btn btn-danger btn-xs" href="jsp/admin/plugins/releaser/ManageClusters.jsp?action=confirmRemoveCluster&amp;id=${cluster.id}" title="Supprimer"> <i class="fa fa-trash fa-fw" aria-hidden="true"></i> <span class="sr-only">Supprimer</span> </a> <a class="btn btn-primary btn-xs" href="jsp/admin/plugins/releaser/ManageClusters.jsp?view=modifyCluster&amp;id=${cluster.id}" title="Modifier"> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i> <span class="sr-only">Modifier</span> </a> <button type="submit" class="btn btn-success btn-xs" name="view_createSite" title="#i18n{releaser.manage_sites.buttonAdd}"> <i class="fa fa-plus fa-fw"></i> <span class="sr-only">#i18n{releaser.manage_sites.buttonAdd}</span> </button> </@tform> </h4> </div> <div class="hidden-xs"> <#if cluster.sites?size &gt; 0 > <button type="button" class="btn btn-default collaspe pull-right" data-widget="collapse"> <i class="fa fa-plus"></i> </button> </#if> </div> </div> </div> <div class="box-body"> <h2 class="hidden"> <strong>${cluster.description}</strong> <small>Liste des sites du cluster</small></h2> <ul class="nav nav-stacked clearfix"> <#if cluster.sites?size &gt; 0> <#list cluster.sites as site> <li class="info-padding"> <div class="row"> <div class="col-xs-8 col-sm-8"> <h4 title="repository : ${site.scmUrl}"> ${site.name} <span class="label label-info label-app pull-right hidden-xs" title="Artifact ID : ${site.artifactId}"> <i class="fa fa-cube fa-fw"></i> ${site.artifactId} </span> </h4> <small><span class="hidden-xs">${site.description}</span> [<a href="${site.scmUrl}">${site.scmUrl}</a>] </small> </div> <div class="col-xs-4 col-sm-4"> <#if !is_application_account> <button class="button border-green btn-release-site" data-id-site="${site.id}" data-repo-type="${site.getRepoType().name()!}" title="Releaser" data-toggle="modal" data-target="#modalRelease${site.getRepoType().name()!}"> <i class="fa fa-cog" aria-hidden="true"></i> <span class="hidden-xs"><#if !site.theme>Releaser<#else>Releaser le theme</#if></span> </button> <#else> <a class="button border-blue" href="jsp/admin/plugins/releaser/ManageSiteRelease.jsp?id_site=${site.id}" title="Modifier"> <i class="fa fa-cog" aria-hidden="true"></i> <span class="hidden-xs"><#if !site.theme>Releaser<#else>Releaser le theme</#if></span> </a> </#if> <a class="button border-blue" href="jsp/admin/plugins/releaser/ManageClusters.jsp?view=modifySite&amp;id=${site.id}" title="Modifier"> <i class="fa fa-pencil" aria-hidden="true"></i> <span class="sr-only">Modifier</span> </a> <a class="button border-red" href="jsp/admin/plugins/releaser/ManageClusters.jsp?action=confirmRemoveSite&amp;id=${site.id}" title="Supprimer"> <i class="fa fa-trash" aria-hidden="true"></i> <span class="sr-only">Supprimer</span> </a> </div> </div> </li> </#list> <#else> <p><span class="text-warning"><i class="fa fa-warning"></i> Aucun site ajout&eacute;</span></p> </#if> </ul> </div> </div> </#list></div> <@modalAuth modId="modalReleaseSVN" type=repo_type_svn formActionUrl="jsp/admin/plugins/releaser/ManageClusters.jsp" formSubmitName="action_releaseSite" /><@modalAuth modId="modalReleaseGITLAB" type=repo_type_gitlab formActionUrl="jsp/admin/plugins/releaser/ManageClusters.jsp" formSubmitName="action_releaseSite" /><@modalAuth modId="modalReleaseGITHUB" type=repo_type_github formActionUrl="jsp/admin/plugins/releaser/ManageClusters.jsp" formSubmitName="action_releaseComponent"/> <@modalAuth modId="modalReleaseComponentGITHUB" type=repo_type_github formActionUrl="jsp/admin/plugins/releaser/ManageComponent.jsp" formSubmitName="view_manageComponent" /> <@paginationAdmin paginator=paginator combo=1 /><script>$(function() { $(".btn-release-site").click( function(e){ var pathElem="#modalRelease" +$(this).data('repo-type')+" .release-id"; $(pathElem).val($(this).data('id-site')); }); $(".btn").tooltip(); $(".button").tooltip(); $(".floating-button").tooltip(); });</script>
\ No newline at end of file
<#include "releaser_util.html" /> <@tform class='form-inline pull-right' name='manage_cluster' action='jsp/admin/plugins/releaser/ManageClusters.jsp'> <button class="floating-button" name="view_createCluster" type="submit" title="#i18n{releaser.manage_clusters.buttonAdd}"> <i class="fa fa-plus"></i> </button></@tform><#if !is_application_account> <button class="floating-button btn-release-site btn-release-site-bg" title="Releaser un composant" data-toggle="modal" data-target="#modalReleaseComponentGITHUB"> <i class="fa fa-cog" aria-hidden="true"></i> <span class="hidden hidden-xs">Releaser un composant</span> </button><#else> <a class="floating-button btn-release-site btn-release-site-bg" href="jsp/admin/plugins/releaser/ManageComponent.jsp" title="Modifier"> <i class="fa fa-cog" aria-hidden="true"></i> <span class="hidden hidden-xs">Releaser un composant</span> </a></#if><div class="app-wrapper app-cluster"><@messages infos=infos /><@messages errors=errors /><#if errors?? && site??> <#list errors as error> <#if error.message == "AUTHENTICATION_ERROR"> <script> $( function(){ var pathElem="#modalRelease${site.getRepoType().name()!} .release-id"; $(pathElem).val(${site.id}); $("#modalRelease${site.getRepoType().name()!}").modal(); }); </script> </#if> </#list></#if><#list cluster_list as cluster> <a name="cluster${cluster.id}" ></a> <!-- widget-app --> <div class="box box-widget widget-app collapsed-box"> <div class="info-box" > <span class="info-box-icon bg-green"><i class="fa fa-cubes"></i></span> <div class="info-box-content"> <div class="col-xs-12 col-sm-11 col-md-11" > <span class="hidden"></span> <h4>${cluster.name} <span class="info-box-number hidden-xs"><#if cluster.sites?size &gt; 0 >${cluster.sites?size} sites <#else> <span class="text-warning"><i class="fa fa-warning"></i> Aucun site ajout&eacute;</span> </#if></span> <@tform class='form-inline' name='manage_site' action='jsp/admin/plugins/releaser/ManageClusters.jsp'> <input type="hidden" name="id" value="${cluster.id}"> <a class="btn btn-danger btn-xs" href="jsp/admin/plugins/releaser/ManageClusters.jsp?action=confirmRemoveCluster&amp;id=${cluster.id}" title="Supprimer"> <i class="fa fa-trash fa-fw" aria-hidden="true"></i> <span class="sr-only">Supprimer</span> </a> <a class="btn btn-primary btn-xs" href="jsp/admin/plugins/releaser/ManageClusters.jsp?view=modifyCluster&amp;id=${cluster.id}" title="Modifier"> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i> <span class="sr-only">Modifier</span> </a> <#if addSitePermission> <button type="submit" class="btn btn-success btn-xs" name="view_createSite" title="#i18n{releaser.manage_sites.buttonAdd}"> <i class="fa fa-plus fa-fw"></i> <span class="sr-only">#i18n{releaser.manage_sites.buttonAdd}</span> </button> </#if> </@tform> </h4> </div> <div class="hidden-xs"> <#if cluster.sites?size &gt; 0 > <button type="button" class="btn btn-default collaspe pull-right" data-widget="collapse"> <i class="fa fa-plus"></i> </button> </#if> </div> </div> </div> <div class="box-body"> <h2 class="hidden"> <strong>${cluster.description}</strong> <small>Liste des sites du cluster</small></h2> <ul class="nav nav-stacked clearfix"> <#if cluster.sites?size &gt; 0> <#list cluster.sites as site> <li class="info-padding"> <div class="row"> <div class="col-xs-8 col-sm-8"> <h4 title="repository : ${site.scmUrl}"> ${site.name} <span class="label label-info label-app pull-right hidden-xs" title="Artifact ID : ${site.artifactId}"> <i class="fa fa-cube fa-fw"></i> ${site.artifactId} </span> </h4> <small><span class="hidden-xs">${site.description}</span> [<a href="${site.scmUrl}">${site.scmUrl}</a>] </small> </div> <div class="col-xs-4 col-sm-4"> <#if !is_application_account> <button class="button border-green btn-release-site" data-id-site="${site.id}" data-repo-type="${site.getRepoType().name()!}" title="Releaser" data-toggle="modal" data-target="#modalRelease${site.getRepoType().name()!}"> <i class="fa fa-cog" aria-hidden="true"></i> <span class="hidden-xs"><#if !site.theme>Releaser<#else>Releaser le theme</#if></span> </button> <#else> <a class="button border-blue" href="jsp/admin/plugins/releaser/ManageSiteRelease.jsp?id_site=${site.id}" title="Modifier"> <i class="fa fa-cog" aria-hidden="true"></i> <span class="hidden-xs"><#if !site.theme>Releaser<#else>Releaser le theme</#if></span> </a> </#if> <#if modifySitePermission> <a class="button border-blue" href="jsp/admin/plugins/releaser/ManageClusters.jsp?view=modifySite&amp;id=${site.id}" title="Modifier"> <i class="fa fa-pencil" aria-hidden="true"></i> <span class="sr-only">Modifier</span> </a> </#if> <#if deleteSitePermission> <a class="button border-red" href="jsp/admin/plugins/releaser/ManageClusters.jsp?action=confirmRemoveSite&amp;id=${site.id}" title="Supprimer"> <i class="fa fa-trash" aria-hidden="true"></i> <span class="sr-only">Supprimer</span> </a> </#if> </div> </div> </li> </#list> <#else> <p><span class="text-warning"><i class="fa fa-warning"></i> Aucun site ajout&eacute;</span></p> </#if> </ul> </div> </div> </#list></div> <@modalAuth modId="modalReleaseSVN" type=repo_type_svn formActionUrl="jsp/admin/plugins/releaser/ManageClusters.jsp" formSubmitName="action_releaseSite" /><@modalAuth modId="modalReleaseGITLAB" type=repo_type_gitlab formActionUrl="jsp/admin/plugins/releaser/ManageClusters.jsp" formSubmitName="action_releaseSite" /><@modalAuth modId="modalReleaseGITHUB" type=repo_type_github formActionUrl="jsp/admin/plugins/releaser/ManageClusters.jsp" formSubmitName="action_releaseComponent"/> <@modalAuth modId="modalReleaseComponentGITHUB" type=repo_type_github formActionUrl="jsp/admin/plugins/releaser/ManageComponent.jsp" formSubmitName="view_manageComponent" /> <@paginationAdmin paginator=paginator combo=1 /><script>$(function() { $(".btn-release-site").click( function(e){ var pathElem="#modalRelease" +$(this).data('repo-type')+" .release-id"; $(pathElem).val($(this).data('id-site')); }); $(".btn").tooltip(); $(".button").tooltip(); $(".floating-button").tooltip(); });</script>
\ No newline at end of file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment