IntelliJ/Java: Duplicate declaration
ApiTokenProperty.checkPermission
@@ -209,7 +209,11 @@ public class ApiTokenProperty extends UserProperty {
*/
private boolean hasPermissionToSeeToken() {
// Administrators can do whatever they want
- if (SHOW_LEGACY_TOKEN_TO_ADMINS && Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
+ return checkPermission(SHOW_LEGACY_TOKEN_TO_ADMINS, user);
+ }
+
+ private static boolean checkPermission(boolean showLegacyTokenToAdmins, User user) {
+ if (showLegacyTokenToAdmins && Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return true;
}
@@ -416,22 +420,7 @@ public class ApiTokenProperty extends UserProperty {
// for Jelly view
@Restricted(NoExternalUse.class)
public boolean hasCurrentUserRightToGenerateNewToken(User propertyOwner){
- if (ADMIN_CAN_GENERATE_NEW_TOKENS && Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
- return true;
- }
-
- User currentUser = User.current();
- if (currentUser == null) {
- // Anonymous
- return false;
- }
-
- if (Jenkins.getAuthentication() == ACL.SYSTEM) {
- // SYSTEM user is always eligible to see tokens
- return true;
- }
-
- return User.idStrategy().equals(propertyOwner.getId(), currentUser.getId());
+ return checkPermission(ADMIN_CAN_GENERATE_NEW_TOKENS, propertyOwner);
}
/**
