From: Julien Lancelot Date: Mon, 23 Nov 2015 14:26:36 +0000 (+0100) Subject: SONAR-7027 Add method to create a developer X-Git-Tag: 5.3-RC1~189 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F651%2Fhead;p=sonarqube.git SONAR-7027 Add method to create a developer No permission check must be done Key should allow any characters No need to delete duplicated entries --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java index 1d342e65da1..b4396bbee01 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java @@ -157,13 +157,22 @@ public class ComponentService { public ComponentDto create(DbSession session, NewComponent newComponent) { userSession.checkGlobalPermission(GlobalPermissions.PROVISIONING); + checkKeyFormat(newComponent.qualifier(), newComponent.key()); ComponentDto project = createProject(session, newComponent); removeDuplicatedProjects(session, project.getKey()); return project; } + /** + * No permission check must be done when inserting a new developer as it's done on Compute Engine side. + * No check must be done on the key + * No need to remove duplicated components as it's not possible to create the same developer twice in the same time. + */ + public ComponentDto createDeveloper(DbSession session, NewComponent newComponent) { + return createProject(session, newComponent); + } + private ComponentDto createProject(DbSession session, NewComponent newComponent) { - checkKeyFormat(newComponent.qualifier(), newComponent.key()); checkBranchFormat(newComponent.qualifier(), newComponent.branch()); String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.branch()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java index a00ad986005..804faa8ac2b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java @@ -327,6 +327,28 @@ public class ComponentServiceTest { assertThat(project.getCreatedAt()).isNotNull(); } + @Test + public void create_developer() throws Exception { + // No permission should be required to create a developer + userSessionRule.anonymous(); + + String key = service.createDeveloper(dbTester.getSession(), NewComponent.create("DEV:jon.name@mail.com", "John").setQualifier("DEV")).getKey(); + dbTester.getSession().commit(); + + ComponentDto dev = service.getNullableByKey(key); + assertThat(dev.key()).isEqualTo("DEV:jon.name@mail.com"); + assertThat(dev.deprecatedKey()).isEqualTo("DEV:jon.name@mail.com"); + assertThat(dev.uuid()).isNotNull(); + assertThat(dev.projectUuid()).isEqualTo(dev.uuid()); + assertThat(dev.moduleUuid()).isNull(); + assertThat(dev.moduleUuidPath()).isEqualTo("." + dev.uuid() + "."); + assertThat(dev.name()).isEqualTo("John"); + assertThat(dev.longName()).isEqualTo("John"); + assertThat(dev.scope()).isEqualTo("PRJ"); + assertThat(dev.qualifier()).isEqualTo("DEV"); + assertThat(dev.getCreatedAt()).isNotNull(); + } + @Test public void fail_to_create_new_component_on_invalid_key() { userSessionRule.login("john").setGlobalPermissions(PROVISIONING);