boolean hasBrowsePerm = userSession.hasComponentUuidPermission(USER, module.projectUuid());
checkPermission(query.isIssuesMode(), hasScanPerm, hasBrowsePerm);
- // Scan permission is enough to analyze all projects but browse permission is limited to projects user can access
- if (query.isIssuesMode() && !userSession.hasComponentUuidPermission(USER, module.projectUuid())) {
- throw new ForbiddenException("You're not authorized to access to project '" + module.name() + "', please contact your SonarQube administrator.");
- }
-
ComponentDto project = getProject(module, session);
if (!project.key().equals(module.key())) {
addSettings(data, module.getKey(), getSettingsFromParents(module, hasScanPerm, session));
"Please contact your SonarQube administrator.");
}
if (preview && !hasBrowsePerm) {
- throw new ForbiddenException("You're not authorized to execute a preview analysis. Please contact your SonarQube administrator.");
+ throw new ForbiddenException("You don't have the required permissions to access this project. Please contact your SonarQube administrator.");
}
}
import org.sonar.api.web.UserRole;
import org.sonar.batch.protocol.input.FileData;
import org.sonar.batch.protocol.input.ProjectRepositories;
+import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
underTest.load(ProjectDataQuery.create().setModuleKey(project.key()).setIssuesMode(false));
}
+ @Test
+ public void fail_when_preview_and_only_scan_permission_without_browse_permission() {
+ ComponentDto project = ComponentTesting.newProjectDto();
+ tester.get(DbClient.class).componentDao().insert(dbSession, project);
+ dbSession.commit();
+
+ userSessionRule.login("john").addProjectUuidPermissions(GlobalPermissions.SCAN_EXECUTION, project.projectUuid());
+
+ thrown.expect(ForbiddenException.class);
+ thrown.expectMessage("You don't have the required permissions to access this project. Please contact your SonarQube administrator.");
+ underTest.load(ProjectDataQuery.create().setModuleKey(project.key()).setIssuesMode(true));
+ }
+
@Test
public void return_file_data_from_single_project() {
ComponentDto project = ComponentTesting.newProjectDto();