Skip to content

Commit

Permalink
JENKINS-7824: Change assign to field to be a drop down list of users
Browse files Browse the repository at this point in the history
from the user DB
  • Loading branch information
ninian committed Jun 22, 2014
1 parent ee8a80d commit 8241d95
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.490</version>
<version>1.542</version>
</parent>

<artifactId>claim</artifactId>
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/hudson/plugins/claim/AbstractClaimBuildAction.java
@@ -1,13 +1,14 @@
package hudson.plugins.claim;

import hudson.model.BuildBadgeAction;
import hudson.model.Hudson;
import hudson.model.Describable;
import hudson.model.ProminentProjectAction;
import hudson.model.Saveable;
import hudson.model.Hudson;
import hudson.model.User;
import hudson.tasks.junit.TestAction;

import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -22,8 +23,8 @@
import org.kohsuke.stapler.export.ExportedBean;

@ExportedBean(defaultVisibility = 2)
public abstract class AbstractClaimBuildAction<T extends Saveable> extends TestAction implements BuildBadgeAction,
ProminentProjectAction {
public abstract class AbstractClaimBuildAction<T extends Saveable> extends DescribableTestAction implements BuildBadgeAction,
ProminentProjectAction, Describable<DescribableTestAction> {

private static final long serialVersionUID = 1L;
private static final Logger LOGGER = Logger.getLogger("claim-plugin");
Expand Down Expand Up @@ -56,7 +57,7 @@ public void doClaim(StaplerRequest req, StaplerResponse resp)
String assignee = req.getSubmittedForm().getString("assignee");
if (!StringUtils.isEmpty(assignee) && !name.equals(assignee)) {
// Validate the specified assignee.
User resolvedAssignee = User.get(assignee, false);
User resolvedAssignee = User.get(assignee, false, Collections.EMPTY_MAP);
if (resolvedAssignee == null) {
LOGGER.log(Level.WARNING, "Invalid username specified for assignment: {0}", assignee);
resp.forwardToPreviousPage(req);
Expand Down Expand Up @@ -85,7 +86,7 @@ public String getClaimedBy() {
}

public String getClaimedByName() {
User user = User.get(claimedBy, false);
User user = User.get(claimedBy, false,Collections.EMPTY_MAP);
if (user != null) {
return user.getDisplayName();
} else {
Expand Down Expand Up @@ -113,7 +114,7 @@ public void claim(String claimedBy, String reason, boolean sticky) {
/**
* Claim a new Run with the same settings as this one.
*/
public void copyTo(AbstractClaimBuildAction other) {
public void copyTo(AbstractClaimBuildAction<T> other) {
other.claim(getClaimedBy(), getReason(), isSticky());
}

Expand Down
54 changes: 54 additions & 0 deletions src/main/java/hudson/plugins/claim/DescribableTestAction.java
@@ -0,0 +1,54 @@
package hudson.plugins.claim;

import hudson.Extension;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.User;
import hudson.tasks.junit.TestAction;
import hudson.util.ListBoxModel;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public abstract class DescribableTestAction extends TestAction implements Describable<DescribableTestAction> {

//private static final Logger LOGGER = Logger.getLogger("claim-plugin");

public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

public Descriptor<DescribableTestAction> getDescriptor() {
return DESCRIPTOR;
}

private static Comparator<User> comparator = new Comparator<User>() {
public int compare(User c1, User c2) {
return c1.getId().compareTo(c2.getId());
}
};

@Extension
public static final class DescriptorImpl extends Descriptor<DescribableTestAction> {
@Override
public String getDisplayName() { return "Assignee"; }

public ListBoxModel doFillAssigneeItems() {
ListBoxModel items = new ListBoxModel();

// sort in case the users are not already in sort order
Collection<User> c = User.getAll();
List<User> l = new ArrayList<User>(c);

Collections.sort(l, comparator);
for (User u : l) {
items.add(u.getDisplayName(), u.getId());
}

return items;

}
}

}
Expand Up @@ -64,10 +64,12 @@
</j:otherwise>
</j:choose>
<div id="claimHoverPopup" style="display:none; width:500px; z-index:1000; border:1px solid #bbb;">
<j:set var="descriptor" value="${it.descriptor}"/>
<f:form method="post" action="claim/claim" name="claim">
<f:entry title="${%Assignee}" help="/plugin/claim/help-assignee.html">
<f:textbox name="assignee" value="${it.assignee}"/>
</f:entry>
<f:entry title="${%Assignee}" field="assignee" help="/plugin/claim/help-assignee.html">
<f:select />
</f:entry>

<f:entry title="${%Reason}" help="/plugin/claim/help-reason.html">
<f:textarea name="reason" value="${it.reason}"/>
</f:entry>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/index.jelly
@@ -1,3 +1,3 @@
<div>
Allow users to claim failed builds.
Allow users to claim or be assigned failed builds.
</div>

0 comments on commit 8241d95

Please sign in to comment.