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-73900] Un-inline JS in ModuleLocation/config.jelly and fix validation logic #319

Merged
merged 10 commits into from
Nov 5, 2024

Conversation

shlomomdahan
Copy link
Contributor

@shlomomdahan shlomomdahan commented Oct 14, 2024

JENKINS-73900

This pull request addresses two main improvements for the Subversion plugin:

  • Fixes the form validation logic for the excludedRevprop property, which was previously broken.
  • Improves CSP compatibility by extracting inline JS

Testing done

Original validation logic improvement: Loom Video
With CSP restrictions enabled: Loom Video

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@shlomomdahan shlomomdahan reopened this Oct 14, 2024
@shlomomdahan shlomomdahan marked this pull request as draft October 14, 2024 22:36
Copy link
Contributor

@yaroslavafenkin yaroslavafenkin left a comment

Choose a reason for hiding this comment

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

Let me know if you get stuck or any of the dots do not connect. I could also provide a patch myself if this all is too confusing :P

src/main/resources/hudson/scm/SubversionSCM/config.jelly Outdated Show resolved Hide resolved
src/main/resources/hudson/scm/SubversionSCM/config.jelly Outdated Show resolved Hide resolved
src/main/java/hudson/scm/SubversionSCM.java Outdated Show resolved Hide resolved
src/main/java/hudson/scm/SubversionSCM.java Outdated Show resolved Hide resolved
src/main/resources/hudson/scm/SubversionSCM/config.jelly Outdated Show resolved Hide resolved
src/main/resources/hudson/scm/SubversionSCM/config.jelly Outdated Show resolved Hide resolved
@shlomomdahan shlomomdahan marked this pull request as ready for review October 15, 2024 14:21
Comment on lines +28 to +30
if (revPropField) {
revPropField.dispatchEvent(new Event('change'));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to dispatch the event here? Is that supposed to retrigger the validation for excludedRevprop field when we change either remote or credentialsId? Is that how it worked before your change?

I don't like it personally, I'd prefer to have it triggered only when excludedRevprop loses focus. But disregard my comment if it worked like this before, who am I to judge :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is the way it was "supposed" to work before. Although it wasn't working correctly.

 if (self===document.getElementById('svn.remote.loc')){
                r=findNextFormItem(self,'excludedRevprop');
                r.onchange(r);
            }

I think it makes sense as we should validate the excluded revProp whenever remote or credentials changes as well as when excluded revProp itself changes

Comment on lines +11 to +13
var remoteLocationElement = document.querySelector("input[name='_.remote']");
var credentialsIdElement = document.querySelector("select[name='_.credentialsId'][filldependson='remote']");
var selectedOption = credentialsIdElement.options[credentialsIdElement.selectedIndex].value;
Copy link
Contributor

Choose a reason for hiding this comment

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

I expect this will fall apart if we try to define a second location in the configuration, because you selectors will return arrays of elements. Could you check how it behaves in that case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, disregard "arrays of elements", you're using querySelector, not querySelectorAll. Either way I'm concerned whether this is going to work when we try to define multiple locations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you're saying.

In this case, each time you add a module, the checkUrl and checkCredentials is correctly called for the corresponding module, however, the validation for the excludedRevprop only works on the module that was added first.

We can discuss this on the call this morning

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorted it out on a call. excludeRevProp validation previously has referenced credentialsId and remote URL or the first module that was defined. While this behavior seems wrong it is preserved here.

basil added a commit to basil/acceptance-test-harness that referenced this pull request Oct 25, 2024
basil added a commit to basil/acceptance-test-harness that referenced this pull request Oct 25, 2024
@shlomomdahan shlomomdahan marked this pull request as draft October 31, 2024 14:22
@shlomomdahan shlomomdahan marked this pull request as ready for review October 31, 2024 14:22
@shlomomdahan shlomomdahan reopened this Oct 31, 2024
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Nice work taking this through to completion!

@basil basil merged commit c8837f9 into jenkinsci:master Nov 5, 2024
19 checks passed
@basil basil added the internal label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants