mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Create first new dummy user resource
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
<groupId>sonia.scm</groupId>
|
||||
<artifactId>scm-annotation-processor</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -370,6 +370,25 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-jdk8</artifactId>
|
||||
<version>${org.mapstruct.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>${org.mapstruct.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -533,6 +552,7 @@
|
||||
<sonar.issue.ignore.multicriteria.e1.ruleKey>javascript:S3827</sonar.issue.ignore.multicriteria.e1.ruleKey>
|
||||
<sonar.issue.ignore.multicriteria.e1.resourceKey>**.js</sonar.issue.ignore.multicriteria.e1.resourceKey>
|
||||
<sonar.exclusions>src/main/webapp/resources/extjs/**,src/main/webapp/resources/moment/**,src/main/webapp/resources/syntaxhighlighter/**</sonar.exclusions>
|
||||
<org.mapstruct.version>1.2.0.Final</org.mapstruct.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserDto {
|
||||
private String name;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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<User, UserException>
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String PATH_PART = "usersnew";
|
||||
|
||||
@Inject
|
||||
public UserNewResource(UserManager userManager) {
|
||||
super(userManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GenericEntity<Collection<User>> createGenericEntity(Collection<User> 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();
|
||||
}
|
||||
}}
|
||||
Reference in New Issue
Block a user