Skip to content

Commit 95a3489

Browse files
committed
feat: improve boolean reability
1 parent 4259bc0 commit 95a3489

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/main/java/org/jenkinsci/plugins/scriptsecurity/scripts/ScriptApproval.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -595,28 +595,32 @@ boolean isEmpty() {
595595
* @param language the language in which it is written
596596
* @param context any additional information about how where or by whom this is being configured
597597
* @param approveIfAdmin indicates whether script should be approved if current user has admin permissions
598-
* @param ignoreAdmin indicates whether auto approval should be ignored, regardless of any configurations.
598+
* @param ignoreAdmin indicates whether an admin's ability to approve a script without visiting the script approval site should be ignored, regardless of any configurations.
599599
* @return {@code script}, for convenience
600600
*/
601601
public synchronized String configuring(@NonNull String script, @NonNull Language language, @NonNull ApprovalContext context, boolean approveIfAdmin, boolean ignoreAdmin) {
602602
final ConversionCheckResult result = checkAndConvertApprovedScript(script, language);
603-
if (!result.approved) {
604-
if (!Jenkins.get().isUseSecurity() ||
605-
(ALLOW_ADMIN_APPROVAL_ENABLED &&
606-
((Jenkins.getAuthentication2() != ACL.SYSTEM2 && Jenkins.get().hasPermission(Jenkins.ADMINISTER))
607-
&& (ADMIN_AUTO_APPROVAL_ENABLED || approveIfAdmin) && !ignoreAdmin))) {
608-
approvedScriptHashes.add(result.newHash);
609-
//Pending scripts are not stored with a precalculated hash, so no need to remove any old hashes
610-
removePendingScript(result.newHash);
611-
} else {
612-
String key = context.getKey();
613-
if (key != null) {
614-
pendingScripts.removeIf(pendingScript -> key.equals(pendingScript.getContext().getKey()));
615-
}
616-
pendingScripts.add(new PendingScript(script, language, context));
603+
if (result.approved) {
604+
return script;
605+
}
606+
// Security is disabled globally.
607+
boolean securityIsDisabled = !Jenkins.get().isUseSecurity();
608+
// Has to be an actual user and the user must be admin. System-triggered jobs should not auto-approve. (I guess that is the reasonf or this boolean?)
609+
boolean isAdminUser = Jenkins.getAuthentication2() != ACL.SYSTEM2 && Jenkins.get().hasPermission(Jenkins.ADMINISTER);
610+
boolean implicitAdminApproval = ADMIN_AUTO_APPROVAL_ENABLED || approveIfAdmin;
611+
if (securityIsDisabled ||
612+
(ALLOW_ADMIN_APPROVAL_ENABLED && isAdminUser && implicitAdminApproval && !ignoreAdmin)) {
613+
approvedScriptHashes.add(result.newHash);
614+
//Pending scripts are not stored with a precalculated hash, so no need to remove any old hashes
615+
removePendingScript(result.newHash);
616+
} else {
617+
String key = context.getKey();
618+
if (key != null) {
619+
pendingScripts.removeIf(pendingScript -> key.equals(pendingScript.getContext().getKey()));
617620
}
618-
save();
621+
pendingScripts.add(new PendingScript(script, language, context));
619622
}
623+
save();
620624
return script;
621625
}
622626

0 commit comments

Comments
 (0)