Search in sources :

Example 31 with Branch

use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.

the class BuildFilterServiceIT method copyToBranch.

@Test
public void copyToBranch() throws Exception {
    // Source branch
    Branch sourceBranch = doCreateBranch();
    // Target branch
    Branch targetBranch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    // Creates a filter for this account
    Ack filterCreated = asAccount(account).call(() -> buildFilterService.saveFilter(sourceBranch.getId(), false, "MyFilter", StandardBuildFilterProvider.class.getName(), JsonUtils.object().with("count", 1).end()));
    assertTrue(filterCreated.isSuccess());
    // Checks the filter is created
    Collection<BuildFilterResource<?>> filters = asAccount(account).with(sourceBranch.projectId(), ProjectView.class).call(() -> buildFilterService.getBuildFilters(sourceBranch.getId()));
    assertEquals(1, filters.size());
    BuildFilterResource<?> filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertEquals(StandardBuildFilterProvider.class.getName(), filter.getType());
    // Copy of the branch
    asUser().with(sourceBranch.projectId(), ProjectView.class).with(targetBranch.projectId(), BranchEdit.class).call(() -> copyService.copy(targetBranch, new BranchCopyRequest(sourceBranch.getId(), Collections.emptyList())));
    // Gets the filter on the new branch
    filters = asAccount(account).withView(targetBranch).call(() -> buildFilterService.getBuildFilters(targetBranch.getId()));
    assertEquals(1, filters.size());
    filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertEquals(StandardBuildFilterProvider.class.getName(), filter.getType());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) BuildFilterResource(net.nemerosa.ontrack.model.buildfilter.BuildFilterResource) BranchCopyRequest(net.nemerosa.ontrack.model.structure.BranchCopyRequest) Ack(net.nemerosa.ontrack.model.Ack) ProjectView(net.nemerosa.ontrack.model.security.ProjectView) BranchEdit(net.nemerosa.ontrack.model.security.BranchEdit) Test(org.junit.Test)

Example 32 with Branch

use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.

the class BuildFilterServiceIT method delete_unshared_filter.

@Test
public void delete_unshared_filter() throws Exception {
    // Branch
    Branch branch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    // Creates a filter for this account
    Ack ack = asAccount(account).call(() -> buildFilterService.saveFilter(branch.getId(), false, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
    assertTrue("Account filter saved", ack.isSuccess());
    // The filter is present
    Collection<BuildFilterResource<?>> filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(1, filters.size());
    BuildFilterResource<?> filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertFalse(filter.isShared());
    // Deletes the filter
    asAccount(account).call(() -> buildFilterService.deleteFilter(branch.getId(), "MyFilter"));
    // The filter is no longer there
    filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(0, filters.size());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) BuildFilterResource(net.nemerosa.ontrack.model.buildfilter.BuildFilterResource) Ack(net.nemerosa.ontrack.model.Ack) Test(org.junit.Test)

Example 33 with Branch

use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.

the class BuildFilterServiceImpl method deleteFilter.

@Override
public Ack deleteFilter(ID branchId, String name) {
    // Gets the branch
    Branch branch = structureService.getBranch(branchId);
    // If user is allowed to manage shared filters, this filter might have to be deleted from the shared filters
    // as well
    boolean sharedFilter = securityService.isProjectFunctionGranted(branch, BranchFilterMgt.class);
    // Deleting the filter
    return buildFilterRepository.delete(securityService.getCurrentAccount().id(), branchId.get(), name, sharedFilter);
}
Also used : Branch(net.nemerosa.ontrack.model.structure.Branch)

Aggregations

Branch (net.nemerosa.ontrack.model.structure.Branch)33 Test (org.junit.Test)29 IntNode (com.fasterxml.jackson.databind.node.IntNode)12 Account (net.nemerosa.ontrack.model.security.Account)7 Ack (net.nemerosa.ontrack.model.Ack)6 Project (net.nemerosa.ontrack.model.structure.Project)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 BuildFilterResource (net.nemerosa.ontrack.model.buildfilter.BuildFilterResource)4 NameDescription (net.nemerosa.ontrack.model.structure.NameDescription)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HttpOutputMessage (org.springframework.http.HttpOutputMessage)3 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 BranchFilterMgt (net.nemerosa.ontrack.model.security.BranchFilterMgt)2 ProjectView (net.nemerosa.ontrack.model.security.ProjectView)2 ID (net.nemerosa.ontrack.model.structure.ID)2 StructureService (net.nemerosa.ontrack.model.structure.StructureService)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 GraphQLInt (graphql.Scalars.GraphQLInt)1 GraphQLString (graphql.Scalars.GraphQLString)1