@Override
 public List<? extends ItemGroup<?>> validDestinations(Item item) {
   List<DirectlyModifiableTopLevelItemGroup> result =
       new ArrayList<DirectlyModifiableTopLevelItemGroup>();
   Jenkins instance = Jenkins.getActiveInstance();
   if (permitted(item, instance)) {
     result.add(instance);
   }
   ITEM:
   for (Item g : instance.getAllItems()) {
     if (g instanceof DirectlyModifiableTopLevelItemGroup) {
       DirectlyModifiableTopLevelItemGroup itemGroup = (DirectlyModifiableTopLevelItemGroup) g;
       if (!permitted(item, itemGroup)) {
         continue;
       }
       ItemGroup<?> p = itemGroup;
       while (p instanceof Item) {
         Item i = (Item) p;
         if (i == item) {
           // Cannot move a folder into itself or a descendant.
           continue ITEM;
         }
         p = i.getParent();
       }
       result.add(itemGroup);
     }
   }
   return result;
 }
 public HandlingMode applicability(Item item) {
   if (item instanceof TopLevelItem
       && item instanceof AbstractItem
       && item.getParent() instanceof DirectlyModifiableTopLevelItemGroup) {
     return HandlingMode.HANDLE;
   } else {
     return HandlingMode.SKIP;
   }
 }
示例#3
0
    /**
     * Returns true if {@link BuildPtr} points to the given job or one of its subordinates.
     *
     * <p>This is useful to check if an artifact in MavenModule belongs to MavenModuleSet.
     */
    public boolean belongsTo(Job job) {
      Item p = Jenkins.getInstance().getItemByFullName(name);
      while (p != null) {
        if (p == job) return true;

        // go up the chain while we
        ItemGroup<? extends Item> parent = p.getParent();
        if (!(parent instanceof Item)) {
          return false;
        }

        p = (Item) parent;
      }

      return false;
    }
 @Override
 public HttpResponse handle(
     Item item,
     ItemGroup<?> destination,
     AtomicReference<Item> newItem,
     List<? extends RelocationHandler> chain)
     throws IOException, InterruptedException {
   if (!(destination instanceof DirectlyModifiableTopLevelItemGroup)) {
     return chain.isEmpty()
         ? null
         : chain.get(0).handle(item, destination, newItem, chain.subList(1, chain.size()));
   }
   Item result = doMove(item, (DirectlyModifiableTopLevelItemGroup) destination);
   newItem.set(result);
   // AbstractItem.getUrl does weird magic here which winds up making it redirect to the old
   // location, so inline the correct part of this method.
   return HttpResponses.redirectViaContextPath(result.getParent().getUrl() + result.getShortUrl());
 }
  @Override
  public OwnershipInfo getOwnershipInfo(AbstractFolder<?> item) {
    if (item == null) { // Handle renames, etc.
      return OwnershipInfo.DISABLED_INFO;
    }

    // Retrieve Ownership from the Folder property
    FolderOwnershipProperty prop = getOwnerProperty(item);
    if (prop != null) {
      OwnershipDescription d = prop.getOwnership();
      if (d.isOwnershipEnabled()) {
        return new OwnershipInfo(prop.getOwnership(), new FolderOwnershipDescriptionSource(item));
      }
    }

    // We go to upper items in order to get the ownership description
    if (!OwnershipPluginConfiguration.get()
        .getInheritanceOptions()
        .isBlockInheritanceFromItemGroups()) {
      ItemGroup parent = item.getParent();
      AbstractOwnershipHelper<ItemGroup> located = OwnershipHelperLocator.locate(parent);
      while (located != null) {
        OwnershipInfo fromParent = located.getOwnershipInfo(parent);
        if (fromParent.getDescription().isOwnershipEnabled()) {
          return fromParent;
        }
        if (parent instanceof Item) {
          Item parentItem = (Item) parent;
          parent = parentItem.getParent();
          located = OwnershipHelperLocator.locate(parent);
        } else {
          located = null;
        }
      }
    }

    return OwnershipInfo.DISABLED_INFO;
  }
示例#6
0
  /** Computes the relative path from the current page to the given item. */
  public static String getRelativeLinkTo(Item p) {
    Map<Object, String> ancestors = new HashMap<Object, String>();
    View view = null;

    StaplerRequest request = Stapler.getCurrentRequest();
    for (Ancestor a : request.getAncestors()) {
      ancestors.put(a.getObject(), a.getRelativePath());
      if (a.getObject() instanceof View) view = (View) a.getObject();
    }

    String path = ancestors.get(p);
    if (path != null) return path;

    Item i = p;
    String url = "";
    while (true) {
      ItemGroup ig = i.getParent();
      url = i.getShortUrl() + url;

      if (ig == Hudson.getInstance()) {
        assert i instanceof TopLevelItem;
        if (view != null && view.contains((TopLevelItem) i)) {
          // if p and the current page belongs to the same view, then return a relative path
          return ancestors.get(view) + '/' + url;
        } else {
          // otherwise return a path from the root Hudson
          return request.getContextPath() + '/' + p.getUrl();
        }
      }

      path = ancestors.get(ig);
      if (path != null) return path + '/' + url;

      assert ig instanceof Item; // if not, ig must have been the Hudson instance
      i = (Item) ig;
    }
  }
 private boolean permitted(Item item, DirectlyModifiableTopLevelItemGroup itemGroup) {
   return itemGroup == item.getParent()
       || itemGroup.canAdd((TopLevelItem) item)
           && ((AccessControlled) itemGroup).hasPermission(Job.CREATE);
 }
示例#8
0
 public String getRelativeNameFrom(Item item) {
     return getRelativeNameFrom(item.getParent());
 }