From 6aecc626c8ad18ce8c714380b87a4b9f1b305bde Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 14 Dec 2018 16:51:17 +0100 Subject: [PATCH] SONARCLOUD-271 Init "notifications.readDate" when creating user --- .../org/sonar/server/user/UserUpdater.java | 42 +++++++++---- .../server/user/ws/SetSettingAction.java | 3 +- .../HttpHeadersAuthenticationTest.java | 2 +- .../authentication/UserRegistrarImplTest.java | 3 + .../server/user/UserUpdaterCreateTest.java | 43 ++++++++++--- .../user/UserUpdaterReactivateTest.java | 63 ++++++++++++++----- .../server/user/UserUpdaterUpdateTest.java | 8 +-- .../user/ws/ChangePasswordActionTest.java | 11 +++- .../server/user/ws/CreateActionTest.java | 2 +- .../server/user/ws/UpdateActionTest.java | 5 +- 10 files changed, 135 insertions(+), 47 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java index 94e252d16e1..0d471f0815b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java @@ -33,12 +33,14 @@ import org.apache.commons.lang.math.RandomUtils; import org.sonar.api.config.Configuration; import org.sonar.api.platform.NewUserHandler; import org.sonar.api.server.ServerSide; +import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.organization.OrganizationMemberDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.db.user.UserGroupDto; +import org.sonar.db.user.UserPropertyDto; import org.sonar.server.authentication.CredentialsLocalAuthentication; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.organization.OrganizationFlags; @@ -62,6 +64,8 @@ import static org.sonar.server.ws.WsUtils.checkRequest; @ServerSide public class UserUpdater { + public static final String NOTIFICATIONS_READ_DATE = "notifications.readDate"; + private static final String SQ_AUTHORITY = "sonarqube"; private static final String LOGIN_PARAM = "Login"; @@ -77,16 +81,18 @@ public class UserUpdater { private final NewUserNotifier newUserNotifier; private final DbClient dbClient; private final UserIndexer userIndexer; - private final OrganizationFlags organizationFlags; private final DefaultOrganizationProvider defaultOrganizationProvider; + private final OrganizationFlags organizationFlags; private final OrganizationUpdater organizationUpdater; private final DefaultGroupFinder defaultGroupFinder; private final Configuration config; private final CredentialsLocalAuthentication localAuthentication; + private final System2 system2; - public UserUpdater(NewUserNotifier newUserNotifier, DbClient dbClient, UserIndexer userIndexer, OrganizationFlags organizationFlags, + public UserUpdater(System2 system2, NewUserNotifier newUserNotifier, DbClient dbClient, UserIndexer userIndexer, OrganizationFlags organizationFlags, DefaultOrganizationProvider defaultOrganizationProvider, OrganizationUpdater organizationUpdater, DefaultGroupFinder defaultGroupFinder, Configuration config, CredentialsLocalAuthentication localAuthentication) { + this.system2 = system2; this.newUserNotifier = newUserNotifier; this.dbClient = dbClient; this.userIndexer = userIndexer; @@ -109,7 +115,7 @@ public class UserUpdater { return commitUser(dbSession, disabledUser, beforeCommit, otherUsersToIndex); } - private void reactivateUser(DbSession dbSession, UserDto disabledUser, NewUser newUser) { + private void reactivateUser(DbSession dbSession, UserDto reactivatedUser, NewUser newUser) { UpdateUser updateUser = new UpdateUser() .setName(newUser.name()) .setEmail(newUser.email()) @@ -123,10 +129,15 @@ public class UserUpdater { if (password != null) { updateUser.setPassword(password); } - setOnboarded(disabledUser); - updateDto(dbSession, updateUser, disabledUser); - updateUser(dbSession, disabledUser); - addUserToDefaultOrganizationAndDefaultGroup(dbSession, disabledUser); + setOnboarded(reactivatedUser); + updateDto(dbSession, updateUser, reactivatedUser); + updateUser(dbSession, reactivatedUser); + boolean isOrganizationEnabled = organizationFlags.isEnabled(dbSession); + if (isOrganizationEnabled) { + setNotificationsReadDate(dbSession, reactivatedUser); + } else { + addUserToDefaultOrganizationAndDefaultGroup(dbSession, reactivatedUser); + } } public void updateAndCommit(DbSession dbSession, UserDto dto, UpdateUser updateUser, Consumer beforeCommit, UserDto... otherUsersToIndex) { @@ -412,7 +423,12 @@ public class UserUpdater { private UserDto saveUser(DbSession dbSession, UserDto userDto) { userDto.setActive(true); UserDto res = dbClient.userDao().insert(dbSession, userDto); - addUserToDefaultOrganizationAndDefaultGroup(dbSession, userDto); + boolean isOrganizationEnabled = organizationFlags.isEnabled(dbSession); + if (isOrganizationEnabled) { + setNotificationsReadDate(dbSession, userDto); + } else { + addUserToDefaultOrganizationAndDefaultGroup(dbSession, userDto); + } organizationUpdater.createForUser(dbSession, userDto); return res; } @@ -435,9 +451,6 @@ public class UserUpdater { } private void addUserToDefaultOrganizationAndDefaultGroup(DbSession dbSession, UserDto userDto) { - if (organizationFlags.isEnabled(dbSession)) { - return; - } addUserToDefaultOrganization(dbSession, userDto); addDefaultGroup(dbSession, userDto); } @@ -456,4 +469,11 @@ public class UserUpdater { } dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupId(defaultGroup.getId())); } + + private void setNotificationsReadDate(DbSession dbSession, UserDto user) { + dbClient.userPropertiesDao().insertOrUpdate(dbSession, new UserPropertyDto() + .setUserUuid(user.getUuid()) + .setKey(NOTIFICATIONS_READ_DATE) + .setValue(Long.toString(system2.now()))); + } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetSettingAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetSettingAction.java index 97d1a3dfe3c..a6ed8969f88 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetSettingAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/SetSettingAction.java @@ -26,6 +26,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.user.UserPropertyDto; import org.sonar.server.user.UserSession; +import org.sonar.server.user.UserUpdater; import static java.util.Objects.requireNonNull; @@ -56,7 +57,7 @@ public class SetSettingAction implements UsersWsAction { .setRequired(true) .setMaximumLength(100) .setDescription("Setting key") - .setPossibleValues("notifications.optOut", "notifications.readDate"); + .setPossibleValues("notifications.optOut", UserUpdater.NOTIFICATIONS_READ_DATE); action.createParam(PARAM_VALUE) .setRequired(true) diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java index ee0033eaf2e..9da0c5db3bb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/HttpHeadersAuthenticationTest.java @@ -105,7 +105,7 @@ public class HttpHeadersAuthenticationTest { private UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client()); private UserRegistrarImpl userIdentityAuthenticator = new UserRegistrarImpl( db.getDbClient(), - new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, organizationFlags, defaultOrganizationProvider, organizationUpdater, + new UserUpdater(system2, mock(NewUserNotifier.class), db.getDbClient(), userIndexer, organizationFlags, defaultOrganizationProvider, organizationUpdater, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), localAuthentication), defaultOrganizationProvider, organizationFlags, mock(OrganizationUpdater.class), new DefaultGroupFinder(db.getDbClient())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java index 0950f6658e6..31f0329d6ba 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/authentication/UserRegistrarImplTest.java @@ -69,6 +69,8 @@ import static org.sonar.server.authentication.event.AuthenticationExceptionMatch public class UserRegistrarImplTest { + private System2 system2 = new AlwaysIncreasingSystem2(); + private static String USER_LOGIN = "github-johndoo"; private static UserIdentity USER_IDENTITY = UserIdentity.builder() @@ -99,6 +101,7 @@ public class UserRegistrarImplTest { private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone(); private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient()); private UserUpdater userUpdater = new UserUpdater( + system2, mock(NewUserNotifier.class), db.getDbClient(), userIndexer, diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterCreateTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterCreateTest.java index e1731a7926a..dfaf38d2f73 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterCreateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterCreateTest.java @@ -37,6 +37,7 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserPropertyDto; import org.sonar.server.authentication.CredentialsLocalAuthentication; import org.sonar.server.authentication.CredentialsLocalAuthentication.HashMethod; import org.sonar.server.es.EsTester; @@ -87,7 +88,8 @@ public class UserUpdaterCreateTest { private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone(); private MapSettings settings = new MapSettings(); private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient()); - private UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer, organizationFlags, defaultOrganizationProvider, organizationUpdater, + + private UserUpdater underTest = new UserUpdater(system2, newUserNotifier, dbClient, userIndexer, organizationFlags, defaultOrganizationProvider, organizationUpdater, new DefaultGroupFinder(dbClient), settings.asConfig(), localAuthentication); @Test @@ -162,7 +164,7 @@ public class UserUpdaterCreateTest { } @Test - public void create_user_generates_unique_login_when_login_is_emnpty() { + public void create_user_generates_unique_login_when_login_is_empty() { createDefaultGroup(); UserDto user = underTest.createAndCommit(db.getSession(), NewUser.builder() @@ -280,8 +282,8 @@ public class UserUpdaterCreateTest { @Test public void create_not_onboarded_user_if_onboarding_setting_is_set_to_false() { - createDefaultGroup(); settings.setProperty(ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS, false); + createDefaultGroup(); underTest.createAndCommit(db.getSession(), NewUser.builder() .setLogin("user") @@ -294,8 +296,8 @@ public class UserUpdaterCreateTest { @Test public void create_onboarded_user_if_onboarding_setting_is_set_to_true() { - createDefaultGroup(); settings.setProperty(ONBOARDING_TUTORIAL_SHOW_TO_NEW_USERS, true); + createDefaultGroup(); underTest.createAndCommit(db.getSession(), NewUser.builder() .setLogin("user") @@ -306,6 +308,36 @@ public class UserUpdaterCreateTest { assertThat(dbClient.userDao().selectByLogin(session, "user").isOnboarded()).isFalse(); } + @Test + public void set_notifications_readDate_setting_when_creating_user_and_organization_enabled() { + long now = system2.now(); + organizationFlags.setEnabled(true); + createDefaultGroup(); + + UserDto user = underTest.createAndCommit(db.getSession(), NewUser.builder() + .setLogin("userLogin") + .setName("UserName") + .build(), u -> { + }); + + UserPropertyDto notificationReadDateSetting = dbClient.userPropertiesDao().selectByUser(session, user).get(0); + assertThat(notificationReadDateSetting.getKey()).isEqualTo("notifications.readDate"); + assertThat(Long.parseLong(notificationReadDateSetting.getValue())).isGreaterThanOrEqualTo(now); + } + + @Test + public void does_not_set_notifications_readDate_setting_when_creating_user_when_not_on_and_organization_disabled() { + createDefaultGroup(); + + UserDto user = underTest.createAndCommit(db.getSession(), NewUser.builder() + .setLogin("userLogin") + .setName("UserName") + .build(), u -> { + }); + + assertThat(dbClient.userPropertiesDao().selectByUser(session, user)).isEmpty(); + } + @Test public void create_user_and_index_other_user() { createDefaultGroup(); @@ -554,7 +586,6 @@ public class UserUpdaterCreateTest { @Test public void associate_default_group_when_creating_user_and_organizations_are_disabled() { - organizationFlags.setEnabled(false); GroupDto defaultGroup = createDefaultGroup(); underTest.createAndCommit(db.getSession(), NewUser.builder() @@ -618,7 +649,6 @@ public class UserUpdaterCreateTest { @Test public void add_user_as_member_of_default_organization_when_creating_user_and_organizations_are_disabled() { - organizationFlags.setEnabled(false); createDefaultGroup(); UserDto dto = underTest.createAndCommit(db.getSession(), NewUser.builder() @@ -651,5 +681,4 @@ public class UserUpdaterCreateTest { private GroupDto createDefaultGroup() { return db.users().insertDefaultGroup(db.getDefaultOrganization()); } - } diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterReactivateTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterReactivateTest.java index 1222dc34c4c..203c4c99fef 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterReactivateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterReactivateTest.java @@ -32,6 +32,7 @@ import org.sonar.db.DbTester; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupTesting; import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserPropertyDto; import org.sonar.server.authentication.CredentialsLocalAuthentication; import org.sonar.server.authentication.CredentialsLocalAuthentication.HashMethod; import org.sonar.server.es.EsTester; @@ -70,8 +71,8 @@ public class UserUpdaterReactivateTest { private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone(); private MapSettings settings = new MapSettings(); private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient()); - private UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer, organizationFlags, defaultOrganizationProvider, organizationUpdater, - new DefaultGroupFinder(dbClient), settings.asConfig(), localAuthentication); + private UserUpdater underTest = new UserUpdater(system2, newUserNotifier, dbClient, userIndexer, organizationFlags, defaultOrganizationProvider, organizationUpdater, + new DefaultGroupFinder(dbClient), settings.asConfig(), localAuthentication);; @Test public void reactivate_user() { @@ -107,10 +108,10 @@ public class UserUpdaterReactivateTest { createDefaultGroup(); underTest.reactivateAndCommit(db.getSession(), user, NewUser.builder() - .setName("Marius2") - .setEmail("marius2@mail.com") - .setPassword("password2") - .build(), + .setName("Marius2") + .setEmail("marius2@mail.com") + .setPassword("password2") + .build(), u -> { }); @@ -222,7 +223,6 @@ public class UserUpdaterReactivateTest { @Test public void associate_default_groups_when_reactivating_user_and_organizations_are_disabled() { - organizationFlags.setEnabled(false); UserDto userDto = db.users().insertDisabledUser(); db.organizations().insertForUuid("org1"); GroupDto groupDto = db.users().insertGroup(GroupTesting.newGroupDto().setName("sonar-devs").setOrganizationUuid("org1")); @@ -262,7 +262,6 @@ public class UserUpdaterReactivateTest { @Test public void add_user_as_member_of_default_organization_when_reactivating_user_and_organizations_are_disabled() { - organizationFlags.setEnabled(false); UserDto user = db.users().insertDisabledUser(); createDefaultGroup(); @@ -314,6 +313,38 @@ public class UserUpdaterReactivateTest { assertThat(dbClient.userDao().selectByLogin(session, user.getLogin()).isOnboarded()).isFalse(); } + @Test + public void set_notifications_readDate_setting_when_reactivating_user_on_sonar_cloud() { + long now = system2.now(); + organizationFlags.setEnabled(true); + createDefaultGroup(); + UserDto user = db.users().insertDisabledUser(); + + underTest.reactivateAndCommit(db.getSession(), user, NewUser.builder() + .setLogin(user.getLogin()) + .setName(user.getName()) + .build(), u -> { + }); + + UserPropertyDto notificationReadDateSetting = dbClient.userPropertiesDao().selectByUser(session, user).get(0); + assertThat(notificationReadDateSetting.getKey()).isEqualTo("notifications.readDate"); + assertThat(Long.parseLong(notificationReadDateSetting.getValue())).isGreaterThanOrEqualTo(now); + } + + @Test + public void does_not_set_notifications_readDate_setting_when_reactivating_user_when_not_on_sonar_cloud() { + createDefaultGroup(); + UserDto user = db.users().insertDisabledUser(); + + underTest.reactivateAndCommit(db.getSession(), user, NewUser.builder() + .setLogin(user.getLogin()) + .setName(user.getName()) + .build(), u -> { + }); + + assertThat(dbClient.userPropertiesDao().selectByUser(session, user)).isEmpty(); + } + @Test public void fail_to_reactivate_user_when_login_already_exists() { createDefaultGroup(); @@ -324,10 +355,10 @@ public class UserUpdaterReactivateTest { expectedException.expectMessage("A user with login 'existing_login' already exists"); underTest.reactivateAndCommit(db.getSession(), user, NewUser.builder() - .setLogin(existingUser.getLogin()) - .setName("Marius2") - .setPassword("password2") - .build(), + .setLogin(existingUser.getLogin()) + .setName("Marius2") + .setPassword("password2") + .build(), u -> { }); } @@ -342,10 +373,10 @@ public class UserUpdaterReactivateTest { expectedException.expectMessage("A user with provider id 'existing_external_id' and identity provider 'existing_external_provider' already exists"); underTest.reactivateAndCommit(db.getSession(), user, NewUser.builder() - .setLogin(user.getLogin()) - .setName("Marius2") - .setExternalIdentity(new ExternalIdentity(existingUser.getExternalIdentityProvider(), existingUser.getExternalLogin(), existingUser.getExternalId())) - .build(), + .setLogin(user.getLogin()) + .setName("Marius2") + .setExternalIdentity(new ExternalIdentity(existingUser.getExternalIdentityProvider(), existingUser.getExternalLogin(), existingUser.getExternalId())) + .build(), u -> { }); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java index 8b47869c40c..3b5489e4c3e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java @@ -82,7 +82,7 @@ public class UserUpdaterUpdateTest { private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone(); private MapSettings settings = new MapSettings(); private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient()); - private UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer, organizationFlags, defaultOrganizationProvider, organizationUpdater, + private UserUpdater underTest = new UserUpdater(system2, newUserNotifier, dbClient, userIndexer, organizationFlags, defaultOrganizationProvider, organizationUpdater, new DefaultGroupFinder(dbClient), settings.asConfig(), localAuthentication); @Test @@ -218,8 +218,7 @@ public class UserUpdaterUpdateTest { new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()), new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setResourceId(project1.getId()), new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setResourceId(project2.getId()), - new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setResourceId(anotherProject.getId()) - ); + new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setResourceId(anotherProject.getId())); userIndexer.indexOnStartup(null); underTest.updateAndCommit(session, oldUser, new UpdateUser() @@ -232,8 +231,7 @@ public class UserUpdaterUpdateTest { tuple("new_login", null), tuple("new_login", project1.getId()), tuple("new_login", project2.getId()), - tuple("another login", anotherProject.getId()) - ); + tuple("another login", anotherProject.getId())); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java index 331fd58c945..f13fe997e06 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java @@ -24,6 +24,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.config.internal.MapSettings; +import org.sonar.api.utils.System2; +import org.sonar.api.utils.internal.AlwaysIncreasingSystem2; import org.sonar.db.DbTester; import org.sonar.server.authentication.CredentialsLocalAuthentication; import org.sonar.server.es.EsTester; @@ -48,6 +50,9 @@ import static org.sonar.db.user.UserTesting.newExternalUser; import static org.sonar.db.user.UserTesting.newLocalUser; public class ChangePasswordActionTest { + + private System2 system2 = new AlwaysIncreasingSystem2(); + @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule @@ -60,7 +65,7 @@ public class ChangePasswordActionTest { private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone(); private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient()); - private UserUpdater userUpdater = new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), new UserIndexer(db.getDbClient(), es.client()), + private UserUpdater userUpdater = new UserUpdater(system2, mock(NewUserNotifier.class), db.getDbClient(), new UserIndexer(db.getDbClient(), es.client()), organizationFlags, TestDefaultOrganizationProvider.from(db), mock(OrganizationUpdater.class), @@ -83,7 +88,7 @@ public class ChangePasswordActionTest { .setName("John") .setPassword("Valar Dohaeris") .build(), u -> { - }); + }); String oldCryptedPassword = db.getDbClient().userDao().selectByLogin(db.getSession(), "john").getCryptedPassword(); userSessionRule.logIn("john"); @@ -139,7 +144,7 @@ public class ChangePasswordActionTest { @Test public void fail_on_disabled_user() { - db.users().insertUser(u -> u.setLogin( "polop").setActive(false)); + db.users().insertUser(u -> u.setLogin("polop").setActive(false)); userSessionRule.logIn().setSystemAdministrator(); expectedException.expect(NotFoundException.class); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java index a47678b4ffb..3994cec124d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java @@ -91,7 +91,7 @@ public class CreateActionTest { private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient()); private WsActionTester tester = new WsActionTester(new CreateAction( db.getDbClient(), - new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, organizationFlags, defaultOrganizationProvider, + new UserUpdater(system2, mock(NewUserNotifier.class), db.getDbClient(), userIndexer, organizationFlags, defaultOrganizationProvider, organizationUpdater, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), localAuthentication), userSessionRule)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java index 5d4d97aa472..004383a9308 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java @@ -74,8 +74,9 @@ public class UpdateActionTest { private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient()); private WsActionTester ws = new WsActionTester(new UpdateAction( - new UserUpdater(mock(NewUserNotifier.class), dbClient, userIndexer, organizationFlags, defaultOrganizationProvider, ORGANIZATION_CREATION_NOT_USED_FOR_UPDATE, - new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), localAuthentication), userSession, new UserJsonWriter(userSession), dbClient)); + new UserUpdater(system2, mock(NewUserNotifier.class), dbClient, userIndexer, organizationFlags, defaultOrganizationProvider, ORGANIZATION_CREATION_NOT_USED_FOR_UPDATE, + new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), localAuthentication), + userSession, new UserJsonWriter(userSession), dbClient)); @Before public void setUp() { -- 2.39.5