Search in sources :

Example 1 with Project

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());
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) Test(org.junit.Test)

Example 2 with Project

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;
        });
    });
}
Also used : ProjectCreation(net.nemerosa.ontrack.model.security.ProjectCreation) Account(net.nemerosa.ontrack.model.security.Account) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) AccessDeniedException(org.springframework.security.access.AccessDeniedException) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) List(java.util.List) AbstractServiceTestSupport(net.nemerosa.ontrack.it.AbstractServiceTestSupport) Authentication(org.springframework.security.core.Authentication) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Assert(org.junit.Assert) Project(net.nemerosa.ontrack.model.structure.Project) Project(net.nemerosa.ontrack.model.structure.Project) Account(net.nemerosa.ontrack.model.security.Account) Test(org.junit.Test)

Example 3 with Project

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;
        });
    });
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) Account(net.nemerosa.ontrack.model.security.Account) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Example 4 with Project

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)));
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) TestPropertyType(net.nemerosa.ontrack.extension.api.support.TestPropertyType) TestConfiguration(net.nemerosa.ontrack.extension.api.support.TestConfiguration) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) ProjectView(net.nemerosa.ontrack.model.security.ProjectView) ProjectEdit(net.nemerosa.ontrack.model.security.ProjectEdit) Test(org.junit.Test)

Example 5 with Project

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();
        }
    };
}
Also used : GraphQLString(graphql.Scalars.GraphQLString) StructureService(net.nemerosa.ontrack.model.structure.StructureService) Predicate(java.util.function.Predicate) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) Autowired(org.springframework.beans.factory.annotation.Autowired) GraphQLArgument.newArgument(graphql.schema.GraphQLArgument.newArgument) GraphqlUtils.stdList(net.nemerosa.ontrack.graphql.support.GraphqlUtils.stdList) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) GraphQLFieldDefinition.newFieldDefinition(graphql.schema.GraphQLFieldDefinition.newFieldDefinition) GraphqlUtils.checkArgList(net.nemerosa.ontrack.graphql.support.GraphqlUtils.checkArgList) Component(org.springframework.stereotype.Component) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) DataFetcher(graphql.schema.DataFetcher) GraphQLInt(graphql.Scalars.GraphQLInt) Pattern(java.util.regex.Pattern) Project(net.nemerosa.ontrack.model.structure.Project) Collections(java.util.Collections) ID(net.nemerosa.ontrack.model.structure.ID) Branch(net.nemerosa.ontrack.model.structure.Branch) Project(net.nemerosa.ontrack.model.structure.Project) Pattern(java.util.regex.Pattern) Branch(net.nemerosa.ontrack.model.structure.Branch) GraphQLString(graphql.Scalars.GraphQLString)

Aggregations

Project (net.nemerosa.ontrack.model.structure.Project)16 Test (org.junit.Test)13 Branch (net.nemerosa.ontrack.model.structure.Branch)5 NameDescription (net.nemerosa.ontrack.model.structure.NameDescription)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HttpOutputMessage (org.springframework.http.HttpOutputMessage)3 IntNode (com.fasterxml.jackson.databind.node.IntNode)2 IOException (java.io.IOException)2 LocalDateTime (java.time.LocalDateTime)2 Account (net.nemerosa.ontrack.model.security.Account)2 ID (net.nemerosa.ontrack.model.structure.ID)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 GraphQLInt (graphql.Scalars.GraphQLInt)1 GraphQLString (graphql.Scalars.GraphQLString)1 DataFetcher (graphql.schema.DataFetcher)1 GraphQLArgument.newArgument (graphql.schema.GraphQLArgument.newArgument)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1