Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-60866][JENKINS-71051][JENKINS-71048] Un-inline 'Build Now' JS #7635

Merged
merged 14 commits into from
Dec 13, 2023

Conversation

daniel-beck
Copy link
Member

@daniel-beck daniel-beck commented Feb 7, 2023

See JENKINS-60866.

Challenged by #5514 (comment). Conflicts with #7633 (but should be straightforward to resolve).

This implements a few different, related changes:

  1. l:task no longer has inline JS unless onclick is defined.
  2. l:task gets support for specifying additional behaviors by making the a element it renders (when it's not a l:confirmationLink) a morph tag, and have its default script check for the presence of data-callback.
  3. The call to l:task from p:configurable is changed to specify data-callback, as well as further attributes needed for this link.

Testing done

Commit tested: a205cc4

  • Clicked "Build with parameters" both in sidepanel and in context menu.
  • Clicked "Build Now" both in sidepanel and in context menu. In recent core there's no tooltip/popup acknowledging the action for "Build Now" from the context menu, due to JENKINS-71880, unrelated to this PR.
  • Removed the data-callback from "Build Now", and repeated the first two tests (still works, just with a different message, the only difference before [JENKINS-49138] Build Now to redirect to new build #7633).
  • Reverted the change in configurable.jelly (so it specifies the now deprecated onclick for the l:task) and repeated the first two tests (still works, displays the custom "scheduled" message).
  • Installed https://plugins.jenkins.io/csp/ and navigated to the /job/whatever page, confirming there's no warning reported to the reporting endpoint.
  • Reverted the change in configurable.jelly (so it specifies the now deprecated onclick for the l:task) and navigated to the /job/whatever page, confirming there is a CSP warning reported to the reporting endpoint.

Proposed changelog entries

  • Developer: Allow replacing onclick attributes containing inline JS on l:task with data-callback.

Proposed upgrade guidelines

N/A

Submitter checklist

  • The Jira issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples).
    • Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • New or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

@mention

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@daniel-beck daniel-beck requested review from jglick and Wadeck February 7, 2023 22:09
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right. (There are a bunch of a different usage modes of l:task so it is tricky to find examples of all of them to test, and HtmlUnit coverage is probably absent.)

@NotMyFault NotMyFault added the developer Changes which impact plugin developers label Feb 8, 2023
@daniel-beck daniel-beck marked this pull request as draft February 13, 2023 21:26
@daniel-beck
Copy link
Member Author

@Wadeck suggested this might be easier with a morph tag, I'll look into that.

@daniel-beck daniel-beck self-assigned this Feb 13, 2023
@jglick
Copy link
Member

jglick commented Feb 14, 2023

You mean to avoid duplication as per #7635 (comment) while still avoiding JS for parameterized builds? Sure, as in

<d:taglib uri="local">
<d:tag name="iconSizeLink">
<j:choose>
<j:when test="${sz==iconSize}">
<li class="jenkins-icon-size__items-item" tooltip="${title}">
${title.charAt(0)}<span class="jenkins-visually-hidden">${title.substring(1)}</span>
</li>
</j:when>
<j:otherwise>
<li>
<a class="jenkins-button jenkins-button--tertiary" href="${rootURL}/iconSize?${sz}" tooltip="${title}">
${title.charAt(0)}<span class="jenkins-visually-hidden">${title.substring(1)}</span>
</a>
</li>
</j:otherwise>
</j:choose>
</d:tag>
</d:taglib>
<div class="jenkins-icon-size__items jenkins-buttons-row" xmlns:local="local">
<span>${%Icon}:</span>
<ol>
<local:iconSizeLink title="${%S}" sz="16x16" />
<local:iconSizeLink title="${%M}" sz="24x24" />
<local:iconSizeLink title="${%L}" sz="32x32" />
for example.

@daniel-beck
Copy link
Member Author

You mean to avoid duplication as per #7635 (comment) while still avoiding JS for parameterized builds?

No, as an alternative to callbackElementId. If the a inside the l:task is morph tag based, it could receive all data-whatever attributes added to the l:task.

@github-actions github-actions bot added the unresolved-merge-conflict There is a merge conflict with the target branch. label Mar 17, 2023
@github-actions github-actions bot removed the unresolved-merge-conflict There is a merge conflict with the target branch. label Aug 8, 2023
@daniel-beck daniel-beck force-pushed the un-inline-build-now branch from 6f218aa to 524c4bb Compare August 8, 2023 11:17
@daniel-beck

This comment was marked as outdated.

@daniel-beck daniel-beck changed the title [JENKINS-60866] Un-inline 'Build Now' JS [JENKINS-71051] Un-inline 'Build Now' JS Aug 11, 2023
@daniel-beck daniel-beck changed the title [JENKINS-71051] Un-inline 'Build Now' JS [JENKINS-60866][JENKINS-71051] Un-inline 'Build Now' JS Aug 11, 2023
@daniel-beck daniel-beck changed the title [JENKINS-60866][JENKINS-71051] Un-inline 'Build Now' JS [JENKINS-60866][JENKINS-71051][JENKINS-71048] Un-inline 'Build Now' JS Aug 11, 2023
@jenkinsci jenkinsci deleted a comment from github-actions bot Aug 21, 2023
@daniel-beck daniel-beck marked this pull request as ready for review August 23, 2023 12:53
@daniel-beck daniel-beck removed their assignment Aug 23, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 9, 2023

Please take a moment and address the merge conflicts of your pull request. Thanks!

@github-actions github-actions bot added the unresolved-merge-conflict There is a merge conflict with the target branch. label Sep 9, 2023
@github-actions github-actions bot removed the unresolved-merge-conflict There is a merge conflict with the target branch. label Sep 18, 2023
NotMyFault
NotMyFault previously approved these changes Sep 18, 2023
}
</script>
<st:adjunct includes="lib.hudson.project.configurable.configurable"/>
<l:task href="${url}/build?delay=0sec" icon="icon-clock icon-md" permission="${it.BUILD}" post="${!it.parameterized}" data-callback="lib_hudson_project_configurable_build_now_callback" data-build-success="${%Build scheduled}" data-parameterized="${it.parameterized}" title="${it.buildNowText}"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only purpose of the callback seems to be to change the message from Done to Build scheduled.
So if we generalize the success message for the post we don't need the callback and the js here.
But I like the idea with the callback

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we generalize the success message for the post we don't need the callback and the js here.

I didn't want to remove functionality unless it really was necessary or required crazy workarounds. The solution here seems generally sensible and supportable.

Doing it this way also provides an additional nontrivial example that can help plugin developers adapt their own code.

@daniel-beck
Copy link
Member Author

/label ready-for-merge

This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback.

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer Changes which impact plugin developers ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants