Skip to content

Commit

Permalink
[JENKINS-74832] disable copybutton in insecure context
Browse files Browse the repository at this point in the history
Copying to clipboard only works in a secure context (https). So instead
of only showing that it doesn't work after pressing the button, the
button is now disabled and a corresponding tooltip is shown.
  • Loading branch information
mawinter69 committed Jan 9, 2025
1 parent a49c83c commit aad71f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
10 changes: 6 additions & 4 deletions core/src/main/resources/lib/layout/copyButton.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ THE SOFTWARE.
</st:documentation>

<!-- 'copy-button' class is for backwards compatability -->
<button class="copy-button jenkins-button ${attrs.iconOnly == 'true' ? 'jenkins-button--tertiary' : ''} jenkins-copy-button ${attrs.clazz}"
<span data-message-insecure="${%Copying to clipboard requires a secure context.}">
<button class="copy-button jenkins-button ${attrs.iconOnly == 'true' ? 'jenkins-button--tertiary' : ''} jenkins-copy-button ${attrs.clazz}"
text="${attrs.text}"
ref="${attrs.ref}"
message="${attrs.message ?: '%Copied'}"
tooltip="${attrs.label != null ? null : attrs.tooltip ?: '%Copy'}"
type="button">
<span class="jenkins-copy-button__icon" />
${attrs.label}
</button>
<span class="jenkins-copy-button__icon" />
${attrs.label}
</button>
</span>

<st:adjunct includes="lib.layout.copyButton.copyButton"/>
</j:jelly>
18 changes: 9 additions & 9 deletions core/src/main/resources/lib/layout/copyButton/copyButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Behaviour.specify(
"copyButton",
0,
function (copyButton) {
copyButton.addEventListener("click", () => {
if (isSecureContext) {
if (isSecureContext) {
copyButton.addEventListener("click", () => {
var text = copyButton.getAttribute("text");
if (copyButton.hasAttribute("ref")) {
var ref = copyButton.getAttribute("ref");
Expand All @@ -27,12 +27,12 @@ Behaviour.specify(
copyButton,
);
});
} else {
hoverNotification(
"Copy is only supported with a secure (HTTPS) connection",
copyButton,
);
}
});
});
} else {
copyButton.disabled = true;
copyButton.removeAttribute("tooltip");
const parent = copyButton.parentElement;
parent.setAttribute("tooltip", parent.dataset.messageInsecure);
}
},
);

0 comments on commit aad71f0

Please sign in to comment.