Skip to content

Commit

Permalink
EPMRPP-94686 restrict same project name per organization
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Sep 4, 2024
1 parent 435ddda commit 3b92efa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies {
implementation 'com.epam.reportportal:commons'
implementation 'com.epam.reportportal:plugin-api:5.11.1'
} else {
implementation 'com.github.reportportal:commons-dao:c5ebfac'
implementation 'com.github.reportportal:commons-dao:69da66d'
implementation 'com.github.reportportal:commons:7f23a5f'
implementation 'com.github.reportportal:plugin-api:d1c0f0e'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ public OrganizationProjectInfo createProject(Long orgId, ProjectDetails projectD
}
var projectKey = organization.getSlug() + "." + projectDetails.getSlug();

Optional<Project> existProject = projectRepository.findByKey(projectKey);
Optional<Project> existProject =
projectRepository.findByNameAndOrganizationId(projectDetails.getName(), orgId);
expect(existProject, not(isPresent())).verify(ErrorType.PROJECT_ALREADY_EXISTS, projectKey);

var projectToSave = generateProjectBody(orgId, projectDetails, projectKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.epam.reportportal.api.model.OffsetRequest.OrderEnum;
import com.epam.reportportal.api.model.OrganizationProfilesPage;
import com.epam.reportportal.api.model.OrganizationProjectsPage;
import com.epam.reportportal.api.model.SearchCriteriaRQ;
import com.epam.reportportal.api.model.SearchCriteriaSearchCriteria;
Expand Down Expand Up @@ -144,4 +143,23 @@ void createProject(String name, String slug, String expectSlug) throws Exception
.andExpect(jsonPath("$.slug").value(expectSlug));
}


@Test
void createDuplicateProjectFails() throws Exception {
JsonObject jsonBody = new JsonObject();
jsonBody.addProperty("name", "uniq_name_123");

mockMvc.perform(post("/organizations/1/projects")
.contentType(MediaType.APPLICATION_JSON)
.with(token(oAuthHelper.getSuperadminToken()))
.content(jsonBody.toString()))
.andExpect(status().isOk());

mockMvc.perform(post("/organizations/1/projects")
.contentType(MediaType.APPLICATION_JSON)
.with(token(oAuthHelper.getSuperadminToken()))
.content(jsonBody.toString()))
.andExpect(status().is4xxClientError());
}

}

0 comments on commit 3b92efa

Please sign in to comment.