| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.itracker.services.util; |
| 20 |
|
|
| 21 |
|
import java.io.UnsupportedEncodingException; |
| 22 |
|
import java.security.MessageDigest; |
| 23 |
|
import java.security.NoSuchAlgorithmException; |
| 24 |
|
import java.util.ArrayList; |
| 25 |
|
import java.util.Arrays; |
| 26 |
|
import java.util.Collections; |
| 27 |
|
import java.util.HashMap; |
| 28 |
|
import java.util.HashSet; |
| 29 |
|
import java.util.Iterator; |
| 30 |
|
import java.util.List; |
| 31 |
|
import java.util.Locale; |
| 32 |
|
import java.util.Map; |
| 33 |
|
import java.util.Random; |
| 34 |
|
import java.util.Set; |
| 35 |
|
|
| 36 |
|
import org.itracker.core.resources.ITrackerResources; |
| 37 |
|
import org.itracker.model.Issue; |
| 38 |
|
import org.itracker.model.NameValuePair; |
| 39 |
|
import org.itracker.model.Permission; |
| 40 |
|
import org.itracker.model.PermissionType; |
| 41 |
|
import org.itracker.model.Project; |
| 42 |
|
import org.itracker.model.User; |
| 43 |
|
import org.itracker.services.UserService; |
| 44 |
|
import org.itracker.services.exceptions.PasswordException; |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
|
|
|
| 4.2% |
Uncovered Elements: 229 (239) |
Complexity: 64 |
Complexity Density: 0.46 |
|
| 48 |
|
public class UserUtilities implements AuthenticationConstants { |
| 49 |
|
protected static final char[] alphabet = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; |
| 50 |
|
|
| 51 |
|
public static final int STATUS_DELETED = -1; |
| 52 |
|
public static final int STATUS_ACTIVE = 1; |
| 53 |
|
public static final int STATUS_LOCKED = 2; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
public static final int PERMISSION_USER_ADMIN = -1; |
| 59 |
|
|
| 60 |
|
public static final int PERMISSION_PRODUCT_ADMIN = 1; |
| 61 |
|
|
| 62 |
|
public static final int PERMISSION_CREATE = 2; |
| 63 |
|
|
| 64 |
|
public static final int PERMISSION_EDIT = 3; |
| 65 |
|
|
| 66 |
|
public static final int PERMISSION_CLOSE = 4; |
| 67 |
|
|
| 68 |
|
public static final int PERMISSION_ASSIGN_SELF = 5; |
| 69 |
|
|
| 70 |
|
public static final int PERMISSION_ASSIGN_OTHERS = 6; |
| 71 |
|
|
| 72 |
|
public static final int PERMISSION_VIEW_ALL = 7; |
| 73 |
|
|
| 74 |
|
public static final int PERMISSION_VIEW_USERS = 8; |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
public static final int PERMISSION_EDIT_USERS = 9; |
| 78 |
|
|
| 79 |
|
public static final int PERMISSION_UNASSIGN_SELF = 10; |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
public static final int PERMISSION_ASSIGNABLE = 11; |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
public static final int PERMISSION_CREATE_OTHERS = 12; |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
public static final int PERMISSION_EDIT_FULL = 13; |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
private static final Integer[] ALL_PERMISSIONS = new Integer[] { |
| 93 |
|
PERMISSION_PRODUCT_ADMIN, |
| 94 |
|
PERMISSION_CREATE, |
| 95 |
|
PERMISSION_EDIT, |
| 96 |
|
PERMISSION_CLOSE, |
| 97 |
|
PERMISSION_ASSIGN_SELF, |
| 98 |
|
PERMISSION_ASSIGN_OTHERS, |
| 99 |
|
PERMISSION_VIEW_ALL, |
| 100 |
|
PERMISSION_VIEW_USERS, |
| 101 |
|
PERMISSION_EDIT_USERS, |
| 102 |
|
PERMISSION_UNASSIGN_SELF, |
| 103 |
|
PERMISSION_ASSIGNABLE, |
| 104 |
|
PERMISSION_CREATE_OTHERS, |
| 105 |
|
PERMISSION_EDIT_FULL, |
| 106 |
|
|
| 107 |
|
}; |
| 108 |
|
public static final Set<Integer> ALL_PERMISSIONS_SET = Collections.unmodifiableSet(getAllPermissionsSet()); |
| 109 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
1
|
private static final Set<Integer> getAllPermissionsSet() {... |
| 111 |
1
|
return new HashSet<Integer>(Arrays.asList(ALL_PERMISSIONS)); |
| 112 |
|
} |
| 113 |
|
public static final int REGISTRATION_TYPE_ADMIN = 1; |
| 114 |
|
public static final int REGISTRATION_TYPE_SELF = 2; |
| 115 |
|
public static final int REGISTRATION_TYPE_IMPORT = 3; |
| 116 |
|
|
| 117 |
|
public static final int PREF_HIDE_ASSIGNED = 1; |
| 118 |
|
public static final int PREF_HIDE_UNASSIGNED = 2; |
| 119 |
|
public static final int PREF_HIDE_CREATED = 4; |
| 120 |
|
public static final int PREF_HIDE_WATCHED = 8; |
| 121 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 122 |
0
|
public UserUtilities() {... |
| 123 |
|
} |
| 124 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 125 |
0
|
public static String getStatusName(int value) {... |
| 126 |
0
|
return getStatusName(value, ITrackerResources.getLocale()); |
| 127 |
|
} |
| 128 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 129 |
3
|
public static String getStatusName(int value, Locale locale) {... |
| 130 |
3
|
return ITrackerResources.getString(ITrackerResources.KEY_BASE_USER_STATUS + value, locale); |
| 131 |
|
} |
| 132 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 133 |
0
|
public static HashMap<String, String> getStatusNames() {... |
| 134 |
0
|
return getStatusNames(ITrackerResources.getLocale()); |
| 135 |
|
} |
| 136 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 137 |
1
|
public static HashMap<String, String> getStatusNames(Locale locale) {... |
| 138 |
1
|
HashMap<String,String> statuses = new HashMap<String,String>(); |
| 139 |
1
|
statuses.put(Integer.toString(STATUS_DELETED), getStatusName(STATUS_DELETED, locale)); |
| 140 |
1
|
statuses.put(Integer.toString(STATUS_ACTIVE), getStatusName(STATUS_ACTIVE, locale)); |
| 141 |
1
|
statuses.put(Integer.toString(STATUS_LOCKED), getStatusName(STATUS_LOCKED, locale)); |
| 142 |
1
|
return statuses; |
| 143 |
|
} |
| 144 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 145 |
0
|
public static String getPermissionName(int value) {... |
| 146 |
0
|
return getPermissionName(value, ITrackerResources.getLocale()); |
| 147 |
|
} |
| 148 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 149 |
0
|
public static String getPermissionName(int value, Locale locale) {... |
| 150 |
0
|
return ITrackerResources.getString(ITrackerResources.KEY_BASE_PERMISSION + value, locale); |
| 151 |
|
} |
| 152 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 153 |
0
|
public static List<NameValuePair> getPermissionNames() {... |
| 154 |
0
|
return getPermissionNames(ITrackerResources.getLocale()); |
| 155 |
|
} |
| 156 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
|
| 157 |
0
|
public static List<NameValuePair> getPermissionNames(Locale locale) {... |
| 158 |
0
|
List<NameValuePair> permissions = new ArrayList<NameValuePair>(); |
| 159 |
0
|
permissions.add(0,new NameValuePair(getPermissionName(PERMISSION_CREATE, locale), Integer.toString(PERMISSION_CREATE))); |
| 160 |
0
|
permissions.add(1,new NameValuePair(getPermissionName(PERMISSION_CREATE_OTHERS, locale), Integer.toString(PERMISSION_CREATE_OTHERS))); |
| 161 |
0
|
permissions.add(2,new NameValuePair(getPermissionName(PERMISSION_EDIT, locale), Integer.toString(PERMISSION_EDIT))); |
| 162 |
0
|
permissions.add(3,new NameValuePair(getPermissionName(PERMISSION_EDIT_USERS, locale), Integer.toString(PERMISSION_EDIT_USERS))); |
| 163 |
0
|
permissions.add(4,new NameValuePair(getPermissionName(PERMISSION_EDIT_FULL, locale), Integer.toString(PERMISSION_EDIT_FULL))); |
| 164 |
0
|
permissions.add(5,new NameValuePair(getPermissionName(PERMISSION_CLOSE, locale), Integer.toString(PERMISSION_CLOSE))); |
| 165 |
0
|
permissions.add(6,new NameValuePair(getPermissionName(PERMISSION_ASSIGNABLE, locale), Integer.toString(PERMISSION_ASSIGNABLE))); |
| 166 |
0
|
permissions.add(7,new NameValuePair(getPermissionName(PERMISSION_ASSIGN_SELF, locale), Integer.toString(PERMISSION_ASSIGN_SELF))); |
| 167 |
0
|
permissions.add(8,new NameValuePair(getPermissionName(PERMISSION_UNASSIGN_SELF, locale), Integer.toString(PERMISSION_UNASSIGN_SELF))); |
| 168 |
0
|
permissions.add(9,new NameValuePair(getPermissionName(PERMISSION_ASSIGN_OTHERS, locale), Integer.toString(PERMISSION_ASSIGN_OTHERS))); |
| 169 |
0
|
permissions.add(10,new NameValuePair(getPermissionName(PERMISSION_VIEW_ALL, locale), Integer.toString(PERMISSION_VIEW_ALL))); |
| 170 |
0
|
permissions.add(11,new NameValuePair(getPermissionName(PERMISSION_VIEW_USERS, locale), Integer.toString(PERMISSION_VIEW_USERS))); |
| 171 |
0
|
permissions.add(12,new NameValuePair(getPermissionName(PERMISSION_PRODUCT_ADMIN, locale), Integer.toString(PERMISSION_PRODUCT_ADMIN))); |
| 172 |
0
|
return permissions; |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
@return |
| 178 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 179 |
0
|
public static String generatePassword() throws PasswordException {... |
| 180 |
0
|
StringBuffer buf = new StringBuffer(); |
| 181 |
0
|
Random rand = new Random(); |
| 182 |
0
|
for(int i = 0; i < 8; i++) { |
| 183 |
0
|
buf.append((rand.nextInt(2) == 0 ? Character.toUpperCase(alphabet[rand.nextInt(34)]) : alphabet[rand.nextInt(34)])); |
| 184 |
|
} |
| 185 |
0
|
return buf.toString(); |
| 186 |
|
} |
| 187 |
|
|
| 188 |
|
|
| 189 |
|
|
| 190 |
|
@param |
| 191 |
|
@return |
| 192 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 5 |
Complexity Density: 0.5 |
|
| 193 |
0
|
public static String encryptPassword(String password) throws PasswordException {... |
| 194 |
0
|
String hash = null; |
| 195 |
0
|
if(password != null && ! password.equals("")) { |
| 196 |
0
|
try { |
| 197 |
0
|
MessageDigest md = MessageDigest.getInstance("SHA"); |
| 198 |
0
|
md.update(password.getBytes("UTF-8")); |
| 199 |
0
|
byte raw[] = md.digest(); |
| 200 |
|
|
| 201 |
|
|
| 202 |
0
|
hash = String.valueOf(Base64Coder.encode(raw)); |
| 203 |
|
|
| 204 |
|
} catch(NoSuchAlgorithmException nsae) { |
| 205 |
0
|
throw new PasswordException(PasswordException.SYSTEM_ERROR); |
| 206 |
|
} catch(UnsupportedEncodingException uee) { |
| 207 |
0
|
throw new PasswordException(PasswordException.SYSTEM_ERROR); |
| 208 |
|
} |
| 209 |
|
} |
| 210 |
0
|
return hash; |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
@param |
| 216 |
|
@return |
| 217 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 218 |
0
|
public static boolean isSuperUser(Map<Integer, Set<PermissionType>> permissionsMap) {... |
| 219 |
0
|
if(permissionsMap == null) { |
| 220 |
0
|
return false; |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
|
| 224 |
0
|
final Set<PermissionType> permissionTypes = permissionsMap.get(null); |
| 225 |
|
|
| 226 |
0
|
return (permissionTypes != null) && permissionTypes.contains(PermissionType.USER_ADMIN); |
| 227 |
|
} |
| 228 |
|
|
| 229 |
|
|
| 230 |
|
|
| 231 |
|
@param |
| 232 |
|
@param |
| 233 |
|
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
| 234 |
0
|
public static boolean hasPermission(Map<Integer, Set<PermissionType>> permissionsMap, int permissionNeeded) {... |
| 235 |
0
|
if(permissionsMap == null) { |
| 236 |
0
|
return false; |
| 237 |
|
} |
| 238 |
|
|
| 239 |
0
|
if (isSuperUser(permissionsMap)) { |
| 240 |
0
|
return true; |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
|
| 244 |
0
|
Set<Integer> keySet = permissionsMap.keySet(); |
| 245 |
|
|
| 246 |
0
|
for(Iterator<Integer> iterator = keySet.iterator(); iterator.hasNext(); ) { |
| 247 |
0
|
Integer projectId = iterator.next(); |
| 248 |
0
|
if (hasPermission(permissionsMap, projectId, permissionNeeded)) { |
| 249 |
0
|
return true; |
| 250 |
|
} |
| 251 |
|
} |
| 252 |
0
|
return false; |
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
|
| 256 |
|
|
| 257 |
|
@param |
| 258 |
|
@param |
| 259 |
|
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
| 260 |
0
|
public static boolean hasPermission(Map<Integer, Set<PermissionType>> permissionsMap, int[] permissionsNeeded) {... |
| 261 |
0
|
if(permissionsMap == null) { |
| 262 |
0
|
return false; |
| 263 |
|
} |
| 264 |
|
|
| 265 |
0
|
if (isSuperUser(permissionsMap)) { |
| 266 |
0
|
return true; |
| 267 |
|
} |
| 268 |
|
|
| 269 |
0
|
Set<Integer> keySet = permissionsMap.keySet(); |
| 270 |
|
|
| 271 |
0
|
for (Iterator<Integer> iterator = keySet.iterator(); iterator.hasNext(); ) { |
| 272 |
0
|
Integer projectId = iterator.next(); |
| 273 |
|
|
| 274 |
0
|
if (hasPermission(permissionsMap, projectId, permissionsNeeded)) { |
| 275 |
0
|
return true; |
| 276 |
|
} |
| 277 |
|
} |
| 278 |
0
|
return false; |
| 279 |
|
} |
| 280 |
|
|
| 281 |
|
|
| 282 |
|
|
| 283 |
|
@param |
| 284 |
|
@param |
| 285 |
|
@param |
| 286 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
| 287 |
0
|
public static boolean hasPermission(Map<Integer, Set<PermissionType>> permissionsMap, Integer projectId, int permissionNeeded) {... |
| 288 |
0
|
if(permissionsMap == null) { |
| 289 |
0
|
return false; |
| 290 |
|
} |
| 291 |
|
|
| 292 |
0
|
if (isSuperUser(permissionsMap)) { |
| 293 |
0
|
return true; |
| 294 |
|
} |
| 295 |
|
|
| 296 |
0
|
final Set<PermissionType> permissionTypes = permissionsMap.get(projectId); |
| 297 |
|
|
| 298 |
0
|
if ((permissionTypes != null) && permissionTypes.contains(PermissionType.fromCode(permissionNeeded))){ |
| 299 |
0
|
return true; |
| 300 |
|
} else { |
| 301 |
0
|
return false; |
| 302 |
|
} |
| 303 |
|
} |
| 304 |
|
|
| 305 |
|
|
| 306 |
|
|
| 307 |
|
@param |
| 308 |
|
@param |
| 309 |
|
@param |
| 310 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 6 |
Complexity Density: 0.6 |
|
| 311 |
0
|
public static boolean hasPermission(Map<Integer, Set<PermissionType>> permissionsMap, Integer projectId, int[] permissionsNeeded) {... |
| 312 |
0
|
if(permissionsMap == null) { |
| 313 |
0
|
return false; |
| 314 |
|
} |
| 315 |
|
|
| 316 |
0
|
if (isSuperUser(permissionsMap)) { |
| 317 |
0
|
return true; |
| 318 |
|
} |
| 319 |
|
|
| 320 |
0
|
final Set<PermissionType> permissionTypes = permissionsMap.get(projectId); |
| 321 |
|
|
| 322 |
0
|
if (permissionTypes != null) { |
| 323 |
0
|
for(int i = 0; i < permissionsNeeded.length; i++) { |
| 324 |
0
|
if(permissionTypes.contains(PermissionType.fromCode(permissionsNeeded[i]))) { |
| 325 |
0
|
return true; |
| 326 |
|
} |
| 327 |
|
} |
| 328 |
|
} |
| 329 |
0
|
return false; |
| 330 |
|
} |
| 331 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 332 |
0
|
public static String getInitial(String name) {... |
| 333 |
0
|
return (name != null && name.length() > 0 ? name.substring(0,1).toUpperCase() + "." : ""); |
| 334 |
|
} |
| 335 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 336 |
0
|
public static Permission[] createPermissionArray(User user, Project project, int[] permissions) {... |
| 337 |
0
|
Permission[] permissionsArray = new Permission[0]; |
| 338 |
|
|
| 339 |
0
|
List<Permission> permissionsList = new ArrayList<Permission>(); |
| 340 |
|
|
| 341 |
0
|
if (user.isSuperUser()) { |
| 342 |
0
|
permissionsList.add(new Permission(-1, user, (Project) null)); |
| 343 |
|
} |
| 344 |
|
|
| 345 |
0
|
for (int i = 0; i < permissions.length; i++) { |
| 346 |
0
|
permissionsList.add(new Permission(permissions[i], user, project)); |
| 347 |
|
} |
| 348 |
0
|
permissionsArray = new Permission[permissionsList.size()]; |
| 349 |
0
|
permissionsArray = permissionsList.toArray(new Permission[]{}); |
| 350 |
|
|
| 351 |
0
|
return permissionsArray; |
| 352 |
|
} |
| 353 |
|
|
| 354 |
|
|
| 355 |
|
|
| 356 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 357 |
0
|
public static Map<Integer, Set<PermissionType>> mapPermissionTypesByProjectId(... |
| 358 |
|
List<Permission> permissionsList) { |
| 359 |
|
|
| 360 |
0
|
final Map<Integer, Set<PermissionType>> permissionsByProjectId = |
| 361 |
|
new HashMap<Integer, Set<PermissionType>>(); |
| 362 |
|
|
| 363 |
0
|
for (int i = 0; i < permissionsList.size(); i++) { |
| 364 |
0
|
Permission permission = permissionsList.get(i); |
| 365 |
|
|
| 366 |
|
|
| 367 |
0
|
final Integer projectId = (permission.getProject() == null) |
| 368 |
|
? null : permission.getProject().getId(); |
| 369 |
|
|
| 370 |
0
|
Set<PermissionType> projectPermissions = permissionsByProjectId.get(projectId); |
| 371 |
|
|
| 372 |
0
|
if (projectPermissions == null) { |
| 373 |
|
|
| 374 |
0
|
projectPermissions = new HashSet<PermissionType>(); |
| 375 |
0
|
permissionsByProjectId.put(projectId, projectPermissions); |
| 376 |
|
} |
| 377 |
|
|
| 378 |
0
|
PermissionType permissionType = PermissionType.fromCode(permission.getPermissionType()); |
| 379 |
0
|
projectPermissions.add(permissionType); |
| 380 |
|
} |
| 381 |
0
|
return permissionsByProjectId; |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
|
| 385 |
|
|
| 386 |
|
@param |
| 387 |
|
@param |
| 388 |
|
@return |
| 389 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 390 |
0
|
public static boolean hideIndexSection(int section, int sections) {... |
| 391 |
0
|
return ((section & sections) == section); |
| 392 |
|
} |
| 393 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
| 394 |
0
|
public static Integer[] getHiddenIndexSections(int sections) {... |
| 395 |
0
|
List<Integer> sectionsList = new ArrayList<Integer>(); |
| 396 |
0
|
if(hideIndexSection(PREF_HIDE_ASSIGNED, sections)) { |
| 397 |
0
|
sectionsList.add(Integer.valueOf(PREF_HIDE_ASSIGNED)); |
| 398 |
|
} |
| 399 |
0
|
if(hideIndexSection(PREF_HIDE_UNASSIGNED, sections)) { |
| 400 |
0
|
sectionsList.add(Integer.valueOf(PREF_HIDE_UNASSIGNED)); |
| 401 |
|
} |
| 402 |
0
|
if(hideIndexSection(PREF_HIDE_CREATED, sections)) { |
| 403 |
0
|
sectionsList.add(Integer.valueOf(PREF_HIDE_CREATED)); |
| 404 |
|
} |
| 405 |
0
|
if(hideIndexSection(PREF_HIDE_WATCHED, sections)) { |
| 406 |
0
|
sectionsList.add(Integer.valueOf(PREF_HIDE_WATCHED)); |
| 407 |
|
} |
| 408 |
0
|
Integer[] sectionsArray = new Integer[sectionsList.size()]; |
| 409 |
0
|
sectionsList.toArray(sectionsArray); |
| 410 |
|
|
| 411 |
0
|
return sectionsArray; |
| 412 |
|
} |
| 413 |
|
|
| 414 |
|
|
| 415 |
|
|
| 416 |
|
|
| 417 |
|
|
| 418 |
|
@param |
| 419 |
|
@param |
| 420 |
|
@param |
| 421 |
|
@param |
| 422 |
|
@param |
| 423 |
|
@return |
| 424 |
|
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 10 |
Complexity Density: 0.45 |
|
| 425 |
0
|
public static List<NameValuePair> getAssignableIssueOwnersList(Issue issue,... |
| 426 |
|
Project project, User currUser, Locale locale, |
| 427 |
|
UserService userService, |
| 428 |
|
Map<Integer, Set<PermissionType>> userPermissions) { |
| 429 |
|
|
| 430 |
0
|
List<NameValuePair> ownersList = new ArrayList<NameValuePair>(); |
| 431 |
|
|
| 432 |
0
|
if (UserUtilities.hasPermission(userPermissions, project.getId(), |
| 433 |
|
UserUtilities.PERMISSION_ASSIGN_OTHERS)) { |
| 434 |
0
|
if (issue.getOwner() == null) { |
| 435 |
0
|
ownersList.add(new NameValuePair(ITrackerResources.getString( |
| 436 |
|
"itracker.web.generic.unassigned", locale), "-1")); |
| 437 |
|
} else { |
| 438 |
0
|
ownersList.add(new NameValuePair(ITrackerResources.getString( |
| 439 |
|
"itracker.web.generic.unassign", locale), "-1")); |
| 440 |
|
} |
| 441 |
0
|
List<User> possibleOwners = userService.getPossibleOwners(issue, |
| 442 |
|
project.getId(), currUser.getId()); |
| 443 |
0
|
Collections.sort(possibleOwners, User.NAME_COMPARATOR); |
| 444 |
0
|
List<NameValuePair> ownerNames = Convert |
| 445 |
|
.usersToNameValuePairs(possibleOwners); |
| 446 |
0
|
for (int i = 0; i < ownerNames.size(); i++) { |
| 447 |
0
|
ownersList.add(ownerNames.get(i)); |
| 448 |
|
} |
| 449 |
0
|
} else if (UserUtilities.hasPermission(userPermissions, |
| 450 |
|
project.getId(), UserUtilities.PERMISSION_ASSIGN_SELF)) { |
| 451 |
0
|
if (issue.getOwner() != null) { |
| 452 |
0
|
if (IssueUtilities.canUnassignIssue(issue, currUser.getId(), |
| 453 |
|
userPermissions)) { |
| 454 |
0
|
ownersList.add(new NameValuePair(ITrackerResources |
| 455 |
|
.getString("itracker.web.generic.unassign", |
| 456 |
|
locale), "-1")); |
| 457 |
|
} |
| 458 |
0
|
if (!issue.getOwner().getId().equals(currUser.getId())) { |
| 459 |
0
|
ownersList.add(new NameValuePair(issue.getOwner() |
| 460 |
|
.getFirstName() |
| 461 |
|
+ " " + issue.getOwner().getLastName(), issue |
| 462 |
|
.getOwner().getId().toString())); |
| 463 |
0
|
ownersList.add(new NameValuePair(currUser.getFirstName() |
| 464 |
|
+ " " + currUser.getLastName(), currUser.getId() |
| 465 |
|
.toString())); |
| 466 |
|
} else { |
| 467 |
0
|
ownersList.add(new NameValuePair(currUser.getFirstName() |
| 468 |
|
+ " " + currUser.getLastName(), currUser.getId() |
| 469 |
|
.toString())); |
| 470 |
|
} |
| 471 |
|
} |
| 472 |
0
|
} else if (issue.getOwner() != null |
| 473 |
|
&& IssueUtilities.canUnassignIssue(issue, currUser.getId(), |
| 474 |
|
userPermissions)) { |
| 475 |
0
|
ownersList.add(new NameValuePair(ITrackerResources.getString( |
| 476 |
|
"itracker.web.generic.unassign", locale), "-1")); |
| 477 |
0
|
ownersList.add(new NameValuePair(issue.getOwner().getFirstName() |
| 478 |
|
+ " " + issue.getOwner().getLastName(), issue.getOwner() |
| 479 |
|
.getId().toString())); |
| 480 |
|
} |
| 481 |
|
|
| 482 |
0
|
return ownersList; |
| 483 |
|
} |
| 484 |
|
} |