Skip to content

Commit

Permalink
Introduce the new UserIdCause constructor, which accepts userId as an…
Browse files Browse the repository at this point in the history
… argument. (#3162)

* Introduce UserIdCause constructor, which accepts userId as an argument.

* [JENKINS-48467] - UserIdCuase: Add issue link in the TODO comment
  • Loading branch information
oleg-nenashev committed Dec 14, 2017
1 parent b7f42b2 commit 14605fe
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions core/src/main/java/hudson/model/Cause.java
Expand Up @@ -402,17 +402,36 @@ public int hashCode() {
*/
public static class UserIdCause extends Cause {

@CheckForNull
private String userId;

/**
* Constructor, which uses the current {@link User}.
*/
public UserIdCause() {
User user = User.current();
this.userId = (user == null) ? null : user.getId();
}

/**
* Constructor.
* @param userId User ID. {@code null} if the user is unknown.
* @since TODO
*/
public UserIdCause(@CheckForNull String userId) {
this.userId = userId;
}

@Exported(visibility = 3)
@CheckForNull
public String getUserId() {
return userId;
}

@Nonnull
private String getUserIdOrUnknown() {
return userId != null ? userId : User.getUnknown().getId();
}

@Exported(visibility = 3)
public String getUserName() {
Expand All @@ -435,8 +454,8 @@ public String getShortDescription() {
@Override
public void print(TaskListener listener) {
listener.getLogger().println(Messages.Cause_UserIdCause_ShortDescription(
// TODO better to use ModelHyperlinkNote.encodeTo(User), or User.getUrl, since it handles URL escaping
ModelHyperlinkNote.encodeTo("/user/"+getUserId(), getUserName())));
// TODO JENKINS-48467 - better to use ModelHyperlinkNote.encodeTo(User), or User.getUrl, since it handles URL escaping
ModelHyperlinkNote.encodeTo("/user/"+getUserIdOrUnknown(), getUserName())));
}

@Override
Expand Down

0 comments on commit 14605fe

Please sign in to comment.