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

Deprecated User.get() replaced and clean-up #27

Merged
merged 2 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import hudson.security.ACL;
import hudson.tasks.Mailer;
import hudson.model.User;
import hudson.model.UserProperty;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.acegisecurity.GrantedAuthority;
Expand Down Expand Up @@ -57,29 +56,29 @@ public boolean setJenkinsUserBuildVars(UserIdCause cause,
SecurityRealm realm = jenkinsInstance.getSecurityRealm();
userid = mapUserId (userid, realm);
GrantedAuthority[] authorities = realm.loadUserByUsername(originalUserid).getAuthorities();
for (int i = 0; i < authorities.length; i++) {
String authorityString = authorities[i].getAuthority();
for (GrantedAuthority authority : authorities) {
String authorityString = authority.getAuthority();
if (authorityString != null && authorityString.length() > 0) {
groupString.append(authorityString).append(",");
}
}
groupString.setLength(groupString.length() == 0 ? 0 : groupString.length() - 1);
} catch (Exception err) {
// Error
log.warning(String.format("Failed to get groups for user: %s error: %s ", userid, err.toString()));
log.warning(String.format("Failed to get groups for user: %s error: %s ", userid, err));
}
variables.put(BUILD_USER_ID, userid);
variables.put(BUILD_USER_VAR_GROUPS, groupString.toString());


User user=User.get(originalUserid);
if(null != user) {
UserProperty prop = user.getProperty(Mailer.UserProperty.class);
if(null != prop) {
String adrs = StringUtils.trimToEmpty(((Mailer.UserProperty)prop).getAddress());
variables.put(BUILD_USER_EMAIL, adrs);
}
}
User user = User.getById(originalUserid, false);
if (null != user) {
Mailer.UserProperty prop = user.getProperty(Mailer.UserProperty.class);
if (null != prop) {
String adrs = StringUtils.trimToEmpty(prop.getAddress());
variables.put(BUILD_USER_EMAIL, adrs);
}
}

return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public void testMakeUserBuildVariablesWithoutUpstream() throws Exception {
// Register non-existent build as an execution cause
Build<FreeStyleProject, FreeStyleBuild> downstreamBuild = childProject.getLastBuild();
List<CauseAction> actions = downstreamBuild.getActions(CauseAction.class);
Assert.assertTrue("CauseAction has not been created properly",
actions != null && actions.size() == 1);
Assert.assertEquals("CauseAction has not been created properly", 1, actions.size());
Cause.UpstreamCause upstreamCause = null;
List<Cause> causes = actions.get(0).getCauses();
for (Cause cause : causes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public void uiAndStorage() throws Throwable {
BuildUserVarsConfig.get().isAllBuilds());
});
sessions.then(
r -> {
assertTrue(
"still there after restart of Jenkins",
BuildUserVarsConfig.get().isAllBuilds());
});
r -> assertTrue(
"still there after restart of Jenkins",
BuildUserVarsConfig.get().isAllBuilds()));
}
}