Changeset 4595


Ignore:
Timestamp:
Oct 21, 2008, 9:44:33 AM (15 years ago)
Author:
Martin Svensson
Message:

Fixes #1142 Batch importer plug-ins should handle lack of USE permission better.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r4551 r4595  
    6161import net.sf.basedb.core.NumberOutOfRangeException;
    6262import net.sf.basedb.core.Permission;
     63import net.sf.basedb.core.PermissionDeniedException;
    6364import net.sf.basedb.core.Platform;
    6465import net.sf.basedb.core.PlatformVariant;
     
    240241    );
    241242 
     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    );
    242252  public AbstractItemImporter()
    243253  {}
     
    404414        storeValue(job, request, numberFormatErrorParameter);
    405415        storeValue(job, request, numberOutOfRangeErrorParameter);
     416        storeValue(job, request, lackOfUsePermissionOnReferencedItemErrorParameter);
    406417       
    407418        // Save context info
     
    465476  private boolean failIfNotFoundReference;
    466477  private boolean failIfMultipleFoundReferences;
     478  private boolean failIfNoUsePermissionOnReference;
    467479 
    468480  // Status report
     
    518530    this.failIfNotFoundReference = "fail".equals(getErrorOption("referenceNotFoundError"));
    519531    this.failIfMultipleFoundReferences = "fail".equals(getErrorOption("multipleReferencesFoundError"));
     532    this.failIfNoUsePermissionOnReference = "fail".equals(getErrorOption("lackOfUsePermissionOnReferencedItemError"));
    520533    this.cropStrings = "crop".equals(getErrorOption("stringTooLongError"));
    521534
     
    14891502    delegates to {@link IdMethod#prepareQuery(DbControl, ItemQuery)} and
    14901503    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       
    14941505    @param dc A DbControl used for database access
    14951506    @param idMethod The identification method to use
     
    15011512    query = idMethod.prepareQuery(dc, query);
    15021513    query.include(Include.MINE, Include.IN_PROJECT, Include.SHARED, Include.OTHERS);
    1503     query.setItemPermission(Permission.USE);
    15041514    return query;
    15051515  }
     
    15441554        }
    15451555      }
    1546       else if (result.size() > 1)
    1547       {
    1548         // Several items found
    1549         if (failIfMultipleFoundReferences)
    1550         {
    1551           throw new BaseException("Found " + result.size() + " " + itemType + " [" +idMethod + "=" + identifier + "]");
    1552         }
    1553       }
    15541556      else
    15551557      {
    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      }
    15591589    }
    15601590    return item;
     
    17461776      if (!updateMode) parameters.add(itemExistsErrorParameter);
    17471777      parameters.add(multipleItemsFoundErrorParameter);
     1778      parameters.add(lackOfUsePermissionOnReferencedItemErrorParameter);
    17481779      parameters.add(referenceNotFoundErrorParameter);
    17491780      parameters.add(multipleReferencesFoundErrorParameter);
Note: See TracChangeset for help on using the changeset viewer.