Fix permission check on branch deletion (#1515)

This commit is contained in:
Eduard Heimbuch
2021-02-01 14:48:19 +01:00
committed by GitHub
parent eb914b1f93
commit e283195530
3 changed files with 5 additions and 3 deletions

View File

@@ -0,0 +1,2 @@
- type: fixed
description: Fix permission check for branch deletion ([#1515](https://github.com/scm-manager/scm-manager/pull/1515))

View File

@@ -62,7 +62,7 @@ public abstract class BranchToBranchDtoMapper extends HalAppenderMapper implemen
.single(linkBuilder("changeset", resourceLinks.changeset().changeset(namespaceAndName.getNamespace(), namespaceAndName.getName(), branch.getRevision())).build())
.single(linkBuilder("source", resourceLinks.source().self(namespaceAndName.getNamespace(), namespaceAndName.getName(), branch.getRevision())).build());
if (!branch.isDefaultBranch() && RepositoryPermissions.modify(repository).isPermitted()) {
if (!branch.isDefaultBranch() && RepositoryPermissions.push(repository).isPermitted()) {
linksBuilder.single(linkBuilder("delete", resourceLinks.branch().delete(repository.getNamespace(), repository.getName(), branch.getName())).build());
}

View File

@@ -87,7 +87,7 @@ class BranchToBranchDtoMapperTest {
@Test
void shouldAppendDeleteLink() {
Repository repository = RepositoryTestData.createHeartOfGold();
when(subject.isPermitted("repository:modify:" + repository.getId())).thenReturn(true);
when(subject.isPermitted("repository:push:" + repository.getId())).thenReturn(true);
Branch branch = Branch.normalBranch("master", "42");
BranchDto dto = mapper.map(branch, repository);
@@ -106,7 +106,7 @@ class BranchToBranchDtoMapperTest {
@Test
void shouldNotAppendDeleteLinkIfNotPermitted() {
Repository repository = RepositoryTestData.createHeartOfGold();
when(subject.isPermitted("repository:modify:" + repository.getId())).thenReturn(false);
when(subject.isPermitted("repository:push:" + repository.getId())).thenReturn(false);
Branch branch = Branch.normalBranch("master", "42");
BranchDto dto = mapper.map(branch, repository);