Skip to content
Permalink
Browse files
[FIXED JENKINS-13023] use validate button to check credenials instead…
… of onChange event which uses findMatchInput.
  • Loading branch information
ssogabe committed Mar 10, 2012
1 parent 0b0c7f6 commit 56ddb987bd16b73f93120dd01936d8e4797667ea
@@ -163,7 +163,7 @@ public String getDisplayName() {

@Override
public boolean configure(final StaplerRequest req, final JSONObject formData) {
sites.replaceBy(req.bindParametersToList(MantisSite.class, "mantis."));
sites.replaceBy(req.bindParametersToList(MantisSite.class, "m."));
save();
return true;
}
@@ -258,37 +258,38 @@ public ListBoxModel doFillCategoryItems(@QueryParameter String siteName, @QueryP
return model;
}

public FormValidation doCheckLogin(final StaplerRequest req, final StaplerResponse res)
public FormValidation doCheckRequired(@QueryParameter String value) {
return FormValidation.validateRequired(value);
}

public FormValidation doCheckLogin(
@QueryParameter("m.url") String url, @QueryParameter("m.version") String version,
@QueryParameter("m.userName") String userName, @QueryParameter("m.password") String password,
@QueryParameter("m.basicUserName") String basicUserName, @QueryParameter("m.basicPassword") String basicPassword)
throws IOException, ServletException {
// only administrator allowed
Hudson.getInstance().checkPermission(Hudson.ADMINISTER);

final String url = Util.fixEmptyAndTrim(req.getParameter("url"));
if (url == null) {
return FormValidation.error(Messages.MantisProjectProperty_MantisUrlMandatory());
}

try {
new URL(url);
} catch (MalformedURLException e) {
return FormValidation.error(Messages.MantisProjectProperty_MalformedURL());
}

final String user = Util.fixEmptyAndTrim(req.getParameter("user"));
final String pass = Util.fixEmptyAndTrim(req.getParameter("pass"));
final String bUser = Util.fixEmptyAndTrim(req.getParameter("buser"));
final String bPass = Util.fixEmptyAndTrim(req.getParameter("bpass"));
final String ver = Util.fixEmptyAndTrim(req.getParameter("version"));

MantisVersion version = MantisVersion.getVersionSafely(ver, MantisVersion.V120);
MantisVersion v = MantisVersion.getVersionSafely(version, MantisVersion.V120);

final MantisSite site = new MantisSite(new URL(url), version.name(), user, pass, bUser, bPass);
final MantisSite site = new MantisSite(new URL(url), v.name(), userName, password, basicUserName, basicPassword);
if (!site.isConnect()) {
return FormValidation.error(Messages.MantisProjectProperty_UnableToLogin());
}

return FormValidation.ok();
return FormValidation.ok(Messages.MantisProjectProperty_Verified());
}

public FormValidation doCheckPattern(@AncestorInPath final AbstractProject<?, ?> project,
@QueryParameter final String value) throws IOException, ServletException {
project.checkPermission(Job.CONFIGURE);
@@ -1,71 +1,51 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:section title="Mantis">
<f:entry title="${%Mantis sites}"
description="${%Mantis sites that projects will want to connect}">

<script type="text/javascript">
function checkUrl(base) {
var url = encodeURIComponent(Form.findMatchingInput(base,'mantis.url').value);
var userName = encodeURIComponent(Form.findMatchingInput(base,'mantis.userName').value);
var password = encodeURIComponent(Form.findMatchingInput(base,'mantis.password').value);
var basicUserName = encodeURIComponent(Form.findMatchingInput(base,'mantis.basicUserName').value);
var basicPassword = encodeURIComponent(Form.findMatchingInput(base,'mantis.basicPassword').value);

var verObj = Form.findMatchingInput(base,'mantis.version');
var version = encodeURIComponent(verObj.options[verObj.selectedIndex].value);

var u = "descriptorByName/MantisProjectProperty/checkLogin?";
u += "url="+url;
u += "&amp;version="+version;
u += "&amp;user="+userName+"&amp;pass="+password;
u += "&amp;buser="+basicUserName+"&amp;bpass="+basicPassword;

return u;
}
</script>

<f:repeatable name="mantissite" var="site" items="${descriptor.sites}">
<f:repeatable name="mantissite" var="site" items="${descriptor.sites}" >

<table width="100%">

<f:entry title="${%URL}" help="/plugin/mantis/help-url.html">
<f:textbox name="mantis.url" value="${site.url}"
checkUrl="checkUrl(this)" />
<f:textbox name="m.url" value="${site.url}"
checkUrl="'descriptorByName/MantisProjectProperty/checkRequired?value=' + encodeURIComponent(this.value)" />
</f:entry>

<f:entry title="${%Version}" description="${%description.version}">
<select class="setting-input" name="mantis.version" style="width: 50%;"
onchange="Form.findMatchingInput(this,'mantis.url').onchange()" >
<select class="setting-input" name="m.version" style="width: 50%;" >
<j:forEach var="v" items="${descriptor.mantisVersions}" >
<f:option selected="${site.version==v}" value="${v}">${v.displayName}</f:option>
</j:forEach>
</select>
</f:entry>

<f:entry title="${%User Name}" help="/plugin/mantis/help-login.html">
<f:textbox name="mantis.userName" value="${site.userName}"
onchange="Form.findMatchingInput(this,'mantis.url').onchange()" />
<f:textbox name="m.userName" value="${site.userName}"
checkUrl="'descriptorByName/MantisProjectProperty/checkRequired?value=' + encodeURIComponent(this.value)" />
</f:entry>

<f:entry title="${%Password}">
<input class="setting-input" name="mantis.password"
type="password" value="${site.password}"
onchange="Form.findMatchingInput(this,'mantis.url').onchange()" />
<f:entry title="${%Password}" >
<f:password class="setting-input"
type="password" name="m.password" value="${site.password}"
checkUrl="'descriptorByName/MantisProjectProperty/checkRequired?value=' + encodeURIComponent(this.value)" />
</f:entry>

<f:advanced>
<f:section title="${%HTTP Basic Authentication}"
help="/plugin/mantis/help-useBasicAuth.html">
<f:entry title="${%User Name}">
<f:textbox name="mantis.basicUserName" value="${site.basicUserName}"
onchange="Form.findMatchingInput(this,'mantis.url').onchange()" />
<f:entry title="${%User Name}" >
<f:textbox name="m.basicUserName" value="${site.basicUserName}" />
</f:entry>
<f:entry title="${%Password}">
<input class="setting-input" name="mantis.basicPassword"
type="password" value="${site.basicPassword}"
onchange="Form.findMatchingInput(this,'mantis.url').onchange()" />
<f:entry title="${%Password}" >
<input class="setting-input"
type="password" name="m.basicPassword" value="${site.basicPassword}" />
</f:entry>
<f:validateButton
title="${%Verify}" progress="${%Verifying...}"
method="checkLogin" with="m.url,m.version,m.userName,m.password,m.basicUserName,m.basicPassword" />
</f:section>
</f:advanced>

@@ -5,4 +5,6 @@ User\ Name = \u30e6\u30fc\u30b6\u30fc\u540d
Password = \u30d1\u30b9\u30ef\u30fc\u30c9
HTTP\ Basic\ Authentication = HTTP Basic\u8a8d\u8a3c
Version = \u30d0\u30fc\u30b8\u30e7\u30f3
description.version=Mantis\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002"1.2.X"\u306f1.2.0\u4ee5\u964d\u3067\u3059\u30021.1.X\u306f\u8fd1\u3044\u5c06\u6765\u30b5\u30dd\u30fc\u30c8\u5916\u306b\u306a\u308a\u307e\u3059\u3002
description.version=Mantis\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002"1.2.X"\u306f1.2.0\u4ee5\u964d\u3067\u3059\u30021.1.X\u306f\u8fd1\u3044\u5c06\u6765\u30b5\u30dd\u30fc\u30c8\u5916\u306b\u306a\u308a\u307e\u3059\u3002
Verify=\u78ba\u8a8d
Verifying...=\u78ba\u8a8d\u4e2d...
@@ -3,6 +3,7 @@ MantisProjectProperty.MalformedURL=Either no legal protocol could be found in a
MantisProjectProperty.UnableToLogin = Unable to login with the user name and password.
MantisProjectProperty.DisplayName = Associated Mantis Website
MantisProjectProperty.InvalidPattern={0} not found. Specify the pattern such as [ISSUE: {0}].
MantisProjectProperty.Verified=Verfied.
MantisIssueUpdater.DisplayName = Updated relevant Mantis issues
Updater.IssueIntegrated = Integrated in {0}:{1} ( See {2} ).
Updater.ChangeSet.Revision=[Revision] {0} {1}
@@ -3,6 +3,7 @@ MantisProjectProperty.MalformedURL=Mantis\u306eURL\u306b\u6709\u52b9\u306a\u30d7
MantisProjectProperty.UnableToLogin = \u5165\u529b\u3055\u308c\u305f\u60c5\u5831\u3067\u306f\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u307e\u305b\u3093\u3002
MantisProjectProperty.DisplayName = Associated Mantis Website
MantisProjectProperty.InvalidPattern={0}\u304c\u3042\u308a\u307e\u305b\u3093\u3002[ISSUE: {0}]\u306e\u3088\u3046\u306b\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002
MantisProjectProperty.Verified=\u78ba\u8a8dOK
MantisIssueUpdater.DisplayName = \u95a2\u9023\u3059\u308bMantis\u306e\u30c1\u30b1\u30c3\u30c8\u3092\u66f4\u65b0
Updater.IssueIntegrated = {0}:{1} \u306b\u7d71\u5408\u3055\u308c\u307e\u3057\u305f\u3002 ( \u8a73\u7d30: {2} )
Updater.ChangeSet.Revision=[\u30ea\u30d3\u30b8\u30e7\u30f3] {0} {1}

0 comments on commit 56ddb98

Please sign in to comment.