Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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-56005] Add user property-change listener #3901
[JENKINS-56005] Add user property-change listener #3901
Changes from 3 commits
1fe3770
f4465d1
124b84c
43b50ff
49400e5
13c8864
87b44db
5de70ac
d0a19f0
d1382a6
97bfcc3
cc75d2c
4466180
4e1c33f
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
{}
in theif
, so you are breaking the statement there.That's exactly the main reason why I hate the
if
without brackets 👿If that code bug was not discovered by your tests => there is a missing path in your coverage.
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.
do you advise using the
if
for only one-liners; or to just never use a non-bracketedif
at all ?Like;
versus;
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 can only advice to never use a
if
without the associated{}
, to avoid situation where someone wants to add a line, but due to the missing brackets will break the code flow like here.And the one-liner is worse from my PoV due to the poor readability.
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.
perks of using Python over Java :)
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 only use one line ifs for things like:
if (foo == null) return null;
or
if (bar) return false;
or
if (baz) return;
Basically, only for control flow type things. Remember, forgetting your brackets can cause security problems (see the old Apple bug). If you auto-format your code before committing, you can see if you missed brackets based on how it indents things.
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 kind of wonder if this would be more appropriate in its own
UserPropertyListener
or similar. I'm thinking in terms that it may eventually be useful to have event listeners for JobProperty, NodeProperty, and others if I'm forgetting.Also, I'm not sure if there's precedence in this class already, but I think it might make more sense to flip the ordering of the parameters here.
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 really convinced one way or another. The
userPropertyUpdated()
method doesn't quite seem to fit the other things in SecurityListener. But then, some of the other items in SecurityListener don't fit well either. The user property is more about users than specifically about security. But so are some of the other things in this file.I guess when it comes down to it I have a slight preference for separating out a
UserPropertyListener
.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.
hmh.. alright. Question though is for the new
UserPropertyListener
: it being an abstract-class versus interface ?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.
@Wadeck Any thoughts on the creation of a new separate
UserPropertyListener
?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.
Separation seems better for the long term, like Matt mentioned, about the other items that could/would require such listeners in the future. And also, it's not directly security related, so not really a reason to be put in
SecurityListener
, except for the specific case ofDetails
. But I imagine the goal of this listener is to be triggered everytime a property change, in general.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.
@Wadeck hmh.. abstract versus interface ?
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 will bet on
abstract
being the most natural way as you are providing some static helper methods (for the event trigger). The interfaces should be used for contract definition.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.
Interfaces allow static methods as of Java 8. See for example the methods added to the collections API. Also default methods.