Merged in bugfix/delete_repository_permissions (pull request #207)

Fix deletion of permissions after modification
This commit is contained in:
Mohamed Karray
2019-03-05 17:17:29 +00:00
7 changed files with 62 additions and 37 deletions

View File

@@ -5,18 +5,8 @@ import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import sonia.scm.repository.RepositoryPermission;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE)
@Mapper( collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE)
public abstract class RepositoryPermissionDtoToRepositoryPermissionMapper {
public abstract RepositoryPermission map(RepositoryPermissionDto permissionDto);
/**
* this method is needed to modify an existing permission object
*
* @param target the target permission
* @param repositoryPermissionDto the source dto
* @return the mapped target permission object
*/
public abstract void modify(@MappingTarget RepositoryPermission target, RepositoryPermissionDto repositoryPermissionDto);
}

View File

@@ -177,7 +177,11 @@ public class RepositoryPermissionRootResource {
.filter(filterPermission(permissionName))
.findFirst()
.orElseThrow(() -> notFound(entity(RepositoryPermission.class, namespace).in(Repository.class, namespace + "/" + name)));
dtoToModelMapper.modify(existingPermission, permission);
RepositoryPermission newPermission = dtoToModelMapper.map(permission);
if (!repository.removePermission(existingPermission)) {
throw new IllegalStateException(String.format("could not delete modified permission %s from repository %s/%s", existingPermission, namespace, name));
}
repository.addPermission(newPermission);
manager.modify(repository);
log.info("the permission with name: {} is updated.", permissionName);
return Response.noContent().build();
@@ -210,7 +214,7 @@ public class RepositoryPermissionRootResource {
.findFirst()
.ifPresent(repository::removePermission);
manager.modify(repository);
log.info("the permission with name: {} is updated.", permissionName);
log.info("the permission with name: {} is deleted.", permissionName);
return Response.noContent().build();
}