1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.releaser.service;
35
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39
40 import fr.paris.lutece.plugins.releaser.business.Cluster;
41 import fr.paris.lutece.plugins.releaser.business.ClusterHome;
42 import fr.paris.lutece.plugins.releaser.business.Site;
43 import fr.paris.lutece.plugins.releaser.business.SiteHome;
44 import fr.paris.lutece.portal.business.user.AdminUser;
45 import fr.paris.lutece.portal.service.rbac.RBACService;
46
47
48
49
50 public class ClusterService
51 {
52
53
54
55
56
57
58 public static List<Cluster> getClustersListWithSites( AdminUser adminUser )
59 {
60 List<Cluster> listCluster = ClusterHome.getClustersList( );
61
62 for ( Cluster cluster : listCluster )
63 {
64 List<Site> listSite = SiteHome.findByCluster( cluster.getId( ) );
65 for ( Site site : listSite )
66 {
67 cluster.getSites( ).add( site );
68 }
69 }
70
71 return listCluster;
72 }
73
74
75
76
77
78
79 public static List<Cluster> getUserClusters( AdminUser adminUser )
80 {
81 List<Cluster> listCluster = ClusterHome.getClustersList( );
82 List<Cluster> listAuthorizedClusters = new ArrayList<Cluster>( );
83
84 for ( Cluster cluster : listCluster )
85 {
86 HashMap<String, Boolean> clusterPermissions = new HashMap<String, Boolean>( );
87 boolean bAuthoriseViewCluster = false;
88
89
90 if ( RBACService.isAuthorized( Cluster.RESOURCE_TYPE, cluster.getResourceId( ), ClusterResourceIdService.PERMISSION_ADD_SITE_TO_CLUSTER,
91 adminUser ) )
92 {
93 clusterPermissions.put( Cluster.PERMISSION_ADD_SITES_TO_CLUSTER, true );
94 bAuthoriseViewCluster = true;
95 }
96 else
97 {
98 clusterPermissions.put( Cluster.PERMISSION_ADD_SITES_TO_CLUSTER, false );
99 }
100
101
102 if ( RBACService.isAuthorized( Cluster.RESOURCE_TYPE, cluster.getResourceId( ), ClusterResourceIdService.PERMISSION_MODIFY, adminUser ) )
103 {
104 clusterPermissions.put( Cluster.PERMISSION_MODIFY_CLUSTER, true );
105 bAuthoriseViewCluster = true;
106 }
107 else
108 {
109 clusterPermissions.put( Cluster.PERMISSION_MODIFY_CLUSTER, false );
110 }
111
112
113 if ( RBACService.isAuthorized( Cluster.RESOURCE_TYPE, cluster.getResourceId( ), ClusterResourceIdService.PERMISSION_DELETE, adminUser ) )
114 {
115 clusterPermissions.put( Cluster.PERMISSION_DELETE_CLUSTER, true );
116 bAuthoriseViewCluster = true;
117 }
118 else
119 {
120 clusterPermissions.put( Cluster.PERMISSION_DELETE_CLUSTER, false );
121 }
122
123
124 cluster.setPermissions( clusterPermissions );
125
126
127 List<Site> listAuthorizedSites = SiteService.getAuthorizedSites( cluster.getId( ), adminUser );
128
129 if ( listAuthorizedSites != null )
130 {
131 cluster.setSites( listAuthorizedSites );
132
133 if ( !listAuthorizedSites.isEmpty( ) )
134 {
135 bAuthoriseViewCluster = true;
136 }
137 }
138
139 if ( bAuthoriseViewCluster )
140 listAuthorizedClusters.add( cluster );
141 }
142
143 return listAuthorizedClusters;
144 }
145
146 public static boolean IsAddClusterAuthorized( AdminUser adminUser )
147 {
148
149 if ( RBACService.isAuthorized( new Cluster( ), ClusterResourceIdService.PERMISSION_ADD, adminUser ) )
150 {
151 return true;
152 }
153
154 return false;
155 }
156
157 public static boolean IsUserAuthorized( AdminUser adminUser, String clusterId, String permission )
158 {
159
160 boolean bAuthorized = false;
161
162 if ( RBACService.isAuthorized( Cluster.RESOURCE_TYPE, clusterId, permission, adminUser ) )
163 {
164 bAuthorized = true;
165 }
166
167 return bAuthorized;
168 }
169 }