import java.util.Arrays;
public enum CreationMethod {
- UNKNOWN(Category.UNKNOWN, false),
- LOCAL_API(Category.LOCAL, false),
- LOCAL_BROWSER(Category.LOCAL, true),
- ALM_IMPORT_API(Category.ALM_IMPORT, false),
- ALM_IMPORT_BROWSER(Category.ALM_IMPORT, true),
- SCANNER_API(Category.SCANNER, false),
- SCANNER_API_DEVOPS_AUTO_CONFIG(Category.SCANNER, false);
+ UNKNOWN(Category.UNKNOWN, false, true),
+ LOCAL_API(Category.LOCAL, false, true),
+ LOCAL_BROWSER(Category.LOCAL, true, true),
+ ALM_IMPORT_API(Category.ALM_IMPORT, false, false),
+ ALM_IMPORT_BROWSER(Category.ALM_IMPORT, true, false),
+ SCANNER_API(Category.SCANNER, false, true),
+ SCANNER_API_DEVOPS_AUTO_CONFIG(Category.SCANNER, false, false);
- private final boolean isCreatedViaBrowser;
private final Category category;
+ private final boolean isCreatedViaBrowser;
+ private final boolean isLocal;
- CreationMethod(Category category, boolean isCreatedViaBrowser) {
+ CreationMethod(Category category, boolean isCreatedViaBrowser, boolean isLocal) {
this.isCreatedViaBrowser = isCreatedViaBrowser;
this.category = category;
+ this.isLocal = isLocal;
}
public static CreationMethod getCreationMethod(Category category, boolean isBrowserCall) {
return category;
}
+ public boolean isLocal() {
+ return isLocal;
+ }
+
public enum Category {UNKNOWN, LOCAL, ALM_IMPORT, SCANNER}
}
import org.sonar.server.almsettings.ws.GithubProjectCreationParameters;
import org.sonar.server.almsettings.ws.GithubProjectCreator;
import org.sonar.server.almsettings.ws.GithubProjectCreatorFactory;
-import org.sonar.server.project.ws.ProjectCreator;
import org.sonar.server.component.ComponentUpdater;
import org.sonar.server.es.TestIndexers;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.project.DefaultBranchNameResolver;
import org.sonar.server.project.ProjectDefaultVisibility;
import org.sonar.server.project.Visibility;
+import org.sonar.server.project.ws.ProjectCreator;
import org.sonar.server.tester.UserSessionRule;
import static java.lang.String.format;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
underTest.submit(PROJECT_KEY, PROJECT_NAME, emptyMap(), IOUtils.toInputStream("{binary}", UTF_8));
- assertLocalProjectWasCreated();
+ ProjectDto projectDto = assertLocalProjectWasCreated();
+ verify(permissionTemplateService).applyDefaultToNewComponent(any(DbSession.class), eq(projectDto), eq(userSession.getUuid()));
}
@Test
underTest.submit(PROJECT_KEY, PROJECT_NAME, CHARACTERISTICS, IOUtils.toInputStream("{binary}", UTF_8));
assertProjectWasCreatedWithBinding();
+ verify(permissionTemplateService, never()).applyDefaultToNewComponent(any(), any(), any());
}
@Test
underTest.submit(PROJECT_KEY, PROJECT_NAME, CHARACTERISTICS, IOUtils.toInputStream("{binary}", UTF_8));
assertProjectWasCreatedWithBinding();
+ verify(permissionTemplateService, never()).applyDefaultToNewComponent(any(), any(), any());
}
@Test
mockSuccessfulPrepareSubmitCall();
underTest.submit(PROJECT_KEY, PROJECT_NAME, CHARACTERISTICS, IOUtils.toInputStream("{binary}", UTF_8));
- assertLocalProjectWasCreated();
+ ProjectDto projectDto = assertLocalProjectWasCreated();
+ verify(permissionTemplateService).applyDefaultToNewComponent(any(DbSession.class), eq(projectDto), eq(userSession.getUuid()));
}
- private void assertLocalProjectWasCreated() {
+ private ProjectDto assertLocalProjectWasCreated() {
ProjectDto projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), PROJECT_KEY).orElseThrow();
assertThat(projectDto.getCreationMethod()).isEqualTo(CreationMethod.SCANNER_API);
assertThat(projectDto.getName()).isEqualTo(PROJECT_NAME);
assertThat(branchDto.isMain()).isTrue();
assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.getUuid())).isEmpty();
+ return projectDto;
}
@Test
import javax.annotation.Nullable;
import org.sonar.alm.client.github.AppInstallationToken;
import org.sonar.alm.client.github.GithubApplicationClient;
+import org.sonar.alm.client.github.GithubPermissionConverter;
import org.sonar.alm.client.github.api.GsonRepositoryCollaborator;
import org.sonar.alm.client.github.api.GsonRepositoryTeam;
import org.sonar.alm.client.github.security.AccessToken;
import org.sonar.api.web.UserRole;
-import org.sonar.alm.client.github.GithubPermissionConverter;
import org.sonar.auth.github.GsonRepositoryPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.server.almsettings.ws.DevOpsProjectCreator;
import org.sonar.server.almsettings.ws.DevOpsProjectCreatorFactory;
-import org.sonar.server.project.ws.ProjectCreator;
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.management.ManagedInstanceService;
import org.sonar.server.permission.PermissionTemplateService;
+import org.sonar.server.project.ws.ProjectCreator;
import org.sonar.server.user.UserSession;
import static java.lang.String.format;
.userLogin(userSession.getLogin())
.userUuid(userSession.getUuid())
.mainBranchName(mainBranchName)
- .isManaged(managedInstanceService.isInstanceExternallyManaged())
+ .isManaged(managedInstanceService.isInstanceExternallyManaged() && !creationMethod.isLocal())
.creationMethod(creationMethod)
.build();
return componentUpdater.createWithoutCommit(dbSession, componentCreationParameters);