Changeset 4595
- Timestamp:
- Oct 21, 2008, 9:44:33 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java
r4551 r4595 61 61 import net.sf.basedb.core.NumberOutOfRangeException; 62 62 import net.sf.basedb.core.Permission; 63 import net.sf.basedb.core.PermissionDeniedException; 63 64 import net.sf.basedb.core.Platform; 64 65 import net.sf.basedb.core.PlatformVariant; … … 240 241 ); 241 242 243 private static final PluginParameter<String> lackOfUsePermissionOnReferencedItemErrorParameter = new PluginParameter<String>( 244 "lackOfUsePermissionOnReferencedItemError", 245 "Lack of use permission on referenced item", 246 "What to do if the plug-in finds a referenced item and has no permission to use it.\n\n"+ 247 "ignore = Do not set/update the reference\n" + 248 "fail = Stop with an error message", 249 new StringParameterType(255, null, false, 1, 0, 0, 250 Arrays.asList( new String[] { "ignore", "fail"} )) 251 ); 242 252 public AbstractItemImporter() 243 253 {} … … 404 414 storeValue(job, request, numberFormatErrorParameter); 405 415 storeValue(job, request, numberOutOfRangeErrorParameter); 416 storeValue(job, request, lackOfUsePermissionOnReferencedItemErrorParameter); 406 417 407 418 // Save context info … … 465 476 private boolean failIfNotFoundReference; 466 477 private boolean failIfMultipleFoundReferences; 478 private boolean failIfNoUsePermissionOnReference; 467 479 468 480 // Status report … … 518 530 this.failIfNotFoundReference = "fail".equals(getErrorOption("referenceNotFoundError")); 519 531 this.failIfMultipleFoundReferences = "fail".equals(getErrorOption("multipleReferencesFoundError")); 532 this.failIfNoUsePermissionOnReference = "fail".equals(getErrorOption("lackOfUsePermissionOnReferencedItemError")); 520 533 this.cropStrings = "crop".equals(getErrorOption("stringTooLongError")); 521 534 … … 1489 1502 delegates to {@link IdMethod#prepareQuery(DbControl, ItemQuery)} and 1490 1503 then adds {@link Include} options: MINE, IN_PROJECT, SHARED and OTHERS. 1491 The query will only search for items that the logged in user has 1492 USE permission for. 1493 1504 1494 1505 @param dc A DbControl used for database access 1495 1506 @param idMethod The identification method to use … … 1501 1512 query = idMethod.prepareQuery(dc, query); 1502 1513 query.include(Include.MINE, Include.IN_PROJECT, Include.SHARED, Include.OTHERS); 1503 query.setItemPermission(Permission.USE);1504 1514 return query; 1505 1515 } … … 1544 1554 } 1545 1555 } 1546 else if (result.size() > 1)1547 {1548 // Several items found1549 if (failIfMultipleFoundReferences)1550 {1551 throw new BaseException("Found " + result.size() + " " + itemType + " [" +idMethod + "=" + identifier + "]");1552 }1553 }1554 1556 else 1555 1557 { 1556 item = result.get(0); 1557 } 1558 itemCache.put(cacheKey, item); 1558 // Pick out items where use-permission is granted 1559 List<T> accessibleItems = new ArrayList<T>(); 1560 for (T t : result) 1561 { 1562 if (t.hasPermission(Permission.USE)) 1563 { 1564 accessibleItems.add(t); 1565 } 1566 } 1567 if (accessibleItems.size() > 1) 1568 { 1569 // Several items found 1570 if (failIfMultipleFoundReferences) 1571 { 1572 throw new BaseException("Found " + accessibleItems.size() + " " + itemType + " [" +idMethod + "=" + identifier + "]"); 1573 } 1574 } 1575 else if (accessibleItems.size() == 0) 1576 { 1577 // No use permission on item 1578 if (failIfNoUsePermissionOnReference) 1579 { 1580 throw new PermissionDeniedException(Permission.USE, itemType+"[" +idMethod + "=" + identifier + "]"); 1581 } 1582 } 1583 else 1584 { 1585 item = accessibleItems.get(0); 1586 } 1587 itemCache.put(cacheKey, item); 1588 } 1559 1589 } 1560 1590 return item; … … 1746 1776 if (!updateMode) parameters.add(itemExistsErrorParameter); 1747 1777 parameters.add(multipleItemsFoundErrorParameter); 1778 parameters.add(lackOfUsePermissionOnReferencedItemErrorParameter); 1748 1779 parameters.add(referenceNotFoundErrorParameter); 1749 1780 parameters.add(multipleReferencesFoundErrorParameter);
Note: See TracChangeset
for help on using the changeset viewer.