import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.component.BranchMapper;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentMapper;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.GroupPermissionDto;
import org.sonar.db.permission.UserPermissionDto;
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, component.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException(format("Could not find organization with uuid '%s' of project '%s'", component.getOrganizationUuid(), projectKey)));
projectsWsSupport.checkCanUpdateProjectsVisibility(organization, changeToPrivate);
- dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, component.uuid(), changeToPrivate);
+ setPrivateForRootComponentUuid(dbSession, component.uuid(), changeToPrivate);
if (changeToPrivate) {
updatePermissionsToPrivate(dbSession, component);
} else {
}
}
+ private void setPrivateForRootComponentUuid(DbSession dbSession, String uuid, boolean isPrivate) {
+ dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate);
+ ComponentMapper mapper = dbSession.getMapper(ComponentMapper.class);
+ dbSession.getMapper(BranchMapper.class).selectByProjectUuid(uuid)
+ .stream()
+ .filter(branch -> !uuid.equals(branch.getUuid()))
+ .forEach(branch -> mapper.setPrivateForRootComponentUuid(branch.getUuid(), isPrivate));
+ }
+
private boolean noPendingTask(DbSession dbSession, ComponentDto rootComponent) {
return dbClient.ceQueueDao().selectByComponentUuid(dbSession, rootComponent.uuid()).isEmpty();
}
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.ce.CeQueueDto;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
public void execute_changes_private_flag_of_specified_project_and_all_children_to_specified_new_visibility() {
ComponentDto project = randomPublicOrPrivateProject();
boolean initiallyPrivate = project.isPrivate();
+
+ BranchDto branchDto = ComponentTesting.newBranchDto(project);
+ dbClient.branchDao().insert(dbSession, branchDto);
+
+ ComponentDto branch = ComponentTesting.newProjectBranch(project, branchDto);
ComponentDto module = ComponentTesting.newModuleDto(project);
ComponentDto dir = ComponentTesting.newDirectory(project, "path");
ComponentDto file = ComponentTesting.newFileDto(project);
- dbTester.components().insertComponents(module, dir, file);
+
+ dbTester.components().insertComponents(branch, module, dir, file);
userSessionRule.addProjectPermission(UserRole.ADMIN, project);
request.setParam(PARAM_PROJECT, project.getDbKey())
.execute();
assertThat(isPrivateInDb(project)).isEqualTo(!initiallyPrivate);
+ assertThat(isPrivateInDb(branch)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(module)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(dir)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(file)).isEqualTo(!initiallyPrivate);
public void execute_has_no_effect_if_specified_project_already_has_specified_visibility() {
ComponentDto project = randomPublicOrPrivateProject();
boolean initiallyPrivate = project.isPrivate();
+
+ BranchDto branchDto = ComponentTesting.newBranchDto(project);
+ dbClient.branchDao().insert(dbSession, branchDto);
+
+ ComponentDto branch = ComponentTesting.newProjectBranch(project, branchDto)
+ .setPrivate(initiallyPrivate);
ComponentDto module = ComponentTesting.newModuleDto(project)
.setPrivate(initiallyPrivate);
ComponentDto dir = ComponentTesting.newDirectory(project, "path")
.setPrivate(!initiallyPrivate);
ComponentDto file = ComponentTesting.newFileDto(project)
.setPrivate(initiallyPrivate);
- dbTester.components().insertComponents(module, dir, file);
+ dbTester.components().insertComponents(branch, module, dir, file);
userSessionRule.addProjectPermission(UserRole.ADMIN, project);
request.setParam(PARAM_PROJECT, project.getDbKey())
.execute();
assertThat(isPrivateInDb(project)).isEqualTo(initiallyPrivate);
+ assertThat(isPrivateInDb(branch)).isEqualTo(initiallyPrivate);
assertThat(isPrivateInDb(module)).isEqualTo(initiallyPrivate);
assertThat(isPrivateInDb(dir)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(file)).isEqualTo(initiallyPrivate);