Commit a8a565e3 authored by oughdi's avatar oughdi
Browse files

move the permissions verification process from ClusterJspBean class to ClusterSerice class

parent d5aaa400
......@@ -54,7 +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;
private HashMap<String, Boolean> permissions;
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
......@@ -537,5 +537,16 @@ public class Site extends AbstractReleaserResource implements RBACResource, Seri
return String.valueOf( _nId );
}
public HashMap<String, Boolean> getPermissions() {
return permissions;
}
public void setPermissions(HashMap<String, Boolean> permissions) {
if ( this.permissions == null) this.permissions = new HashMap<String, Boolean>( );
else this.permissions.clear();
this.permissions.putAll( permissions );
}
}
......@@ -13,7 +13,7 @@ adminFeature.ManageReleaser.description=Mont\u00e9e de version des composants Lu
rbac.site.resourceType=sites
rbac.site.permission.create=Ajouter des sites
rbac.site.permission.view=Visualiser les sites
rbac.site.permission.modify=Modifier les sites
rbac.site.permission.modify=Modifier des sites
rbac.site.permission.delete=Supprimer des sites
# Business classes keys
......
package fr.paris.lutece.plugins.releaser.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import fr.paris.lutece.plugins.releaser.business.Cluster;
......@@ -15,6 +16,13 @@ import fr.paris.lutece.portal.service.rbac.RBACService;
*/
public class ClusterService
{
// Permissions
private static final String PERMISSION_ADD_SITE = "addSitePermission";
private static final String PERMISSION_VIEW_SITE = "viewSitePermission";
private static final String PERMISSION_MODIFY_SITE = "modifySitePermission";
private static final String PERMISSION_DELETE_SITE = "deleteSitePermission";
/**
* Load the liste of sites into each cluster object and returns the list of clusters
*
......@@ -41,15 +49,16 @@ public class ClusterService
*
* @return the list which contains the data of all the cluster objects
*/
public static List<Cluster> getClustersListWithPermissedSites( AdminUser adminUser)
public static List<Cluster> getClustersListWithAuthorizedSites( AdminUser adminUser)
{
List<Cluster> listCluster = ClusterHome.getClustersList( );
List<Cluster> listClusterWithPermissedSites = new ArrayList<Cluster>( );
List<Cluster> listClusterWithAuthorizedSites = new ArrayList<Cluster>( );
HashMap<String, Boolean> sitePermissions = new HashMap<String, Boolean>( );
for ( Cluster cluster : listCluster )
{
Cluster clusterWithPermissedList = cluster;
List<Site> listPermissedSites = new ArrayList<Site>( );
Cluster clusterWithAuthorizedList = cluster;
List<Site> listAuthorizedSites = new ArrayList<Site>( );
List<Site> listSite = SiteHome.findByCluster( cluster.getId( ) );
for ( Site site : listSite )
......@@ -57,20 +66,58 @@ public class ClusterService
if ( RBACService.isAuthorized( Site.RESOURCE_TYPE, site.getResourceId(),
SiteResourceIdService.PERMISSION_VIEW, adminUser ) )
{
listPermissedSites.add( site );
sitePermissions.clear();
// Add site's permissions
sitePermissions.put(PERMISSION_VIEW_SITE, true);
if (RBACService.isAuthorized( Site.RESOURCE_TYPE, site.getResourceId(),
SiteResourceIdService.PERMISSION_ADD, adminUser ))
{
sitePermissions.put(PERMISSION_ADD_SITE, true);
}
else
{
sitePermissions.put(PERMISSION_ADD_SITE, false);
}
if (RBACService.isAuthorized( Site.RESOURCE_TYPE, site.getResourceId(),
SiteResourceIdService.PERMISSION_MODIFY, adminUser ))
{
sitePermissions.put(PERMISSION_MODIFY_SITE, true);
}
else
{
sitePermissions.put(PERMISSION_MODIFY_SITE, false);
}
if (RBACService.isAuthorized( Site.RESOURCE_TYPE, site.getResourceId(),
SiteResourceIdService.PERMISSION_DELETE, adminUser ))
{
sitePermissions.put(PERMISSION_DELETE_SITE, true);
}
else
{
sitePermissions.put(PERMISSION_DELETE_SITE, false);
}
// Add permissions to the site
site.setPermissions( sitePermissions );
// Add the site to list of Authorized sites
listAuthorizedSites.add( site );
}
}
if ( listPermissedSites != null && !listPermissedSites.isEmpty( ) )
if ( listAuthorizedSites != null && !listAuthorizedSites.isEmpty( ) )
{
clusterWithPermissedList.setSites( listPermissedSites );
listClusterWithPermissedSites.add( clusterWithPermissedList );
}
clusterWithAuthorizedList.setSites( listAuthorizedSites );
listClusterWithAuthorizedSites.add( clusterWithAuthorizedList );
}
}
return listClusterWithPermissedSites;
return listClusterWithAuthorizedSites;
}
......
......@@ -158,33 +158,10 @@ public class ClusterJspBean extends ManageSitesJspBean
_cluster = null;
_site = null;
List<Cluster> listClusters = ClusterService.getClustersListWithPermissedSites(AdminUserService.getAdminUser(request));
List<Cluster> listClusters = ClusterService.getClustersListWithAuthorizedSites(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 );
......
<#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
<#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> <#if site.permissions.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 site.permissions.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