Skip to content

Commit 273a580

Browse files
committed
2 lines only
make the creation date a tooltip of the expiration
1 parent df6bd2f commit 273a580

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

core/src/main/java/jenkins/security/ApiTokenProperty.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import edu.umd.cs.findbugs.annotations.NonNull;
2929
import edu.umd.cs.findbugs.annotations.Nullable;
3030
import hudson.Extension;
31+
import hudson.Functions;
3132
import hudson.Util;
3233
import hudson.model.Descriptor.FormException;
3334
import hudson.model.User;
@@ -44,6 +45,7 @@
4445
import java.time.ZoneId;
4546
import java.time.ZonedDateTime;
4647
import java.time.format.DateTimeFormatter;
48+
import java.time.format.FormatStyle;
4749
import java.util.Collection;
4850
import java.util.Collections;
4951
import java.util.Date;
@@ -274,7 +276,8 @@ public TokenInfoAndStats(@NonNull ApiTokenStore.HashedToken token, @NonNull ApiT
274276
if (expirationDate == null) {
275277
this.expirationDate = "never";
276278
} else {
277-
this.expirationDate = expirationDate.toString();
279+
this.expirationDate = expirationDate.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
280+
.withLocale(Functions.getCurrentLocale()));
278281
}
279282

280283
this.useCounter = stats.getUseCounter();
@@ -617,7 +620,8 @@ public HttpResponse doGenerateNewToken(@AncestorInPath User u, @QueryParameter S
617620
TokenUuidAndPlainValue tokenUuidAndPlainValue = p.generateNewToken(tokenName, expirationDate);
618621
String expirationDateString = "never";
619622
if (expirationDate != null) {
620-
expirationDateString = expirationDate.toString();
623+
expirationDateString = expirationDate.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
624+
.withLocale(Functions.getCurrentLocale()));
621625
}
622626

623627
Map<String, String> data = new HashMap<>();
@@ -634,7 +638,7 @@ private LocalDate getExpirationDate(String tokenExpiration, String expirationDur
634638
}
635639
expirationDuration = expirationDuration.trim();
636640

637-
return switch (expirationDuration) {
641+
return switch (expirationDuration) {
638642
case "", "never" -> {
639643
yield null;
640644
}

core/src/main/java/jenkins/security/apitoken/ApiTokenStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private void addLegacyToken(@NonNull Secret legacyToken, boolean migrationFromEx
178178
}
179179

180180
/**
181-
* Create a new token with the given name and expiration and return it id and secret value.
181+
* Create a new token with the given name and expiration and return its id and secret value.
182182
* Result meant to be sent / displayed and then discarded.
183183
*/
184184
public synchronized @NonNull TokenUuidAndPlainValue generateNewToken(@NonNull String name, @Nullable LocalDate expirationDate) {

core/src/main/resources/jenkins/security/ApiTokenProperty/config.jelly

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,9 @@ THE SOFTWARE.
9191
<div class="token-card__title">
9292
<span class="token-name">${token.name}</span>
9393
</div>
94-
<div>
94+
<div class="token-stats">
9595
<span class="api-token-new-expiration" data-never="${%This token does not expire}"
9696
data-expires-on="${%tokenExpiresOn('__DATA__')}"/>
97-
</div>
98-
<div class="token-stats">
99-
<span class="token-creation" tooltip="${%Just Now}">${%Created just now}</span>
10097
<span class="token-last-used">${%TokenNeverUsed}</span>
10198
</div>
10299
</div>
@@ -162,32 +159,29 @@ THE SOFTWARE.
162159
</j:if>
163160
<span class="token-name">${token.name}</span>
164161
</div>
165-
<div>
162+
<j:set var="creationDateFormat" value="${%NoCreationDate}" />
163+
<j:if test="${token.creationDate != null}">
164+
<i:formatDate var="creationDateFormat" value="${token.creationDate}" type="both" dateStyle="medium" timeStyle="medium" />
165+
<!--TODO convert to "Today", "Tomorrow", "4 days ago", "2 weeks ago", etc. -->
166+
</j:if>
167+
<div class="token-stats">
166168
<j:choose>
167169
<j:when test="${token.expired}">
168-
<span class="error">
170+
<span class="error" tooltip="${%tokenCreatedOn(creationDateFormat)}">
169171
${%This token has expired}
170172
</span>
171173
</j:when>
172174
<j:when test="${token.expirationDate == 'never'}">
173-
<span class="warning">
175+
<span class="warning" tooltip="${%tokenCreatedOn(creationDateFormat)}">
174176
${%This token does not expire}
175177
</span>
176178
</j:when>
177179
<j:otherwise>
178-
<span class="${token.aboutToExpire ? 'warning' : ''}">
180+
<span class="${token.aboutToExpire ? 'warning' : ''}" tooltip="${%tokenCreatedOn(creationDateFormat)}">
179181
${%tokenExpiresOn(token.expirationDate)}
180182
</span>
181183
</j:otherwise>
182184
</j:choose>
183-
</div>
184-
<j:set var="creationDateFormat" value="${%NoCreationDate}" />
185-
<j:if test="${token.creationDate != null}">
186-
<i:formatDate var="creationDateFormat" value="${token.creationDate}" type="both" dateStyle="medium" timeStyle="medium" />
187-
<!--TODO convert to "Today", "Tomorrow", "4 days ago", "2 weeks ago", etc. -->
188-
</j:if>
189-
<div class="token-stats">
190-
<span class="token-creation ${oldClazz}" tooltip="${creationDateFormat}">${token.createdDaysAgo()}</span>
191185
<span class="token-last-used">
192186
<j:choose>
193187
<j:when test="${isStatisticsEnabled}">

core/src/main/resources/jenkins/security/ApiTokenProperty/config.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ NoCreationDate=There is no creation date for that token
1919
NoCreationDateValue=Unknown
2020
ConfirmRevokeSingleTitle=Revoke token
2121
tokenExpiresOn=Expires on {0}
22+
tokenCreatedOn=Created on {0}

0 commit comments

Comments
 (0)