mirror of
https://github.com/sismics/docs.git
synced 2025-12-13 01:36:18 +00:00
#83: GET /tag/id
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package com.sismics.rest.util;
|
||||
|
||||
import com.sismics.docs.core.constant.PermType;
|
||||
import com.sismics.docs.core.dao.jpa.AclDao;
|
||||
import com.sismics.docs.core.dao.jpa.dto.AclDto;
|
||||
import com.sismics.security.IPrincipal;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Acl utilities.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class AclUtil {
|
||||
/**
|
||||
* Add ACLs to a JSON response.
|
||||
*
|
||||
* @param json JSON
|
||||
* @param sourceId Source ID
|
||||
* @param principal Principal
|
||||
*/
|
||||
public static void addAcls(JsonObjectBuilder json, String sourceId, IPrincipal principal) {
|
||||
AclDao aclDao = new AclDao();
|
||||
List<AclDto> aclDtoList = aclDao.getBySourceId(sourceId);
|
||||
JsonArrayBuilder aclList = Json.createArrayBuilder();
|
||||
boolean writable = false;
|
||||
for (AclDto aclDto : aclDtoList) {
|
||||
aclList.add(Json.createObjectBuilder()
|
||||
.add("perm", aclDto.getPerm().name())
|
||||
.add("id", aclDto.getTargetId())
|
||||
.add("name", JsonUtil.nullable(aclDto.getTargetName()))
|
||||
.add("type", aclDto.getTargetType()));
|
||||
|
||||
if (!principal.isAnonymous()
|
||||
&& (aclDto.getTargetId().equals(principal.getId())
|
||||
|| principal.getGroupIdSet().contains(aclDto.getTargetId()))
|
||||
&& aclDto.getPerm() == PermType.WRITE) {
|
||||
// The source is writable for the current user
|
||||
writable = true;
|
||||
}
|
||||
}
|
||||
json.add("acls", aclList)
|
||||
.add("writable", writable);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import javax.json.JsonValue;
|
||||
* @author bgamard
|
||||
*/
|
||||
public class JsonUtil {
|
||||
|
||||
/**
|
||||
* Returns a JsonValue from a String.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user