private void removeMember(DbSession dbSession, OrganizationDto organization, UserDto user) { ensureLastAdminIsNotRemoved(dbSession, organization, user); int userId = user.getId(); String organizationUuid = organization.getUuid(); dbClient.userPermissionDao().deleteOrganizationMemberPermissions(dbSession, organizationUuid, userId); dbClient.permissionTemplateDao().deleteUserPermissionsByOrganization(dbSession, organizationUuid, userId); dbClient.qProfileEditUsersDao().deleteByOrganizationAndUser(dbSession, organization, user); dbClient.userGroupDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userId); dbClient.propertiesDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userId); dbClient.propertiesDao().deleteByOrganizationAndMatchingLogin(dbSession, organizationUuid, user.getLogin(), singletonList(DEFAULT_ISSUE_ASSIGNEE)); dbClient.organizationMemberDao().delete(dbSession, organizationUuid, userId); userIndexer.commitAndIndex(dbSession, user); }
@Test public void delete_by_organization_and_user() { OrganizationDto organization = db.organizations().insert(); OrganizationDto anotherOrganization = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organization); ComponentDto anotherProject = db.components().insertPrivateProject(anotherOrganization); UserDto user = db.users().insertUser(); UserDto anotherUser = db.users().insertUser(); insertProperty("KEY_11", "VALUE", project.getId(), user.getId()); insertProperty("KEY_12", "VALUE", project.getId(), user.getId()); insertProperty("KEY_11", "VALUE", project.getId(), anotherUser.getId()); insertProperty("KEY_11", "VALUE", anotherProject.getId(), user.getId()); underTest.deleteByOrganizationAndUser(session, organization.getUuid(), user.getId()); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(project.getId()).build(), session)) .hasSize(1) .extracting(PropertyDto::getUserId).containsOnly(anotherUser.getId()); assertThat(dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setComponentId(anotherProject.getId()).build(), session)).extracting(PropertyDto::getUserId) .hasSize(1).containsOnly(user.getId()); }
private void removeMember(DbSession dbSession, OrganizationDto organization, UserDto user) { ensureLastAdminIsNotRemoved(dbSession, organization, user); int userId = user.getId(); String organizationUuid = organization.getUuid(); dbClient.userPermissionDao().deleteOrganizationMemberPermissions(dbSession, organizationUuid, userId); dbClient.permissionTemplateDao().deleteUserPermissionsByOrganization(dbSession, organizationUuid, userId); dbClient.qProfileEditUsersDao().deleteByOrganizationAndUser(dbSession, organization, user); dbClient.userGroupDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userId); dbClient.propertiesDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userId); dbClient.propertiesDao().deleteByOrganizationAndMatchingLogin(dbSession, organizationUuid, user.getLogin(), singletonList(DEFAULT_ISSUE_ASSIGNEE)); dbClient.organizationMemberDao().delete(dbSession, organizationUuid, userId); userIndexer.commitAndIndex(dbSession, user); }