Commit
…sentation
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,9 @@ | |
import java.util.SortedMap; | ||
import java.util.logging.Logger; | ||
|
||
import net.sf.json.JSONArray; | ||
import net.sf.json.JSONObject; | ||
import net.sf.json.util.JSONUtils; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
kutzi
Member
|
||
|
||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
|
@@ -222,6 +224,30 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> | |
} | ||
} | ||
|
||
/** | ||
* Check boxes values are not passed in the posted form when they are unchecked. | ||
* The workaround consists in acceding these values via the JSON representation. | ||
*/ | ||
private static List<JSONObject> fillChannelsFromJSON(JSONObject root){ | ||
List<JSONObject> result = null; | ||
JSONObject chan = root.optJSONObject("channels"); | ||
if (chan != null){ | ||
result = new ArrayList<JSONObject>(); | ||
result.add(chan); | ||
} | ||
else{ | ||
JSONArray chans = root.optJSONArray("channels"); | ||
if (chans != null){ | ||
result = new ArrayList<JSONObject>(); | ||
for(int i=0; i<chans.size(); ++i){ | ||
chan = chans.getJSONObject(i); | ||
result.add(chan); | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* @see hudson.model.Descriptor#configure(org.kohsuke.stapler.StaplerRequest) | ||
*/ | ||
|
@@ -251,10 +277,20 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc | |
|
||
String[] channelsNames = req.getParameterValues("irc_publisher.channel.name"); | ||
String[] channelsPasswords = req.getParameterValues("irc_publisher.channel.password"); | ||
String[] notifyOnlys = req.getParameterValues("irc_publisher.chat.notificationOnly"); | ||
// only checked state can be queried, unchecked state are ignored and the size of | ||
// notifyOnlys may be lower than the size of channelNames | ||
// so getting the values via stapler is unreliable. | ||
// String[] notifyOnlys = req.getParameterValues("irc_publisher.chat.notificationOnly"); | ||
|
||
List<IMMessageTarget> targets = Collections.emptyList(); | ||
if (channelsNames != null) { | ||
// JENKINS-13697: Get the data from the JSON representation which always returns | ||
// a value. The downside is that we are dependent on the data structure. | ||
List<JSONObject> jchans = null; | ||
JSONObject enabled = formData.optJSONObject("enabled"); | ||
if (enabled != null){ | ||
This comment has been minimized.
Sorry, something went wrong.
kutzi
Member
|
||
jchans = fillChannelsFromJSON(enabled); | ||
} | ||
targets = new ArrayList<IMMessageTarget>(channelsNames.length); | ||
for (int i=0; i < channelsNames.length; i++) { | ||
|
||
|
@@ -263,7 +299,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc | |
} | ||
|
||
String password = Util.fixEmpty(channelsPasswords[i]); | ||
boolean notifyOnly = notifyOnlys != null ? "on".equalsIgnoreCase(notifyOnlys[i]) : false; | ||
boolean notifyOnly = jchans.size() > 0 ? jchans.get(i).getBoolean("notificationOnly") : false; | ||
This comment has been minimized.
Sorry, something went wrong.
syl20bnr
Author
Member
|
||
|
||
targets.add(new GroupChatIMMessageTarget(channelsNames[i], password, notifyOnly)); | ||
} | ||
|
@@ -321,10 +357,10 @@ public String getHelpFile() { | |
public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException { | ||
String[] channelsNames = req.getParameterValues("irc_publisher.channel.name"); | ||
String[] channelsPasswords = req.getParameterValues("irc_publisher.channel.password"); | ||
String[] notifyOnlys = req.getParameterValues("irc_publisher.chat.notificationOnly"); | ||
|
||
List<IMMessageTarget> targets = Collections.emptyList(); | ||
if (channelsNames != null) { | ||
List<JSONObject> jchans = fillChannelsFromJSON(formData); | ||
targets = new ArrayList<IMMessageTarget>(channelsNames.length); | ||
for (int i=0; i < channelsNames.length; i++) { | ||
|
||
|
@@ -333,7 +369,7 @@ public Publisher newInstance(StaplerRequest req, JSONObject formData) throws For | |
} | ||
|
||
String password = Util.fixEmpty(channelsPasswords[i]); | ||
boolean notifyOnly = notifyOnlys != null ? "on".equalsIgnoreCase(notifyOnlys[i]) : false; | ||
boolean notifyOnly = jchans.size() > 0 ? jchans.get(i).getBoolean("notificationOnly") : false; | ||
This comment has been minimized.
Sorry, something went wrong.
syl20bnr
Author
Member
|
||
targets.add(new GroupChatIMMessageTarget(channelsNames[i], password, notifyOnly)); | ||
} | ||
} | ||
|
4 comments
on commit ffbda2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really thankful that you looked at this issue, but I'd be grateful if you'd open pull requests instead of commiting directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're welcome and my apologies for this. It won't happen again!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about what you meant, do you prefere to rollback this fix and want me to submit a pull request instead ? No problem for me to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No prob
import net.sf.json.util.JSONUtils; not needed ?