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());
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);