diff --git a/scm-webapp/pom.xml b/scm-webapp/pom.xml index 7d0e0fc8c9..bc78d8f9e9 100644 --- a/scm-webapp/pom.xml +++ b/scm-webapp/pom.xml @@ -23,7 +23,7 @@ sonia.scm scm-annotation-processor 2.0.0-SNAPSHOT - provided + true @@ -370,6 +370,25 @@ provided + + org.projectlombok + lombok + 1.16.18 + provided + + + + org.mapstruct + mapstruct-jdk8 + ${org.mapstruct.version} + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + provided + @@ -456,7 +475,7 @@ - + org.apache.maven.plugins maven-war-plugin @@ -533,6 +552,7 @@ javascript:S3827 **.js src/main/webapp/resources/extjs/**,src/main/webapp/resources/moment/**,src/main/webapp/resources/syntaxhighlighter/** + 1.2.0.Final diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/UserDto.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/UserDto.java new file mode 100644 index 0000000000..4ff27cfa2f --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/UserDto.java @@ -0,0 +1,8 @@ +package sonia.scm.api.rest.resources; + +import lombok.Data; + +@Data +public class UserDto { + private String name; +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/UserMapper.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/UserMapper.java new file mode 100644 index 0000000000..eb2be1e703 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/UserMapper.java @@ -0,0 +1,14 @@ +package sonia.scm.api.rest.resources; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; +import sonia.scm.user.User; + +@Mapper +public interface UserMapper { + UserMapper INSTANCE = Mappers.getMapper( UserMapper.class ); + + @Mapping(source = "name", target = "name") + UserDto userToUserDto(User user); +} diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/UserNewResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/UserNewResource.java new file mode 100644 index 0000000000..48cdbef4b2 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/UserNewResource.java @@ -0,0 +1,73 @@ +package sonia.scm.api.rest.resources; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.webcohesion.enunciate.metadata.rs.ResponseCode; +import com.webcohesion.enunciate.metadata.rs.StatusCodes; +import com.webcohesion.enunciate.metadata.rs.TypeHint; +import org.apache.shiro.SecurityUtils; +import sonia.scm.Manager; +import sonia.scm.security.Role; +import sonia.scm.user.User; +import sonia.scm.user.UserException; +import sonia.scm.user.UserManager; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.*; +import java.util.Collection; + +@Singleton +@Path("usersnew") +public class UserNewResource extends AbstractManagerResource +{ + + /** Field description */ + public static final String PATH_PART = "usersnew"; + + @Inject + public UserNewResource(UserManager userManager) { + super(userManager); + } + + @Override + protected GenericEntity> createGenericEntity(Collection items) { + return null; + } + + @Override + protected String getId(User user) { + return user.getName(); + } + + @Override + protected String getPathPart() { + return PATH_PART; + } + + @GET + @Path("{id}") + @TypeHint(UserDto.class) + @StatusCodes({ + @ResponseCode(code = 200, condition = "success"), + @ResponseCode(code = 403, condition = "forbidden, the current user has no admin privileges"), + @ResponseCode(code = 404, condition = "not found, no group with the specified id/name available"), + @ResponseCode(code = 500, condition = "internal server error") + }) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Override + public Response get(@Context Request request, @PathParam("id") String id) + { + if (SecurityUtils.getSubject().hasRole(Role.ADMIN)) + { + User user = manager.get(id); + UserDto userDto = UserMapper.INSTANCE.userToUserDto(user); + return Response.ok(userDto).build(); + } + else + { + return Response.status(Response.Status.FORBIDDEN).build(); + } + }}