mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 22:45:45 +01:00
merge
This commit is contained in:
@@ -34,6 +34,8 @@ package sonia.scm.api.rest;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -50,12 +52,17 @@ public class AuthorizationExceptionMapper
|
||||
extends StatusExceptionMapper<AuthorizationException>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AuthorizationExceptionMapper.class);
|
||||
|
||||
public AuthorizationExceptionMapper()
|
||||
{
|
||||
super(AuthorizationException.class, Response.Status.FORBIDDEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response toResponse(AuthorizationException exception) {
|
||||
LOG.info("user is missing permission: {}", exception.getMessage());
|
||||
LOG.trace("AuthorizationException:", exception);
|
||||
return super.toResponse(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpStatus;
|
||||
import sonia.scm.ConcurrentModificationException;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.api.MergeCommandBuilder;
|
||||
import sonia.scm.repository.api.MergeCommandResult;
|
||||
@@ -73,7 +74,7 @@ public class MergeResource {
|
||||
if (mergeCommandResult.isMergeable()) {
|
||||
return Response.noContent().build();
|
||||
} else {
|
||||
return Response.status(HttpStatus.SC_CONFLICT).build();
|
||||
throw new ConcurrentModificationException("revision", mergeCommand.getTargetRevision());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,9 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
linksBuilder.single(link("incomingDiff", resourceLinks.incoming().diff(repository.getNamespace(), repository.getName())));
|
||||
}
|
||||
if (repositoryService.isSupported(Command.MERGE)) {
|
||||
linksBuilder.single(link("merge", resourceLinks.merge().merge(repository.getNamespace(), repository.getName())));
|
||||
if (RepositoryPermissions.push(repository).isPermitted()) {
|
||||
linksBuilder.single(link("merge", resourceLinks.merge().merge(repository.getNamespace(), repository.getName())));
|
||||
}
|
||||
linksBuilder.single(link("mergeDryRun", resourceLinks.merge().dryRun(repository.getNamespace(), repository.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user