Changeset 7294
- Timestamp:
- Feb 17, 2017, 11:15:35 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/resources/menu.properties
r6991 r7294 272 272 impersonate.title Impersonate 273 273 impersonate.tooltip Login as another user without knowing the password 274 myroles.title My roles 275 myroles.tooltip.0 De-activate this role 276 myroles.tooltip.1 Activate this role 274 277 275 278 ## Refresh menu ## -
trunk/src/core/net/sf/basedb/core/Keyring.java
r6444 r7294 141 141 142 142 /** 143 Holds the ID of the roles that are inactive. 144 @since 3.11 145 */ 146 private Set<Integer> inactiveRoles; 147 148 /** 143 149 The active project's ID. 144 150 */ … … 240 246 this.projects = parent.projects; 241 247 this.roles = parent.roles; 248 if (parent.inactiveRoles != null) 249 { 250 this.inactiveRoles = new HashSet<Integer>(parent.inactiveRoles); 251 } 242 252 this.maxProjectPermission = parent.maxProjectPermission; 243 253 this.itemKeys = parent.itemKeys; … … 625 635 for (RoleKeys rk : roleKeys) 626 636 { 637 if (inactiveRoles != null && inactiveRoles.contains(rk.getRoleId())) 638 { 639 continue; // Skip inactive roles 640 } 627 641 int keyId = rk.getKeyId(); 628 642 if ((index >= 0) && (rolePermissions[0][index] == keyId)) … … 778 792 779 793 /** 794 Set a roles as inactive (or active). 795 @return TRUE if the status was changes, FALSE if not 796 @since 3.11 797 */ 798 synchronized boolean setRoleInactive(int roleId, boolean inactive) 799 { 800 // Ignore roles that the user is not a member of 801 if (!roles.contains(roleId)) return false; 802 803 if (inactiveRoles == null) inactiveRoles = new HashSet<Integer>(); 804 805 boolean changed = inactive ? inactiveRoles.add(roleId) : inactiveRoles.remove(roleId); 806 // Force permission reload if this changes the inactive roles 807 reload |= changed; 808 return changed; 809 } 810 811 812 /** 780 813 Returns the permission value for the specified key or 781 814 PERMISSION.DENIED if not found in the array of keys. … … 909 942 } 910 943 944 Set<Integer> getInactiveRoles() 945 { 946 if (getReload()) reload(); 947 return inactiveRoles == null ? Collections.emptySet() : inactiveRoles; 948 } 949 911 950 Set<Integer> getGroups(boolean onlyWithNonHiddenMembers) 912 951 { -
trunk/src/core/net/sf/basedb/core/Role.java
r7016 r7294 398 398 if (filter != null) 399 399 { 400 Set<Integer> roles = sc.get Roles();400 Set<Integer> roles = sc.getAllRoles(); 401 401 if (roles == null || roles.size() == 0) roles = Collections.singleton(0); 402 402 filter.setParameterList("items", roles); -
trunk/src/core/net/sf/basedb/core/SessionControl.java
r7189 r7294 58 58 import java.util.Map; 59 59 import java.util.HashMap; 60 import java.util.HashSet; 60 61 import java.util.WeakHashMap; 61 62 import java.util.Collections; … … 1084 1085 } 1085 1086 1086 1087 1088 1087 /** 1089 1088 Create a new session control for executing a plugin. … … 1296 1295 /** 1297 1296 Get the id of all roles where the logged in user is a member. 1297 For backwards compatibility reasons this method return 1298 {@link #getAllRoles()}. 1299 1298 1300 @return A <code>Set</code> containing role id:s 1299 */ 1301 @deprecated In 3.11, use {@link #getAllRoles()} or {@link #getActiveRoles()} instead 1302 */ 1303 @Deprecated 1300 1304 public Set<Integer> getRoles() 1301 1305 { 1306 return getAllRoles(); 1307 } 1308 1309 /** 1310 Get the id of all roles where the logged in user is a member. 1311 @return A <code>Set</code> containing role id:s, or null 1312 @since 3.11 1313 */ 1314 public Set<Integer> getAllRoles() 1315 { 1302 1316 return loginInfo == null ? null : loginInfo.keyring.getRoles(); 1317 } 1318 1319 /** 1320 Get the id of all active roles where the logged in user is a member. 1321 @return A <code>Set</code> containing role id:s or null 1322 @since 3.11 1323 */ 1324 public Set<Integer> getActiveRoles() 1325 { 1326 if (loginInfo == null) return null; 1327 Set<Integer> roles = new HashSet<Integer>(loginInfo.keyring.getRoles()); 1328 roles.removeAll(loginInfo.keyring.getInactiveRoles()); 1329 return roles; 1330 } 1331 1332 /** 1333 Get the id of all inactive roles where the logged in user is a member. 1334 @return A <code>Set</code> containing role id:s or null 1335 @since 3.11 1336 */ 1337 public Set<Integer> getInactiveRoles() 1338 { 1339 return loginInfo == null ? null : Collections.unmodifiableSet(loginInfo.keyring.getInactiveRoles()); 1340 } 1341 1342 /** 1343 Is the given role inactive or not? Note that 1344 if the user is not a member of the given role 1345 FALSE is returned. 1346 1347 @param roleId The id of the role to check 1348 @return TRUE if the role is inactive, FALSE if not (or if the user 1349 is not a member) 1350 @since 3.11 1351 */ 1352 public boolean isRoleInactive(int roleId) 1353 { 1354 return loginInfo != null && loginInfo.keyring.getInactiveRoles().contains(roleId); 1355 } 1356 1357 /** 1358 Set a role as active or inactive. 1359 1360 @param roleId The id of the role to set 1361 @param inactive TRUE to set the role to inactive, FALSE to set 1362 it to active 1363 @return TRUE if a change was made, FALSE if not (or if the user 1364 is not a member of the role) 1365 @since 3.11 1366 */ 1367 public synchronized boolean setRoleInactive(int roleId, boolean inactive) 1368 { 1369 updateLastAccess(); 1370 boolean changed = false; 1371 if (loginInfo != null) 1372 { 1373 changed = loginInfo.keyring.setRoleInactive(roleId, inactive); 1374 if (changed) allowedClients.clear(); 1375 } 1376 return changed; 1303 1377 } 1304 1378 -
trunk/www/include/menu.jsp
r7158 r7294 53 53 import="net.sf.basedb.core.ItemResultList" 54 54 import="net.sf.basedb.core.Type" 55 import="net.sf.basedb.core.Role" 55 56 import="net.sf.basedb.core.query.Orders" 56 57 import="net.sf.basedb.core.query.Order" … … 1162 1163 final boolean hasImpersonate = 1163 1164 !sc.isImpersonated() && sc.hasSystemPermission(Permission.ACT_AS_ANOTHER_USER); 1165 1166 List<Role> roles = null; 1167 Set<Integer> roleIds = sc.getAllRoles(); 1168 if (roleIds != null && roleIds.size() > 0) 1169 { 1170 ItemQuery<Role> roleQuery = Role.getQuery(); 1171 roleQuery.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("roles"))); 1172 roleQuery.setParameter("roles", roleIds, Type.INT); 1173 roleQuery.order(Orders.asc(Hql.property("name"))); 1174 roles = roleQuery.list(dc); 1175 } 1164 1176 %> 1165 1177 <m:menu … … 1186 1198 tooltip="<%=menu.getString("logout.tooltip")%>" 1187 1199 /> 1200 <% 1201 if (roles != null && roles.size() > 0) 1202 { 1203 %> 1204 <m:menuseparator /> 1205 <m:menuitem 1206 title="<%=menu.getString("myroles.title")%>" 1207 subclass="menusection" 1208 enabled="false" 1209 /> 1210 <m:menuseparator /> 1211 <% 1212 for (Role r : roles) 1213 { 1214 boolean isInactive = sc.isRoleInactive(r.getId()); 1215 %> 1216 <m:menuitem 1217 title="<%=r.getName() %>" 1218 tooltip="<%=menu.getString("myroles.tooltip", isInactive)%>" 1219 icon="<%=isInactive ? "option_unselected.png" : "option_selected.png"%>" 1220 url="<%=root+"my_base/toggle_active_role.jsp?ID="+ID+"&role_id="+r.getId()%>" 1221 data-popup="ActivateRole, 300, 200" 1222 /> 1223 <% 1224 } 1225 } 1226 %> 1188 1227 </m:menu> 1189 1228 <%
Note: See TracChangeset
for help on using the changeset viewer.