mirror of
https://github.com/sismics/docs.git
synced 2024-11-25 23:27:57 +01:00
#18: GET /group + fix JUnit
This commit is contained in:
parent
3b9a66d1d8
commit
c1c2228937
@ -68,7 +68,8 @@ public class AclDao {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<AclDto> getBySourceId(String sourceId) {
|
public List<AclDto> getBySourceId(String sourceId) {
|
||||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||||
StringBuilder sb = new StringBuilder("select a.ACL_ID_C, a.ACL_PERM_C, a.ACL_TARGETID_C, u.USE_USERNAME_C, s.SHA_NAME_C, g.GRP_NAME_C ");
|
StringBuilder sb = new StringBuilder("select a.ACL_ID_C, a.ACL_PERM_C, a.ACL_TARGETID_C, ");
|
||||||
|
sb.append(" u.USE_USERNAME_C, s.SHA_ID_C, s.SHA_NAME_C, g.GRP_NAME_C ");
|
||||||
sb.append(" from T_ACL a ");
|
sb.append(" from T_ACL a ");
|
||||||
sb.append(" left join T_USER u on u.USE_ID_C = a.ACL_TARGETID_C ");
|
sb.append(" left join T_USER u on u.USE_ID_C = a.ACL_TARGETID_C ");
|
||||||
sb.append(" left join T_SHARE s on s.SHA_ID_C = a.ACL_TARGETID_C ");
|
sb.append(" left join T_SHARE s on s.SHA_ID_C = a.ACL_TARGETID_C ");
|
||||||
@ -89,13 +90,14 @@ public class AclDao {
|
|||||||
aclDto.setPerm(PermType.valueOf((String) o[i++]));
|
aclDto.setPerm(PermType.valueOf((String) o[i++]));
|
||||||
aclDto.setTargetId((String) o[i++]);
|
aclDto.setTargetId((String) o[i++]);
|
||||||
String userName = (String) o[i++];
|
String userName = (String) o[i++];
|
||||||
|
String shareId = (String) o[i++];
|
||||||
String shareName = (String) o[i++];
|
String shareName = (String) o[i++];
|
||||||
String groupName = (String) o[i++];
|
String groupName = (String) o[i++];
|
||||||
if (userName != null) {
|
if (userName != null) {
|
||||||
aclDto.setTargetName(userName);
|
aclDto.setTargetName(userName);
|
||||||
aclDto.setTargetType(AclTargetType.USER.name());
|
aclDto.setTargetType(AclTargetType.USER.name());
|
||||||
}
|
}
|
||||||
if (shareName != null) {
|
if (shareId != null) { // Use ID because share name is nullable
|
||||||
aclDto.setTargetName(shareName);
|
aclDto.setTargetName(shareName);
|
||||||
aclDto.setTargetType(AclTargetType.SHARE.name());
|
aclDto.setTargetType(AclTargetType.SHARE.name());
|
||||||
}
|
}
|
||||||
|
@ -152,11 +152,12 @@ public class GroupDao {
|
|||||||
Map<String, Object> parameterMap = new HashMap<String, Object>();
|
Map<String, Object> parameterMap = new HashMap<String, Object>();
|
||||||
List<String> criteriaList = new ArrayList<String>();
|
List<String> criteriaList = new ArrayList<String>();
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("select g.GRP_ID_C as c0, g.GRP_NAME_C as c1, g.GRP_IDPARENT_C as c2 ");
|
StringBuilder sb = new StringBuilder("select g.GRP_ID_C as c0, g.GRP_NAME_C as c1, g.GRP_IDPARENT_C as c2, gp.GRP_NAME_C as c3 ");
|
||||||
if (criteria.getUserId() != null) {
|
if (criteria.getUserId() != null) {
|
||||||
sb.append(" , ug.UGP_ID_C ");
|
sb.append(" , ug.UGP_ID_C ");
|
||||||
}
|
}
|
||||||
sb.append(" from T_GROUP g ");
|
sb.append(" from T_GROUP g ");
|
||||||
|
sb.append(" left join T_GROUP gp on g.GRP_IDPARENT_C = gp.GRP_ID_C ");
|
||||||
|
|
||||||
// Add search criterias
|
// Add search criterias
|
||||||
if (criteria.getSearch() != null) {
|
if (criteria.getSearch() != null) {
|
||||||
@ -190,7 +191,8 @@ public class GroupDao {
|
|||||||
GroupDto groupDto = new GroupDto()
|
GroupDto groupDto = new GroupDto()
|
||||||
.setId((String) o[i++])
|
.setId((String) o[i++])
|
||||||
.setName((String) o[i++])
|
.setName((String) o[i++])
|
||||||
.setParentId((String) o[i++]);
|
.setParentId((String) o[i++])
|
||||||
|
.setParentName((String) o[i++]);
|
||||||
groupDtoList.add(groupDto);
|
groupDtoList.add(groupDto);
|
||||||
if (criteria.getUserId() != null && o[i++] != null) {
|
if (criteria.getUserId() != null && o[i++] != null) {
|
||||||
userGroupDtoList.add(groupDto);
|
userGroupDtoList.add(groupDto);
|
||||||
|
@ -21,6 +21,11 @@ public class GroupDto {
|
|||||||
*/
|
*/
|
||||||
private String parentId;
|
private String parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent name.
|
||||||
|
*/
|
||||||
|
private String parentName;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -48,6 +53,15 @@ public class GroupDto {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getParentName() {
|
||||||
|
return parentName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GroupDto setParentName(String parentName) {
|
||||||
|
this.parentName = parentName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return id.equals(((GroupDto) obj).getId());
|
return id.equals(((GroupDto) obj).getId());
|
||||||
|
@ -30,20 +30,20 @@ public class Acl implements Loggable {
|
|||||||
/**
|
/**
|
||||||
* ACL permission.
|
* ACL permission.
|
||||||
*/
|
*/
|
||||||
@Column(name = "ACL_PERM_C", length = 30)
|
@Column(name = "ACL_PERM_C", length = 30, nullable = false)
|
||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
private PermType perm;
|
private PermType perm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ACL source ID.
|
* ACL source ID.
|
||||||
*/
|
*/
|
||||||
@Column(name = "ACL_SOURCEID_C", length = 36)
|
@Column(name = "ACL_SOURCEID_C", length = 36, nullable = false)
|
||||||
private String sourceId;
|
private String sourceId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ACL target ID.
|
* ACL target ID.
|
||||||
*/
|
*/
|
||||||
@Column(name = "ACL_TARGETID_C", length = 36)
|
@Column(name = "ACL_TARGETID_C", length = 36, nullable = false)
|
||||||
private String targetId;
|
private String targetId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,12 +4,15 @@ import java.text.MessageFormat;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.json.Json;
|
import javax.json.Json;
|
||||||
|
import javax.json.JsonArrayBuilder;
|
||||||
import javax.json.JsonObjectBuilder;
|
import javax.json.JsonObjectBuilder;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.FormParam;
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
@ -21,9 +24,11 @@ import com.sismics.docs.core.dao.jpa.dto.GroupDto;
|
|||||||
import com.sismics.docs.core.model.jpa.Group;
|
import com.sismics.docs.core.model.jpa.Group;
|
||||||
import com.sismics.docs.core.model.jpa.User;
|
import com.sismics.docs.core.model.jpa.User;
|
||||||
import com.sismics.docs.core.model.jpa.UserGroup;
|
import com.sismics.docs.core.model.jpa.UserGroup;
|
||||||
|
import com.sismics.docs.core.util.jpa.SortCriteria;
|
||||||
import com.sismics.docs.rest.constant.BaseFunction;
|
import com.sismics.docs.rest.constant.BaseFunction;
|
||||||
import com.sismics.rest.exception.ClientException;
|
import com.sismics.rest.exception.ClientException;
|
||||||
import com.sismics.rest.exception.ForbiddenClientException;
|
import com.sismics.rest.exception.ForbiddenClientException;
|
||||||
|
import com.sismics.rest.util.JsonUtil;
|
||||||
import com.sismics.rest.util.ValidationUtil;
|
import com.sismics.rest.util.ValidationUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,4 +182,35 @@ public class GroupResource extends BaseResource {
|
|||||||
.add("status", "ok");
|
.add("status", "ok");
|
||||||
return Response.ok().entity(response.build()).build();
|
return Response.ok().entity(response.build()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all active groups.
|
||||||
|
*
|
||||||
|
* @param sortColumn Sort index
|
||||||
|
* @param asc If true, ascending sorting, else descending
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
public Response list(
|
||||||
|
@QueryParam("sort_column") Integer sortColumn,
|
||||||
|
@QueryParam("asc") Boolean asc) {
|
||||||
|
if (!authenticate()) {
|
||||||
|
throw new ForbiddenClientException();
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArrayBuilder groups = Json.createArrayBuilder();
|
||||||
|
SortCriteria sortCriteria = new SortCriteria(sortColumn, asc);
|
||||||
|
|
||||||
|
GroupDao groupDao = new GroupDao();
|
||||||
|
List<GroupDto> groupDtoList = groupDao.findByCriteria(new GroupCriteria(), sortCriteria);
|
||||||
|
for (GroupDto groupDto : groupDtoList) {
|
||||||
|
groups.add(Json.createObjectBuilder()
|
||||||
|
.add("name", groupDto.getName())
|
||||||
|
.add("parent", JsonUtil.nullable(groupDto.getParentName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||||
|
.add("groups", groups);
|
||||||
|
return Response.ok().entity(response.build()).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -532,8 +532,6 @@ public class UserResource extends BaseResource {
|
|||||||
/**
|
/**
|
||||||
* Returns all active users.
|
* Returns all active users.
|
||||||
*
|
*
|
||||||
* @param limit Page limit
|
|
||||||
* @param offset Page offset
|
|
||||||
* @param sortColumn Sort index
|
* @param sortColumn Sort index
|
||||||
* @param asc If true, ascending sorting, else descending
|
* @param asc If true, ascending sorting, else descending
|
||||||
* @return Response
|
* @return Response
|
||||||
|
@ -108,7 +108,8 @@ public class TestCommentResource extends BaseJerseyTest {
|
|||||||
.put(Entity.form(new Form()
|
.put(Entity.form(new Form()
|
||||||
.param("source", document1Id)
|
.param("source", document1Id)
|
||||||
.param("perm", "READ")
|
.param("perm", "READ")
|
||||||
.param("username", "comment2")), JsonObject.class);
|
.param("target", "comment2")
|
||||||
|
.param("type", "USER")), JsonObject.class);
|
||||||
|
|
||||||
// Create a comment with comment2
|
// Create a comment with comment2
|
||||||
json = target().path("/comment").request()
|
json = target().path("/comment").request()
|
||||||
|
@ -41,11 +41,24 @@ public class TestGroupResource extends BaseJerseyTest {
|
|||||||
clientUtil.createUser("group1", "g112", "g12");
|
clientUtil.createUser("group1", "g112", "g12");
|
||||||
String group1Token = clientUtil.login("group1");
|
String group1Token = clientUtil.login("group1");
|
||||||
|
|
||||||
// Check admin groups (all computed groups)
|
// Get all groups
|
||||||
JsonObject json = target().path("/user").request()
|
JsonObject json = target().path("/group")
|
||||||
|
.queryParam("sort_column", "1")
|
||||||
|
.queryParam("asc", "true")
|
||||||
|
.request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
.get(JsonObject.class);
|
.get(JsonObject.class);
|
||||||
JsonArray groups = json.getJsonArray("groups");
|
JsonArray groups = json.getJsonArray("groups");
|
||||||
|
Assert.assertEquals(6, groups.size());
|
||||||
|
JsonObject groupG11 = groups.getJsonObject(2);
|
||||||
|
Assert.assertEquals("g11", groupG11.getString("name"));
|
||||||
|
Assert.assertEquals("g1", groupG11.getString("parent"));
|
||||||
|
|
||||||
|
// Check admin groups (all computed groups)
|
||||||
|
json = target().path("/user").request()
|
||||||
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||||
|
.get(JsonObject.class);
|
||||||
|
groups = json.getJsonArray("groups");
|
||||||
Assert.assertEquals(1, groups.size());
|
Assert.assertEquals(1, groups.size());
|
||||||
Assert.assertEquals("administrators", groups.getString(0));
|
Assert.assertEquals("administrators", groups.getString(0));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user