*/
package org.sonar.db.user;
+import java.util.Set;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
return dto;
}
+ public Set<String> selectUserUuidsInGroup(DbSession session, String groupUuid) {
+ return mapper(session).selectUserUuidsInGroup(groupUuid);
+ }
+
public void delete(DbSession session, String groupUuid, String userUuid) {
mapper(session).delete(groupUuid, userUuid);
}
*/
package org.sonar.db.user;
+import java.util.Set;
import org.apache.ibatis.annotations.Param;
public interface UserGroupMapper {
void insert(UserGroupDto dto);
+ Set<String> selectUserUuidsInGroup(@Param("groupUuid") String groupUuid);
+
void delete(@Param("groupUuid") String groupUuid, @Param("userUuid") String userUuid);
void deleteByGroupUuid(@Param("groupUuid") String groupUuid);
)
</insert>
+ <select id="selectUserUuidsInGroup" resultType="String">
+ select gu.user_uuid
+ from groups_users gu
+ where gu.group_uuid=#{groupUuid,jdbcType=VARCHAR}
+ </select>
+
<delete id="delete" parameterType="map">
delete from groups_users
where user_uuid = #{userUuid,jdbcType=VARCHAR} and
*/
package org.sonar.db.user;
+import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
-import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private DbClient dbClient = dbTester.getDbClient();
- private DbSession dbSession = dbTester.getSession();
- private UserGroupDao underTest = dbTester.getDbClient().userGroupDao();
+ private final DbSession dbSession = dbTester.getSession();
+ private final UserGroupDao underTest = dbTester.getDbClient().userGroupDao();
@Test
public void insert() {
assertThat(dbTester.getDbClient().groupMembershipDao().selectGroupUuidsByUserUuid(dbTester.getSession(), user.getUuid())).containsOnly(group.getUuid());
}
+ @Test
+ public void select_user_uuids_in_group() {
+ UserDto user1 = dbTester.users().insertUser();
+ UserDto user2 = dbTester.users().insertUser();
+ UserDto user3 = dbTester.users().insertUser();
+ GroupDto group1 = dbTester.users().insertGroup();
+ GroupDto group2 = dbTester.users().insertGroup();
+ UserGroupDto userGroupDto1 = new UserGroupDto().setUserUuid(user1.getUuid()).setGroupUuid(group1.getUuid());
+ UserGroupDto userGroupDto2 = new UserGroupDto().setUserUuid(user2.getUuid()).setGroupUuid(group2.getUuid());
+ UserGroupDto userGroupDto3 = new UserGroupDto().setUserUuid(user3.getUuid()).setGroupUuid(group2.getUuid());
+ underTest.insert(dbSession, userGroupDto1);
+ underTest.insert(dbSession, userGroupDto2);
+ underTest.insert(dbSession, userGroupDto3);
+ dbTester.getSession().commit();
+
+ Set<String> userUuids = underTest.selectUserUuidsInGroup(dbTester.getSession(), group2.getUuid());
+
+ assertThat(userUuids).containsExactlyInAnyOrder(user2.getUuid(), user3.getUuid());
+ }
+
+ @Test
+ public void select_user_uuids_in_group_returns_empty_set_when_nothing_found() {
+ UserDto user1 = dbTester.users().insertUser();
+ GroupDto group1 = dbTester.users().insertGroup();
+ GroupDto group2 = dbTester.users().insertGroup();
+ UserGroupDto userGroupDto1 = new UserGroupDto().setUserUuid(user1.getUuid()).setGroupUuid(group1.getUuid());
+ underTest.insert(dbSession, userGroupDto1);
+ dbTester.getSession().commit();
+
+ Set<String> userUuids = underTest.selectUserUuidsInGroup(dbTester.getSession(), group2.getUuid());
+
+ assertThat(userUuids).isEmpty();
+ }
+
@Test
public void delete_members_by_group_uuid() {
UserDto user1 = dbTester.users().insertUser();
import org.sonar.db.alm.ALM;
import org.sonar.db.alm.OrganizationAlmBindingDto;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationMemberDto;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserGroupDto;
import org.sonar.server.user.index.UserIndexer;
this.userIndexer = userIndexer;
}
- public void addMember(DbSession dbSession, OrganizationDto organization, UserDto user) {
- addMembers(dbSession, organization, singletonList(user));
+ public void addMember(DbSession dbSession, UserDto user) {
+ addMembers(dbSession, singletonList(user));
}
- public void addMembers(DbSession dbSession, OrganizationDto organization, List<UserDto> users) {
- Set<String> currentMemberUuids = new HashSet<>(dbClient.organizationMemberDao().selectUserUuidsByOrganizationUuid(dbSession, organization.getUuid()));
+ public void addMembers(DbSession dbSession, List<UserDto> users) {
+ Set<String> currentMemberUuids = dbClient.userGroupDao().selectUserUuidsInGroup(dbSession, defaultGroupFinder.findDefaultGroup(dbSession).getUuid());
List<UserDto> usersToAdd = users.stream()
.filter(UserDto::isActive)
.filter(u -> !currentMemberUuids.contains(u.getUuid()))
if (usersToAdd.isEmpty()) {
return;
}
- usersToAdd.forEach(u -> addMemberInDb(dbSession, organization, u));
+ usersToAdd.forEach(u -> addMemberInDb(dbSession, u));
userIndexer.commitAndIndex(dbSession, usersToAdd);
}
- private void addMemberInDb(DbSession dbSession, OrganizationDto organization, UserDto user) {
- dbClient.organizationMemberDao().insert(dbSession, new OrganizationMemberDto()
- .setOrganizationUuid(organization.getUuid())
- .setUserUuid(user.getUuid()));
+ private void addMemberInDb(DbSession dbSession, UserDto user) {
dbClient.userGroupDao().insert(dbSession,
new UserGroupDto().setGroupUuid(defaultGroupFinder.findDefaultGroup(dbSession).getUuid()).setUserUuid(user.getUuid()));
}
+ // TODO remove org param like it was removed from addMembers
public void removeMember(DbSession dbSession, OrganizationDto organization, UserDto user) {
removeMembers(dbSession, organization, singletonList(user));
}
+ // TODO remove org param like it was removed from addMembers
public void removeMembers(DbSession dbSession, OrganizationDto organization, List<UserDto> users) {
Set<String> currentMemberIds = new HashSet<>(dbClient.organizationMemberDao().selectUserUuidsByOrganizationUuid(dbSession, organization.getUuid()));
List<UserDto> usersToRemove = users.stream()
allOrganizationsByUuid.entrySet().stream()
.filter(entry -> organizationUuidsToBeAdded.contains(entry.getKey()))
- .forEach(entry -> addMemberInDb(dbSession, entry.getValue(), user));
+ .forEach(entry -> addMemberInDb(dbSession, user));
allOrganizationsByUuid.entrySet().stream()
.filter(entry -> organizationUuidsToBeRemoved.contains(entry.getKey()))
.forEach(entry -> removeMemberInDb(dbSession, entry.getValue(), user));
import org.sonar.api.server.ServerSide;
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.server.authentication.CredentialsLocalAuthentication;
-import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
import org.sonar.server.util.Validation;
private final NewUserNotifier newUserNotifier;
private final DbClient dbClient;
private final UserIndexer userIndexer;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
private final DefaultGroupFinder defaultGroupFinder;
private final Configuration config;
private final CredentialsLocalAuthentication localAuthentication;
- public UserUpdater(NewUserNotifier newUserNotifier, DbClient dbClient, UserIndexer userIndexer,
- DefaultOrganizationProvider defaultOrganizationProvider, DefaultGroupFinder defaultGroupFinder, Configuration config,
+ public UserUpdater(NewUserNotifier newUserNotifier, DbClient dbClient, UserIndexer userIndexer, DefaultGroupFinder defaultGroupFinder, Configuration config,
CredentialsLocalAuthentication localAuthentication) {
this.newUserNotifier = newUserNotifier;
this.dbClient = dbClient;
this.userIndexer = userIndexer;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
this.defaultGroupFinder = defaultGroupFinder;
this.config = config;
this.localAuthentication = localAuthentication;
setOnboarded(reactivatedUser);
updateDto(dbSession, updateUser, reactivatedUser);
updateUser(dbSession, reactivatedUser);
- addUserToDefaultOrganizationAndDefaultGroup(dbSession, reactivatedUser);
+ addUserToDefaultGroup(dbSession, reactivatedUser);
}
public void updateAndCommit(DbSession dbSession, UserDto dto, UpdateUser updateUser, Consumer<UserDto> beforeCommit, UserDto... otherUsersToIndex) {
private UserDto saveUser(DbSession dbSession, UserDto userDto) {
userDto.setActive(true);
UserDto res = dbClient.userDao().insert(dbSession, userDto);
- addUserToDefaultOrganizationAndDefaultGroup(dbSession, userDto);
+ addUserToDefaultGroup(dbSession, userDto);
return res;
}
return userGroups.stream().anyMatch(group -> defaultGroup.getUuid().equals(group.getUuid()));
}
- private void addUserToDefaultOrganizationAndDefaultGroup(DbSession dbSession, UserDto userDto) {
- addUserToDefaultOrganization(dbSession, userDto);
+ private void addUserToDefaultGroup(DbSession dbSession, UserDto userDto) {
addDefaultGroup(dbSession, userDto);
}
- private void addUserToDefaultOrganization(DbSession dbSession, UserDto userDto) {
- String defOrgUuid = defaultOrganizationProvider.get().getUuid();
- dbClient.organizationMemberDao().insert(dbSession, new OrganizationMemberDto().setOrganizationUuid(defOrgUuid).setUserUuid(userDto.getUuid()));
- }
-
private void addDefaultGroup(DbSession dbSession, UserDto userDto) {
List<GroupDto> userGroups = dbClient.groupDao().selectByUserLogin(dbSession, userDto.getLogin());
GroupDto defaultGroup = defaultGroupFinder.findDefaultGroup(dbSession);
import org.sonar.server.authentication.event.AuthenticationEvent;
import org.sonar.server.authentication.event.AuthenticationEvent.Source;
import org.sonar.server.es.EsTester;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
import org.sonar.server.user.index.UserIndexer;
public class HttpHeadersAuthenticationTest {
- private MapSettings settings = new MapSettings();
+ private final MapSettings settings = new MapSettings();
@Rule
public ExpectedException expectedException = none();
private GroupDto group2;
private GroupDto sonarUsers;
- private System2 system2 = mock(System2.class);
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
+ private final System2 system2 = mock(System2.class);
+ private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
- private UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
+ private final UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
private final DefaultGroupFinder defaultGroupFinder = new DefaultGroupFinder(db.getDbClient());
- private final UserRegistrarImpl userIdentityAuthenticator = new UserRegistrarImpl(
- db.getDbClient(),
- new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, defaultOrganizationProvider, defaultGroupFinder, settings.asConfig(),
- localAuthentication),
+ private final UserRegistrarImpl userIdentityAuthenticator = new UserRegistrarImpl(db.getDbClient(),
+ new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, defaultGroupFinder, settings.asConfig(), localAuthentication),
defaultGroupFinder);
-
- private HttpServletResponse response = mock(HttpServletResponse.class);
- private JwtHttpHandler jwtHttpHandler = mock(JwtHttpHandler.class);
- private AuthenticationEvent authenticationEvent = mock(AuthenticationEvent.class);
-
- private HttpHeadersAuthentication underTest = new HttpHeadersAuthentication(system2, settings.asConfig(), userIdentityAuthenticator, jwtHttpHandler, authenticationEvent);
+ private final HttpServletResponse response = mock(HttpServletResponse.class);
+ private final JwtHttpHandler jwtHttpHandler = mock(JwtHttpHandler.class);
+ private final AuthenticationEvent authenticationEvent = mock(AuthenticationEvent.class);
+ private final HttpHeadersAuthentication underTest = new HttpHeadersAuthentication(system2, settings.asConfig(), userIdentityAuthenticator, jwtHttpHandler,
+ authenticationEvent);
@Before
public void setUp() {
import org.sonar.server.authentication.event.AuthenticationEvent.Source;
import org.sonar.server.authentication.exception.EmailAlreadyExistsRedirectionException;
import org.sonar.server.es.EsTester;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
import org.sonar.server.user.index.UserIndexer;
import static org.sonar.server.authentication.event.AuthenticationExceptionMatcher.authenticationException;
public class UserRegistrarImplTest {
- private static String USER_LOGIN = "johndoo";
+ private static final String USER_LOGIN = "johndoo";
- private static UserIdentity USER_IDENTITY = UserIdentity.builder()
+ private static final UserIdentity USER_IDENTITY = UserIdentity.builder()
.setProviderId("ABCD")
.setProviderLogin("johndoo")
.setName("John")
.setEmail("john@email.com")
.build();
- private static TestIdentityProvider IDENTITY_PROVIDER = new TestIdentityProvider()
+ private static final TestIdentityProvider IDENTITY_PROVIDER = new TestIdentityProvider()
.setKey("github")
.setName("name of github")
.setEnabled(true)
.setAllowsUsersToSignUp(true);
- private MapSettings settings = new MapSettings();
+ private final MapSettings settings = new MapSettings();
@Rule
public ExpectedException expectedException = ExpectedException.none();
public DbTester db = DbTester.create(new AlwaysIncreasingSystem2());
@Rule
public EsTester es = EsTester.create();
- private UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
+ private final UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
+ private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
private final DefaultGroupFinder groupFinder = new DefaultGroupFinder(db.getDbClient());
- private UserUpdater userUpdater = new UserUpdater(
+ private final UserUpdater userUpdater = new UserUpdater(
mock(NewUserNotifier.class),
db.getDbClient(),
userIndexer,
- defaultOrganizationProvider,
groupFinder,
settings.asConfig(),
localAuthentication);
- private UserRegistrarImpl underTest = new UserRegistrarImpl(db.getDbClient(), userUpdater, groupFinder);
+ private final UserRegistrarImpl underTest = new UserRegistrarImpl(db.getDbClient(), userUpdater, groupFinder);
private GroupDto defaultGroup;
@Before
import org.sonar.server.authentication.CredentialsLocalAuthentication.HashMethod;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.user.index.UserIndexDefinition;
import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
private static final String DEFAULT_LOGIN = "marius";
- private System2 system2 = new AlwaysIncreasingSystem2();
+ private final System2 system2 = new AlwaysIncreasingSystem2();
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
public DbTester db = DbTester.create(system2);
- private DbClient dbClient = db.getDbClient();
- private NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
- private ArgumentCaptor<NewUserHandler.Context> newUserHandler = ArgumentCaptor.forClass(NewUserHandler.Context.class);
- private DbSession session = db.getSession();
- private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private MapSettings settings = new MapSettings();
- private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
-
- private UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer, defaultOrganizationProvider,
+ private final DbClient dbClient = db.getDbClient();
+ private final NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
+ private final ArgumentCaptor<NewUserHandler.Context> newUserHandler = ArgumentCaptor.forClass(NewUserHandler.Context.class);
+ private final DbSession session = db.getSession();
+ private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
+ private final MapSettings settings = new MapSettings();
+ private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
+ private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer,
new DefaultGroupFinder(dbClient), settings.asConfig(), localAuthentication);
@Test
}
@Test
- public void does_not_set_notifications_readDate_setting_when_creating_user_when_not_on_and_organization_disabled() {
+ public void does_not_set_notifications_readDate_setting_when_creating_user_when_not_on() {
createDefaultGroup();
UserDto user = underTest.createAndCommit(db.getSession(), NewUser.builder()
});
}
- @Test
- public void add_user_as_member_of_default_organization_when_creating_user_and_organizations_are_disabled() {
- createDefaultGroup();
-
- UserDto dto = underTest.createAndCommit(db.getSession(), NewUser.builder()
- .setLogin("user")
- .setName("User")
- .setEmail("user@mail.com")
- .setPassword("PASSWORD")
- .build(), u -> {
- });
-
- assertThat(dbClient.organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dto.getUuid())).isPresent();
- }
-
private GroupDto createDefaultGroup() {
return db.users().insertDefaultGroup();
}
import org.sonar.server.authentication.CredentialsLocalAuthentication;
import org.sonar.server.authentication.CredentialsLocalAuthentication.HashMethod;
import org.sonar.server.es.EsTester;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
private final NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
private final DbSession session = db.getSession();
private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
- private final DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private final MapSettings settings = new MapSettings();
private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
- private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer, defaultOrganizationProvider,
+ private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer,
new DefaultGroupFinder(dbClient),
settings.asConfig(), localAuthentication);
import org.sonar.server.authentication.CredentialsLocalAuthentication;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.user.index.UserIndexDefinition;
import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.usergroups.DefaultGroupFinder;
private static final Consumer<UserDto> EMPTY_USER_CONSUMER = userDto -> {
};
- private System2 system2 = new AlwaysIncreasingSystem2();
+ private final System2 system2 = new AlwaysIncreasingSystem2();
@Rule
public EsTester es = EsTester.create();
@Rule
public DbTester db = DbTester.create(system2);
- private DbClient dbClient = db.getDbClient();
- private NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
- private DbSession session = db.getSession();
- private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private MapSettings settings = new MapSettings();
- private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
- private UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer, defaultOrganizationProvider,
+ private final DbClient dbClient = db.getDbClient();
+ private final NewUserNotifier newUserNotifier = mock(NewUserNotifier.class);
+ private final DbSession session = db.getSession();
+ private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
+ private final MapSettings settings = new MapSettings();
+ private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
+ private final UserUpdater underTest = new UserUpdater(newUserNotifier, dbClient, userIndexer,
new DefaultGroupFinder(dbClient), settings.asConfig(), localAuthentication);
@Test
import static org.sonar.server.ws.KeyExamples.KEY_ORG_EXAMPLE_001;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
+//TODO remove when getting rid of organizations
+@Deprecated
public class AddMemberAction implements OrganizationsWsAction {
private final DbClient dbClient;
private final UserSession userSession;
userSession.checkPermission(GlobalPermission.ADMINISTER);
wsSupport.checkMemberSyncIsDisabled(dbSession, organization);
UserDto user = checkFound(dbClient.userDao().selectByLogin(dbSession, login), "User '%s' is not found", login);
- memberUpdater.addMember(dbSession, organization, user);
+ memberUpdater.addMember(dbSession, user);
int groups = dbClient.groupMembershipDao().countGroups(dbSession, GroupMembershipQuery.builder().membership(IN).build(), user.getUuid());
AddMemberWsResponse wsResponse = buildResponse(user, groups);
import org.sonar.api.server.ServerSide;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
-import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.user.UserSession;
-import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static org.sonar.server.exceptions.BadRequestException.checkRequest;
import static org.sonar.server.exceptions.NotFoundException.checkFound;
private final DbClient dbClient;
private final UserSession userSession;
- private final DefaultOrganizationProvider defaultOrganizationProvider;
- public QProfileWsSupport(DbClient dbClient, UserSession userSession, DefaultOrganizationProvider defaultOrganizationProvider) {
+ public QProfileWsSupport(DbClient dbClient, UserSession userSession) {
this.dbClient = dbClient;
this.userSession = userSession;
- this.defaultOrganizationProvider = defaultOrganizationProvider;
- }
-
- public OrganizationDto getDefaultOrganization(DbSession dbSession) {
- String organizationOrDefaultKey = defaultOrganizationProvider.get().getKey();
- return checkFoundWithOptional(dbClient.organizationDao().selectByKey(dbSession, organizationOrDefaultKey),
- "No organization with key '%s'", organizationOrDefaultKey);
}
public RuleDefinitionDto getRule(DbSession dbSession, RuleKey ruleKey) {
public UserDto getUser(DbSession dbSession, String login) {
UserDto user = dbClient.userDao().selectActiveUserByLogin(dbSession, login);
checkFound(user, "User with login '%s' is not found'", login);
- checkMembership(dbSession, getDefaultOrganization(dbSession), user);
return user;
}
void checkNotBuiltIn(QProfileDto profile) {
checkRequest(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s' with language '%s'", profile.getName(), profile.getLanguage());
}
-
- private void checkMembership(DbSession dbSession, OrganizationDto organization, UserDto user) {
- checkArgument(isMember(dbSession, organization, user.getUuid()), "User '%s' is not member of organization '%s'", user.getLogin(), organization.getKey());
- }
-
- private boolean isMember(DbSession dbSession, OrganizationDto organization, String userUuid) {
- return dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), userUuid).isPresent();
- }
}
dbClient.userPermissionDao().deleteByUserUuid(dbSession, userUuid);
dbClient.permissionTemplateDao().deleteUserPermissionsByUserUuid(dbSession, userUuid);
dbClient.qProfileEditUsersDao().deleteByUser(dbSession, user);
- dbClient.organizationMemberDao().deleteByUserUuid(dbSession, userUuid);
dbClient.userPropertiesDao().deleteByUser(dbSession, user);
dbClient.almPatDao().deleteByUser(dbSession, user);
dbClient.sessionTokensDao().deleteByUser(dbSession, user);
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileRules;
import org.sonar.server.qualityprofile.RuleActivation;
import org.sonar.server.tester.UserSessionRule;
private ArgumentCaptor<Collection<RuleActivation>> ruleActivationCaptor = ArgumentCaptor.forClass(Collection.class);
private DbClient dbClient = db.getDbClient();
private QProfileRules qProfileRules = mock(QProfileRules.class);
- private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
private WsActionTester ws = new WsActionTester(new ActivateRuleAction(dbClient, qProfileRules, userSession, wsSupport));
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileRules;
import org.sonar.server.rule.ws.RuleQueryFactory;
import org.sonar.server.tester.UserSessionRule;
public ExpectedException expectedException = ExpectedException.none();
private DbClient dbClient = db.getDbClient();
- private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
private RuleQueryFactory ruleQueryFactory = mock(RuleQueryFactory.class, Mockito.RETURNS_MOCKS);
private QProfileRules qProfileRules = mock(QProfileRules.class, Mockito.RETURNS_DEEP_STUBS);
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
@Rule
public DbTester db = DbTester.create();
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
private WsActionTester ws = new WsActionTester(new AddGroupAction(db.getDbClient(), uuidFactory, wsSupport, LANGUAGES));
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.TestResponse;
private DbClient dbClient = db.getDbClient();
private Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
- private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db));
+ private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
private AddProjectAction underTest = new AddProjectAction(dbClient, userSession, languages, TestComponentFinder.from(db), wsSupport);
private WsActionTester tester = new WsActionTester(underTest);
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
@Rule
public DbTester db = DbTester.create();
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db));
+ private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
private WsActionTester ws = new WsActionTester(new AddUserAction(db.getDbClient(), uuidFactory, wsSupport, LANGUAGES));
import org.sonar.db.DbTester;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileBackuperImpl;
import org.sonar.server.qualityprofile.QProfileParser;
public UserSessionRule userSession = UserSessionRule.standalone();
private QProfileBackuper backuper = new QProfileBackuperImpl(db.getDbClient(), null, null, null, new QProfileParser());
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider);
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
private Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
private WsActionTester tester = new WsActionTester(new BackupAction(db.getDbClient(), backuper, wsSupport, languages));
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileTreeImpl;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
new Languages(),
new QProfileWsSupport(
dbClient,
- userSession,
- TestDefaultOrganizationProvider.from(db)),
+ userSession),
userSession);
ws = new WsActionTester(underTest);
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.UserDto;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.ActiveRuleChange;
import org.sonar.server.qualityprofile.ActiveRuleInheritance;
import org.sonar.server.tester.UserSessionRule;
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db));
+ private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
private WsActionTester ws = new WsActionTester(new ChangelogAction(wsSupport, new Languages(), db.getDbClient()));
@Test
.setParam(PARAM_SINCE, "2011-04-25T01:15:42+0100")
.execute()
.getInput()).isSimilarTo("{\n" +
- " \"events\": [\n" +
- " {\n" +
- " \"date\": \"2011-04-25T01:15:42+0100\",\n" +
- " \"authorLogin\": \"" + user.getLogin() + "\",\n" +
- " \"action\": \"ACTIVATED\",\n" +
- " \"ruleKey\": \"" + rule.getKey() + "\",\n" +
- " \"ruleName\": \"" + rule.getName() + "\",\n" +
- " }\n" +
- " ]\n" +
- "}");
+ " \"events\": [\n" +
+ " {\n" +
+ " \"date\": \"2011-04-25T01:15:42+0100\",\n" +
+ " \"authorLogin\": \"" + user.getLogin() + "\",\n" +
+ " \"action\": \"ACTIVATED\",\n" +
+ " \"ruleKey\": \"" + rule.getKey() + "\",\n" +
+ " \"ruleName\": \"" + rule.getName() + "\",\n" +
+ " }\n" +
+ " ]\n" +
+ "}");
assertJson(ws.newRequest()
.setParam(PARAM_LANGUAGE, qualityProfile.getLanguage())
.setParam(PARAM_SINCE, "2011-04-25T01:15:43+0100")
.execute()
.getInput()).isSimilarTo("{\n" +
- " \"events\": []\n" +
- "}");
+ " \"events\": []\n" +
+ "}");
}
@Test
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileCopier;
import org.sonar.server.qualityprofile.QProfileFactory;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public JUnitTempFolder tempDir = new JUnitTempFolder();
- private ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class);
- private TestBackuper backuper = new TestBackuper();
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private QProfileFactory profileFactory = new QProfileFactoryImpl(db.getDbClient(), new SequenceUuidFactory(), System2.INSTANCE, activeRuleIndexer);
- private QProfileCopier profileCopier = new QProfileCopier(db.getDbClient(), profileFactory, backuper);
- private Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider);
- private CopyAction underTest = new CopyAction(db.getDbClient(), profileCopier, languages, userSession, wsSupport);
- private WsActionTester tester = new WsActionTester(underTest);
+ private final ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class);
+ private final TestBackuper backuper = new TestBackuper();
+ private final QProfileFactory profileFactory = new QProfileFactoryImpl(db.getDbClient(), new SequenceUuidFactory(), System2.INSTANCE, activeRuleIndexer);
+ private final QProfileCopier profileCopier = new QProfileCopier(db.getDbClient(), profileFactory, backuper);
+ private final Languages languages = LanguageTesting.newLanguages(A_LANGUAGE);
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
+ private final CopyAction underTest = new CopyAction(db.getDbClient(), profileCopier, languages, userSession, wsSupport);
+ private final WsActionTester tester = new WsActionTester(underTest);
@Test
public void test_definition() {
throw new UnsupportedOperationException();
}
- @Override public QProfileRestoreSummary copy(DbSession dbSession, QProfileDto from, QProfileDto to) {
+ @Override
+ public QProfileRestoreSummary copy(DbSession dbSession, QProfileDto from, QProfileDto to) {
this.copiedProfile = from;
this.toProfile = to;
return null;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileRules;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
private ArgumentCaptor<Collection<String>> ruleUuidsCaptor = ArgumentCaptor.forClass(Collection.class);
private DbClient dbClient = db.getDbClient();
private QProfileRules qProfileRules = mock(QProfileRules.class);
- private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
private DeactivateRuleAction underTest = new DeactivateRuleAction(dbClient, qProfileRules, userSession, wsSupport);
private WsActionTester ws = new WsActionTester(underTest);
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileRules;
import org.sonar.server.rule.ws.RuleQueryFactory;
import org.sonar.server.tester.UserSessionRule;
private DbClient dbClient = db.getDbClient();
private QProfileRules qProfileRules = mock(QProfileRules.class, RETURNS_DEEP_STUBS);
- private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
private RuleQueryFactory ruleQueryFactory = mock(RuleQueryFactory.class, RETURNS_DEEP_STUBS);
private DeactivateRulesAction underTest = new DeactivateRulesAction(ruleQueryFactory, userSession, qProfileRules, wsSupport, dbClient);
private WsActionTester ws = new WsActionTester(underTest);
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileFactoryImpl;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.tester.UserSessionRule;
private DeleteAction underTest = new DeleteAction(
new Languages(LanguageTesting.newLanguage(A_LANGUAGE)),
new QProfileFactoryImpl(dbClient, UuidFactoryFast.getInstance(), System2.INSTANCE, activeRuleIndexer), dbClient, userSession,
- new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db)));
+ new QProfileWsSupport(dbClient, userSession));
private WsActionTester ws = new WsActionTester(underTest);
@Test
import org.sonar.server.es.EsClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileRules;
import org.sonar.server.qualityprofile.QProfileRulesImpl;
import org.sonar.server.qualityprofile.QProfileTree;
private WsActionTester ws = new WsActionTester(new InheritanceAction(
dbClient,
- new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db)),
+ new QProfileWsSupport(dbClient, userSession),
new Languages()));
@Test
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import static java.lang.String.format;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private DefaultOrganizationProvider defaultOrgProvider = TestDefaultOrganizationProvider.from(db);
- private QProfileWsSupport underTest = new QProfileWsSupport(db.getDbClient(), userSession, defaultOrgProvider);
+ private final QProfileWsSupport underTest = new QProfileWsSupport(db.getDbClient(), userSession);
@Test
public void getProfile_returns_the_profile_specified_by_key() {
import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import java.util.Optional;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QProfileName;
import org.sonar.server.qualityprofile.QProfileRules;
import org.sonar.server.qualityprofile.QProfileRulesImpl;
private TypeValidations typeValidations = new TypeValidations(emptyList());
private RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, dbClient, typeValidations, userSessionRule);
private QProfileRules qProfileRules = new QProfileRulesImpl(dbClient, ruleActivator, ruleIndex, activeRuleIndexer);
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
- private QProfileWsSupport qProfileWsSupport = new QProfileWsSupport(dbClient, userSessionRule, defaultOrganizationProvider);
- private RuleQueryFactory ruleQueryFactory = new RuleQueryFactory(dbClient);
- private OrganizationDto organization;
-
- private WsActionTester wsDeactivateRule = new WsActionTester(new DeactivateRuleAction(dbClient, qProfileRules, userSessionRule, qProfileWsSupport));
- private WsActionTester wsDeactivateRules = new WsActionTester(new DeactivateRulesAction(ruleQueryFactory, userSessionRule, qProfileRules, qProfileWsSupport, dbClient));
- private WsActionTester wsActivateRule = new WsActionTester(new ActivateRuleAction(dbClient, qProfileRules, userSessionRule, qProfileWsSupport));
- private WsActionTester wsActivateRules = new WsActionTester(new ActivateRulesAction(ruleQueryFactory, userSessionRule, qProfileRules, qProfileWsSupport, dbClient));
-
- @Before
- public void setUp() {
- organization = dbTester.organizations().insert();
- }
+ private final QProfileWsSupport qProfileWsSupport = new QProfileWsSupport(dbClient, userSessionRule);
+ private final RuleQueryFactory ruleQueryFactory = new RuleQueryFactory(dbClient);
+
+ private final WsActionTester wsDeactivateRule = new WsActionTester(new DeactivateRuleAction(dbClient, qProfileRules, userSessionRule, qProfileWsSupport));
+ private final WsActionTester wsDeactivateRules = new WsActionTester(new DeactivateRulesAction(ruleQueryFactory, userSessionRule, qProfileRules, qProfileWsSupport, dbClient));
+ private final WsActionTester wsActivateRule = new WsActionTester(new ActivateRuleAction(dbClient, qProfileRules, userSessionRule, qProfileWsSupport));
+ private final WsActionTester wsActivateRules = new WsActionTester(new ActivateRulesAction(ruleQueryFactory, userSessionRule, qProfileRules, qProfileWsSupport, dbClient));
@Test
public void deactivate_rule() {
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
@Rule
public DbTester db = DbTester.create();
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
private WsActionTester ws = new WsActionTester(new RemoveGroupAction(db.getDbClient(), wsSupport, LANGUAGES));
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.TestResponse;
private DbClient dbClient = db.getDbClient();
private Languages languages = LanguageTesting.newLanguages(LANGUAGE_1, LANGUAGE_2);
- private QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, TestDefaultOrganizationProvider.from(db));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
private RemoveProjectAction underTest = new RemoveProjectAction(dbClient, userSession, languages,
new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT)), wsSupport);
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
@Rule
public DbTester db = DbTester.create();
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db));
+ private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
private WsActionTester ws = new WsActionTester(new RemoveUserAction(db.getDbClient(), wsSupport, LANGUAGES));
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
private String xoo1Key = "xoo1";
private String xoo2Key = "xoo2";
- private OrganizationDto organization;
@Before
public void setUp() {
- TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession, defaultOrganizationProvider);
+ QProfileWsSupport wsSupport = new QProfileWsSupport(dbClient, userSession);
RenameAction underTest = new RenameAction(dbClient, userSession, wsSupport);
ws = new WsActionTester(underTest);
- organization = db.organizations().getDefaultOrganization();
createProfiles();
}
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.Qualityprofiles.SearchGroupsResponse;
@Rule
public DbTester db = DbTester.create();
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
private WsActionTester ws = new WsActionTester(new SearchGroupsAction(db.getDbClient(), wsSupport, LANGUAGES));
import org.sonar.server.issue.AvatarResolverImpl;
import org.sonar.server.issue.FakeAvatarResolver;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.Qualityprofiles.SearchUsersResponse;
@Rule
public DbTester db = DbTester.create();
- private QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db));
+ private final QProfileWsSupport wsSupport = new QProfileWsSupport(db.getDbClient(), userSession);
private AvatarResolver avatarResolver = new FakeAvatarResolver();
private WsActionTester ws = new WsActionTester(new SearchUsersAction(db.getDbClient(), wsSupport, LANGUAGES, avatarResolver));
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.language.LanguageTesting;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
- private DefaultOrganizationProvider defaultOrganizationProvider;
private DbClient dbClient;
private QProfileWsSupport wsSupport;
private SetDefaultAction underTest;
private WsActionTester ws;
- private OrganizationDto organization;
/** Single, default quality profile for language xoo1 */
private QProfileDto xoo1Profile;
/** Parent quality profile for language xoo2 (not a default) */
@Before
public void setUp() {
- defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
dbClient = db.getDbClient();
- wsSupport = new QProfileWsSupport(dbClient, userSessionRule, defaultOrganizationProvider);
- organization = db.organizations().getDefaultOrganization();
+ wsSupport = new QProfileWsSupport(dbClient, userSessionRule);
underTest = new SetDefaultAction(LanguageTesting.newLanguages(XOO_1_KEY, XOO_2_KEY), dbClient, userSessionRule, wsSupport);
xoo1Profile = QualityProfileTesting.newQualityProfileDto().setLanguage(XOO_1_KEY);
import org.sonar.db.user.UserDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleIndexer;
private RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
private WsActionTester ws = new WsActionTester(
- new ShowAction(db.getDbClient(), new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db)), LANGUAGES, ruleIndex));
+ new ShowAction(db.getDbClient(), new QProfileWsSupport(db.getDbClient(), userSession), LANGUAGES, ruleIndex));
@Test
public void profile_info() {
CompareToSonarWay result = call(ws.newRequest()
.setParam(PARAM_KEY, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"))
- .getCompareToSonarWay();
+ .getCompareToSonarWay();
assertThat(result)
.extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName, CompareToSonarWay::getMissingRuleCount)
CompareToSonarWay result = call(ws.newRequest()
.setParam(PARAM_KEY, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"))
- .getCompareToSonarWay();
+ .getCompareToSonarWay();
assertThat(result)
.extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName, CompareToSonarWay::getMissingRuleCount)
CompareToSonarWay result = call(ws.newRequest()
.setParam(PARAM_KEY, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"))
- .getCompareToSonarWay();
+ .getCompareToSonarWay();
assertThat(result)
.extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName)
CompareToSonarWay result = call(ws.newRequest()
.setParam(PARAM_KEY, profile.getKee())
.setParam(PARAM_COMPARE_TO_SONAR_WAY, "true"))
- .getCompareToSonarWay();
+ .getCompareToSonarWay();
assertThat(result)
.extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName)
.forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
ws = new WsActionTester(
- new ShowAction(db.getDbClient(), new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db)), new Languages(cs), ruleIndex));
+ new ShowAction(db.getDbClient(), new QProfileWsSupport(db.getDbClient(), userSession), new Languages(cs), ruleIndex));
String result = ws.newRequest().setParam(PARAM_KEY, profile.getKee()).execute().getInput();
assertJson(result).ignoreFields("rulesUpdatedAt", "lastUsed", "userUpdatedAt").isSimilarTo(ws.getDef().responseExampleAsString());
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn();
- private TestDefaultOrganizationProvider testDefaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
+ private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
- private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
+ private final UserUpdater userUpdater = new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(),
+ new UserIndexer(db.getDbClient(), es.client()), new DefaultGroupFinder(db.getDbClient()),
+ new MapSettings().asConfig(), localAuthentication);
- private UserUpdater userUpdater = new UserUpdater(
- mock(NewUserNotifier.class), db.getDbClient(), new UserIndexer(db.getDbClient(), es.client()), testDefaultOrganizationProvider,
- new DefaultGroupFinder(db.getDbClient()),
- new MapSettings().asConfig(),
- localAuthentication);
-
- private WsActionTester tester = new WsActionTester(new ChangePasswordAction(db.getDbClient(), userUpdater, userSessionRule, localAuthentication));
+ private final WsActionTester tester = new WsActionTester(new ChangePasswordAction(db.getDbClient(), userUpdater, userSessionRule, localAuthentication));
@Before
public void setUp() {
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
-import org.sonar.core.config.CorePropertyDefinitions;
import org.sonar.db.DbTester;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.es.EsClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
public class CreateActionTest {
- private MapSettings settings = new MapSettings();
- private System2 system2 = new AlwaysIncreasingSystem2();
+ private final MapSettings settings = new MapSettings();
+ private final System2 system2 = new AlwaysIncreasingSystem2();
@Rule
public DbTester db = DbTester.create(system2);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
+ private final UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
private GroupDto defaultGroup;
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
- private WsActionTester tester = new WsActionTester(new CreateAction(
- db.getDbClient(),
- new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), userIndexer, defaultOrganizationProvider,
- new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), localAuthentication),
- userSessionRule));
+ private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
+ private final WsActionTester tester = new WsActionTester(new CreateAction(db.getDbClient(), new UserUpdater(mock(NewUserNotifier.class),
+ db.getDbClient(), userIndexer, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), localAuthentication), userSessionRule));
@Before
public void setUp() {
assertThat(dbUser).isPresent();
assertThat(dbUser.get().isRoot()).isFalse();
- // member of default group in default organization
+ // member of default group
assertThat(db.users().selectGroupUuidsOfUser(dbUser.get())).containsOnly(defaultGroup.getUuid());
}
return request.executeProtobuf(CreateWsResponse.class);
}
- private void enableCreatePersonalOrg(boolean flag) {
- settings.setProperty(CorePropertyDefinitions.ORGANIZATIONS_CREATE_PERSONAL_ORG, flag);
- }
-
}
@UseDataProvider("enterpriseAndAbove")
public void return_homepage_when_set_to_a_portfolio(EditionProvider.Edition edition) {
setPlatformEdition(edition);
- ComponentDto portfolio = db.components().insertPrivatePortfolio(db.getDefaultOrganization());
+ ComponentDto portfolio = db.components().insertPrivatePortfolio();
UserDto user = db.users().insertUser(u -> u.setHomepageType("PORTFOLIO").setHomepageParameter(portfolio.uuid()));
userSessionRule.logIn(user).addProjectPermission(USER, portfolio);
@UseDataProvider("enterpriseAndAbove")
public void return_default_when_set_to_a_portfolio_but_no_rights_on_this_portfolio(EditionProvider.Edition edition) {
setPlatformEdition(edition);
- ComponentDto portfolio = db.components().insertPrivatePortfolio(db.getDefaultOrganization());
+ ComponentDto portfolio = db.components().insertPrivatePortfolio();
UserDto user = db.users().insertUser(u -> u.setHomepageType("PORTFOLIO").setHomepageParameter(portfolio.uuid()));
userSessionRule.logIn(user);
@UseDataProvider("enterpriseAndAbove")
public void return_homepage_when_set_to_an_application(EditionProvider.Edition edition) {
setPlatformEdition(edition);
- ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPrivateApplication();
UserDto user = db.users().insertUser(u -> u.setHomepageType("APPLICATION").setHomepageParameter(application.uuid()));
userSessionRule.logIn(user).addProjectPermission(USER, application);
@UseDataProvider("enterpriseAndAbove")
public void return_default_homepage_when_set_to_an_application_but_no_rights_on_this_application(EditionProvider.Edition edition) {
setPlatformEdition(edition);
- ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPrivateApplication();
UserDto user = db.users().insertUser(u -> u.setHomepageType("APPLICATION").setHomepageParameter(application.uuid()));
userSessionRule.logIn(user);
@Test
public void fallback_when_edition_is_null() {
setPlatformEdition(null);
- ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPrivateApplication();
UserDto user = db.users().insertUser(u -> u.setHomepageType("APPLICATION").setHomepageParameter(application.uuid()));
userSessionRule.logIn(user.getLogin());
@UseDataProvider("belowEnterprise")
public void fallback_when_user_homepage_application_and_edition_below_enterprise(EditionProvider.Edition edition) {
setPlatformEdition(edition);
- ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization());
+ ComponentDto application = db.components().insertPrivateApplication();
UserDto user = db.users().insertUser(u -> u.setHomepageType("APPLICATION").setHomepageParameter(application.uuid()));
userSessionRule.logIn(user.getLogin());
UserDto user = db.users().insertUser();
userSession
.logIn(user)
- // permissions on default organization
.addPermission(SCAN)
.addPermission(ADMINISTER_QUALITY_PROFILES);
import java.util.Optional;
import javax.annotation.Nullable;
-import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.alm.setting.AlmSettingDto;
import org.sonar.db.ce.CeTaskMessageType;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.permission.template.PermissionTemplateUserDto;
import org.sonar.db.project.ProjectDto;
assertThat(db.getDbClient().propertiesDao().selectByQuery(PropertyQuery.builder().build(), db.getSession())).extracting(PropertyDto::getKey).containsOnly("other");
}
- @Test
- public void deactivate_user_deletes_his_organization_membership() {
- createAdminUser();
- logInAsSystemAdministrator();
- UserDto user = db.users().insertUser();
- OrganizationDto organization = db.organizations().insert();
- db.organizations().addMember(organization, user);
- OrganizationDto anotherOrganization = db.organizations().insert();
- db.organizations().addMember(anotherOrganization, user);
-
- deactivate(user.getLogin());
-
- assertThat(dbClient.organizationMemberDao().select(db.getSession(), organization.getUuid(), user.getUuid())).isNotPresent();
- assertThat(dbClient.organizationMemberDao().select(db.getSession(), anotherOrganization.getUuid(), user.getUuid())).isNotPresent();
- }
-
@Test
public void deactivate_user_deletes_his_user_settings() {
createAdminUser();
@Test
public void administrators_can_be_deactivated_if_there_are_still_other_administrators() {
- UserDto admin = createAdminUser();;
+ UserDto admin = createAdminUser();
+ ;
UserDto anotherAdmin = createAdminUser();
logInAsSystemAdministrator();
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.UnauthorizedException;
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DbClient dbClient = db.getDbClient();
-
- private WsActionTester ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db)));
+ private final DbClient dbClient = db.getDbClient();
+ private final WsActionTester ws = new WsActionTester(new SetHomepageAction(userSession, dbClient, TestComponentFinder.from(db)));
@Test
public void verify_definition() {
@Test
public void set_project_homepage() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
UserDto user = db.users().insertUser();
userSession.logIn(user);
@Test
public void set_branch_homepage() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPublicProject(organization);
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project);
UserDto user = db.users().insertUser();
userSession.logIn(user);
@Test
public void set_portfolio_homepage() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto portfolio = db.components().insertPrivatePortfolio(organization);
+ ComponentDto portfolio = db.components().insertPrivatePortfolio();
UserDto user = db.users().insertUser();
userSession.logIn(user);
@Test
public void set_application_homepage() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto application = db.components().insertPrivateApplication(organization);
+ ComponentDto application = db.components().insertPrivateApplication();
UserDto user = db.users().insertUser();
userSession.logIn(user);
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.UserUpdater;
public class UpdateActionTest {
- private MapSettings settings = new MapSettings();
- private System2 system2 = new System2();
+ private final MapSettings settings = new MapSettings();
+ private final System2 system2 = new System2();
@Rule
public DbTester db = DbTester.create(system2);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DbClient dbClient = db.getDbClient();
- private DbSession dbSession = db.getSession();
- private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
- private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
-
- private WsActionTester ws = new WsActionTester(new UpdateAction(
- new UserUpdater(mock(NewUserNotifier.class), dbClient, userIndexer, defaultOrganizationProvider,
- new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), localAuthentication),
+ private final DbClient dbClient = db.getDbClient();
+ private final DbSession dbSession = db.getSession();
+ private final UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
+ private final CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient());
+ private final WsActionTester ws = new WsActionTester(new UpdateAction(
+ new UserUpdater(mock(NewUserNotifier.class), dbClient, userIndexer, new DefaultGroupFinder(db.getDbClient()), settings.asConfig(), localAuthentication),
userSession, new UserJsonWriter(userSession), dbClient));
@Before
public class UpdateLoginActionTest {
- private System2 system2 = new System2();
+ private final System2 system2 = new System2();
@Rule
public DbTester db = DbTester.create(system2);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private WsActionTester ws = new WsActionTester(new UpdateLoginAction(db.getDbClient(), userSession,
- new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), new UserIndexer(db.getDbClient(), es.client()),
- null,null, null, null)));
+ private final WsActionTester ws = new WsActionTester(new UpdateLoginAction(db.getDbClient(), userSession,
+ new UserUpdater(mock(NewUserNotifier.class), db.getDbClient(), new UserIndexer(db.getDbClient(), es.client()), null, null, null)));
@Test
public void update_login_from_sonarqube_account_when_user_is_local() {
public static final String SONAR_ANALYSIS = "sonar.analysis.";
private static final String CATEGORY_ORGANIZATIONS = "organizations";
+
+ //TODO remove
+ @Deprecated
public static final String ORGANIZATIONS_ANYONE_CAN_CREATE = "sonar.organizations.anyoneCanCreate";
+
+ //TODO remove
+ @Deprecated
public static final String ORGANIZATIONS_CREATE_PERSONAL_ORG = "sonar.organizations.createPersonalOrg";
public static final String DISABLE_NOTIFICATION_ON_BUILT_IN_QPROFILES = "sonar.builtInQualityProfiles.disableNotificationOnUpdate";
.category(CATEGORY_ORGANIZATIONS)
.type(BOOLEAN)
.hidden()
- .build(),
- PropertyDefinition.builder(ORGANIZATIONS_CREATE_PERSONAL_ORG)
- .name("Create an organization for each new user.")
- .defaultValue(Boolean.toString(false))
- .category(CATEGORY_ORGANIZATIONS)
- .type(BOOLEAN)
- .hidden()
.build()));
return defs;
}
@Test
public void all() {
List<PropertyDefinition> defs = CorePropertyDefinitions.all();
- assertThat(defs).hasSize(56);
+ assertThat(defs).hasSize(55);
}
@Test