]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7027 Add method to create a developer 651/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 23 Nov 2015 14:26:36 +0000 (15:26 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 24 Nov 2015 10:43:33 +0000 (11:43 +0100)
No permission check must be done
Key should allow any characters
No need to delete duplicated entries

server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java

index 1d342e65da18cf3b6bfdb5bcb3aebb67b50a62e5..b4396bbee01c3807054b2c7012bda5086860d69b 100644 (file)
@@ -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());
 
index a00ad986005d89d0c010f1e873cde73a17e27e9c..804faa8ac2b2c22ba4477a236a757f0dd824cd66 100644 (file)
@@ -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);