Skip to content

Commit

Permalink
JENKINS-70417: Add option to display email address near user full nam…
Browse files Browse the repository at this point in the history
…en for in drop … (#200)

* Add option to display email address near user full namen for in drop down list

* Change naming, and add help file referenced

Co-authored-by: Stefan Sedelmaier <stefan.sedelmaier@softline.at>
Co-authored-by: Greybird <arnaud.dev@gmail.com>
  • Loading branch information
3 people authored Jan 22, 2023
1 parent eeaa6c5 commit 3629356
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/main/java/hudson/plugins/claim/ClaimConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public ClaimConfig() {
*/
private boolean sortUsersByFullName;

/**
* Display email address for assignees when claiming.
*/
private boolean emailDisplayedForAssigneesList;

/**
* Groovy script to be run when a claim is changed.
*/
Expand Down Expand Up @@ -77,6 +82,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
stickyByDefault = formData.getBoolean("stickyByDefault");
propagateToFollowingBuildsByDefault = formData.getBoolean("propagateToFollowingBuildsByDefault");
sortUsersByFullName = formData.getBoolean("sortUsersByFullName");
emailDisplayedForAssigneesList = formData.getBoolean("emailDisplayedForAssigneesList");
setGroovyTrigger(req.bindJSON(SecureGroovyScript.class, formData.getJSONObject("groovyTrigger")));
save();
return super.configure(req, formData);
Expand Down Expand Up @@ -171,6 +177,24 @@ public void setSortUsersByFullName(boolean sortUsersByFullName) {
this.sortUsersByFullName = sortUsersByFullName;
}

/**
* Returns true if the email should be displayed in the assignee list when claiming.
*
* @return true to display email address, else false.
*/
public boolean isEmailDisplayedForAssigneesList() {
return emailDisplayedForAssigneesList;
}

/**
* Sets the email display option for assignees list when claiming.
*
* @param emailDisplayedForAssigneesList true to display email address, else false.
*/
public void setEmailDisplayedForAssigneesList(boolean emailDisplayedForAssigneesList) {
this.emailDisplayedForAssigneesList = emailDisplayedForAssigneesList;
}

@NonNull
public SecureGroovyScript getGroovyTrigger() {
return groovyTrigger;
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/hudson/plugins/claim/DescribableTestAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import hudson.Extension;
import hudson.model.*;
import hudson.tasks.Mailer;
import hudson.tasks.junit.TestAction;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -40,7 +41,7 @@ public ListBoxModel doFillAssigneeItems() {
currentUser = User.get(currentUserId, false, Collections.emptyMap());
}
if (currentUser != null) {
items.add(currentUser.getDisplayName(), currentUser.getId());
items.add(getUserDisplayName(currentUser), currentUser.getId());
}
Collection<User> c = User.getAll();
if (currentUser != null) {
Expand All @@ -50,12 +51,23 @@ public ListBoxModel doFillAssigneeItems() {
List<User> l = new ArrayList<>(c);
l.sort(getComparator());
for (User u : l) {
items.add(u.getDisplayName(), u.getId());
items.add(getUserDisplayName(u), u.getId());
}

return items;
}

private static String getUserDisplayName(User user) {
StringBuilder sb = new StringBuilder(user.getDisplayName());
if(ClaimConfig.get().isEmailDisplayedForAssigneesList()) {
Mailer.UserProperty mailProperty = user.getProperty(Mailer.UserProperty.class);
if (mailProperty != null && mailProperty.getEmailAddress() != null) {
sb.append(String.format(" (%s)", mailProperty.getEmailAddress()));
}
}
return sb.toString();
}

public ListBoxModel doFillErrorsItems(@AncestorInPath Run run) throws Exception {

ListBoxModel items = new ListBoxModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
help="/plugin/claim/help-sortUsersByFullName.html">
<f:checkbox/>
</f:entry>

<f:entry title="${%DisplayEmailForAssigneesList}" field="emailDisplayedForAssigneesList"
help="/plugin/claim/help-emailDisplayedForAssigneesList.html">
<f:checkbox/>
</f:entry>
<f:property field="groovyTrigger"/>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ SendEmailsForStickyFailures=Send emails when sticky build/test fails again
StickyByDefault=Make claim sticky by default when claiming
PropagateToFollowingBuildsByDefault=Make claim propagate to following failed builds by default
SortUsersByFullName=Sort the users by their name rather than they ids when listing them
DisplayEmailForAssigneesList=Display email address of users when listing assignees
GroovyScript=The Groovy script to run when claims are changed
3 changes: 3 additions & 0 deletions src/main/webapp/help-emailDisplayedForAssigneesList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
If selected, when claiming, the email address will be shown in the list of assignees after their name.
</div>

0 comments on commit 3629356

Please sign in to comment.