use of net.nemerosa.ontrack.model.structure.Project in project ontrack by nemerosa.
the class ValidationStampFilterJdbcRepositoryIT method new_filter_with_both_project_and_branch.
@Test(expected = IllegalStateException.class)
public void new_filter_with_both_project_and_branch() {
Project project = Project.of(NameDescription.nd("P", ""));
filterRepository.newValidationStampFilter(ValidationStampFilter.builder().name("My filter").project(project).branch(Branch.of(project, NameDescription.nd("B", ""))).vsNames(Collections.singletonList("CI")).build());
}
use of net.nemerosa.ontrack.model.structure.Project in project ontrack by nemerosa.
the class SecurityServiceIT method read_only_on_all_projects.
@Test
public void read_only_on_all_projects() throws Exception {
withNoGrantViewToAll(() -> {
// Creates two projects
Project p1 = doCreateProject();
Project p2 = doCreateProject();
// Creates an account authorised to access all projects
Account account = doCreateAccountWithGlobalRole("READ_ONLY");
return asAccount(account).call(() -> {
// With this account, gets the list of projects
List<Project> list = structureService.getProjectList();
// Checks we only have the two projects (among all others)
assertTrue(list.size() >= 2);
assertTrue(list.stream().anyMatch(project -> StringUtils.equals(p1.getName(), project.getName())));
assertTrue(list.stream().anyMatch(project -> StringUtils.equals(p2.getName(), project.getName())));
// Access to the projects
assertTrue(structureService.findProjectByName(p1.getName()).isPresent());
assertNotNull(structureService.getProject(p1.getId()));
assertTrue(structureService.findProjectByName(p2.getName()).isPresent());
assertNotNull(structureService.getProject(p2.getId()));
// OK
return true;
});
});
}
use of net.nemerosa.ontrack.model.structure.Project in project ontrack by nemerosa.
the class SecurityServiceIT method read_only_on_one_project.
@Test
public void read_only_on_one_project() throws Exception {
withNoGrantViewToAll(() -> {
// Creates two projects
Project p1 = doCreateProject();
Project p2 = doCreateProject();
// Creates an account authorised to access only one project
Account account = doCreateAccountWithProjectRole(p2, "READ_ONLY");
return asAccount(account).call(() -> {
// With this account, gets the list of projects
List<Project> list = structureService.getProjectList();
// Checks we only have one project
assertEquals(1, list.size());
assertEquals(p2.getName(), list.get(0).getName());
// Access to the authorised project
assertTrue(structureService.findProjectByName(p2.getName()).isPresent());
assertNotNull(structureService.getProject(p2.getId()));
// No access to the other project
assertFalse(structureService.findProjectByName(p1.getName()).isPresent());
try {
structureService.getProject(p1.getId());
fail("Project is not authorised");
} catch (AccessDeniedException ignored) {
assertTrue("Project cannot be found", true);
}
// OK
return true;
});
});
}
use of net.nemerosa.ontrack.model.structure.Project in project ontrack by nemerosa.
the class ConfigurationServiceIT method configuration_property_removed_on_configuration_deleted.
/**
* Checks that configuration properties are removed when an associated configuration is deleted.
*/
@Test
public void configuration_property_removed_on_configuration_deleted() throws Exception {
// Creates two configurations
String conf1Name = uid("C");
String conf2Name = uid("C");
TestConfiguration conf1 = asUser().with(GlobalSettings.class).call(() -> configurationService.newConfiguration(config(conf1Name)));
TestConfiguration conf2 = asUser().with(GlobalSettings.class).call(() -> configurationService.newConfiguration(config(conf2Name)));
// Creates two projects
Project p1 = doCreateProject();
Project p2 = doCreateProject();
// Sets the properties
asUser().with(p1, ProjectEdit.class).call(() -> propertyService.editProperty(p1, TestPropertyType.class, TestProperty.of(conf1, "1")));
asUser().with(p2, ProjectEdit.class).call(() -> propertyService.editProperty(p2, TestPropertyType.class, TestProperty.of(conf2, "2")));
// Assert the properties are there
asUser().with(p1, ProjectView.class).execute(() -> assertTrue(propertyService.hasProperty(p1, TestPropertyType.class)));
asUser().with(p2, ProjectView.class).execute(() -> assertTrue(propertyService.hasProperty(p2, TestPropertyType.class)));
// Deletes the first configuration
asUser().with(GlobalSettings.class).execute(() -> configurationService.deleteConfiguration(conf1Name));
// Checks the property 1 is gone
asUser().with(p1, ProjectView.class).execute(() -> assertFalse("Project configuration should be gone", propertyService.hasProperty(p1, TestPropertyType.class)));
// ... but not the second one
asUser().with(p2, ProjectView.class).execute(() -> assertTrue(propertyService.hasProperty(p2, TestPropertyType.class)));
}
use of net.nemerosa.ontrack.model.structure.Project in project ontrack by nemerosa.
the class GQLRootQueryBranches method branchFetcher.
private DataFetcher branchFetcher() {
return environment -> {
Integer id = environment.getArgument("id");
String projectName = environment.getArgument("project");
String name = environment.getArgument("name");
Object propertyFilterArg = environment.getArgument(GQLInputPropertyFilter.ARGUMENT_NAME);
// Per ID
if (id != null) {
checkArgList(environment, "id");
return Collections.singletonList(structureService.getBranch(ID.of(id)));
} else // Per project name, name or property filter
if (isNotBlank(projectName) || isNotBlank(name) || propertyFilterArg != null) {
// Project filter
Predicate<Project> projectFilter = p -> true;
if (isNotBlank(projectName)) {
projectFilter = projectFilter.and(project -> StringUtils.equals(projectName, project.getName()));
}
// Branch filter
Predicate<Branch> branchFilter = b -> true;
if (isNotBlank(name)) {
Pattern pattern = Pattern.compile(name);
branchFilter = branchFilter.and(b -> pattern.matcher(b.getName()).matches());
}
// Property filter?
if (propertyFilterArg != null) {
PropertyFilter filterObject = propertyFilter.convert(propertyFilterArg);
if (filterObject != null && StringUtils.isNotBlank(filterObject.getType())) {
branchFilter = branchFilter.and(propertyFilter.getFilter(filterObject));
}
}
// Gets the list of authorised projects
return structureService.getProjectList().stream().filter(projectFilter).flatMap(project -> structureService.getBranchesForProject(project.getId()).stream()).filter(branchFilter).collect(Collectors.toList());
} else // No result to return
{
return Collections.emptyList();
}
};
}
Aggregations