mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
#83: Use ACLs for tag operations
This commit is contained in:
parent
37fc2d09bb
commit
1b1d5e9b4c
@ -215,16 +215,15 @@ public class TagDao {
|
||||
|
||||
StringBuilder sb = new StringBuilder("select t.TAG_ID_C as c0, t.TAG_NAME_C as c1, t.TAG_COLOR_C as c2, t.TAG_IDPARENT_C as c3 ");
|
||||
sb.append(" from T_TAG t ");
|
||||
// TODO Use ACLs
|
||||
|
||||
// Add search criterias
|
||||
if (criteria.getId() != null) {
|
||||
criteriaList.add("t.TAG_ID_C = :id");
|
||||
parameterMap.put("id", criteria.getId());
|
||||
}
|
||||
if (criteria.getUserId() != null) {
|
||||
criteriaList.add("t.TAG_IDUSER_C = :userId");
|
||||
parameterMap.put("userId", criteria.getUserId());
|
||||
if (criteria.getTargetIdList() != null) {
|
||||
sb.append(" left join T_ACL a on a.ACL_TARGETID_C in (:targetIdList) and a.ACL_SOURCEID_C = t.TAG_ID_C and a.ACL_PERM_C = 'READ' and a.ACL_DELETEDATE_D is null ");
|
||||
parameterMap.put("targetIdList", criteria.getTargetIdList());
|
||||
}
|
||||
if (criteria.getDocumentId() != null) {
|
||||
sb.append(" join T_DOCUMENT_TAG dt on dt.DOT_IDTAG_C = t.TAG_ID_C and dt.DOT_DELETEDATE_D is null ");
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.sismics.docs.core.dao.jpa.criteria;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tag criteria.
|
||||
*
|
||||
@ -12,9 +14,9 @@ public class TagCriteria {
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* User ID.
|
||||
* ACL target ID list.
|
||||
*/
|
||||
private String userId;
|
||||
private List<String> targetIdList;
|
||||
|
||||
/**
|
||||
* Document ID.
|
||||
@ -40,12 +42,12 @@ public class TagCriteria {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
public List<String> getTargetIdList() {
|
||||
return targetIdList;
|
||||
}
|
||||
|
||||
public TagCriteria setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
public TagCriteria setTargetIdList(List<String> targetIdList) {
|
||||
this.targetIdList = targetIdList;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ public class DocumentResource extends BaseResource {
|
||||
} else {
|
||||
// Add tags added by the current user on this document
|
||||
TagDao tagDao = new TagDao();
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setDocumentId(documentId), new SortCriteria(1, true));
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setTargetIdList(getTargetIdList(null)).setDocumentId(documentId), new SortCriteria(1, true));
|
||||
JsonArrayBuilder tags = Json.createArrayBuilder();
|
||||
for (TagDto tagDto : tagDtoList) {
|
||||
tags.add(Json.createObjectBuilder()
|
||||
@ -292,7 +292,7 @@ public class DocumentResource extends BaseResource {
|
||||
|
||||
for (DocumentDto documentDto : paginatedList.getResultList()) {
|
||||
// Get tags added by the current user on this document
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setDocumentId(documentDto.getId()), new SortCriteria(1, true));
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setTargetIdList(getTargetIdList(null)).setDocumentId(documentDto.getId()), new SortCriteria(1, true));
|
||||
JsonArrayBuilder tags = Json.createArrayBuilder();
|
||||
for (TagDto tagDto : tagDtoList) {
|
||||
tags.add(Json.createObjectBuilder()
|
||||
@ -355,7 +355,7 @@ public class DocumentResource extends BaseResource {
|
||||
switch (params[0]) {
|
||||
case "tag":
|
||||
// New tag criteria
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setNameLike(params[1]), null);
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setTargetIdList(getTargetIdList(null)).setNameLike(params[1]), null);
|
||||
if (documentCriteria.getTagIdList() == null) {
|
||||
documentCriteria.setTagIdList(new ArrayList<String>());
|
||||
}
|
||||
@ -657,7 +657,7 @@ public class DocumentResource extends BaseResource {
|
||||
TagDao tagDao = new TagDao();
|
||||
Set<String> tagSet = new HashSet<>();
|
||||
Set<String> tagIdSet = new HashSet<>();
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()), null);
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setTargetIdList(getTargetIdList(null)), null);
|
||||
for (TagDto tagDto : tagDtoList) {
|
||||
tagIdSet.add(tagDto.getId());
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class TagResource extends BaseResource {
|
||||
}
|
||||
|
||||
TagDao tagDao = new TagDao();
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()), null);
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setTargetIdList(getTargetIdList(null)), null);
|
||||
JsonArrayBuilder items = Json.createArrayBuilder();
|
||||
for (TagDto tagDto : tagDtoList) {
|
||||
items.add(Json.createObjectBuilder()
|
||||
@ -125,7 +125,7 @@ public class TagResource extends BaseResource {
|
||||
if (StringUtils.isEmpty(parentId)) {
|
||||
parentId = null;
|
||||
} else {
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setId(parentId), null);
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setTargetIdList(getTargetIdList(null)).setId(parentId), null);
|
||||
if (tagDtoList.size() == 0) {
|
||||
throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId));
|
||||
}
|
||||
@ -190,7 +190,7 @@ public class TagResource extends BaseResource {
|
||||
|
||||
// Get the tag
|
||||
TagDao tagDao = new TagDao();
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setId(id), null);
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setTargetIdList(getTargetIdList(null)).setId(id), null);
|
||||
if (tagDtoList.size() == 0) {
|
||||
throw new ClientException("TagNotFound", MessageFormat.format("Tag not found: {0}", id));
|
||||
}
|
||||
@ -199,7 +199,7 @@ public class TagResource extends BaseResource {
|
||||
if (StringUtils.isEmpty(parentId)) {
|
||||
parentId = null;
|
||||
} else {
|
||||
tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setId(parentId), null);
|
||||
tagDtoList = tagDao.findByCriteria(new TagCriteria().setTargetIdList(getTargetIdList(null)).setId(parentId), null);
|
||||
if (tagDtoList.size() == 0) {
|
||||
throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId));
|
||||
}
|
||||
@ -240,7 +240,7 @@ public class TagResource extends BaseResource {
|
||||
|
||||
// Get the tag
|
||||
TagDao tagDao = new TagDao();
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setUserId(principal.getId()).setId(id), null);
|
||||
List<TagDto> tagDtoList = tagDao.findByCriteria(new TagCriteria().setTargetIdList(getTargetIdList(null)).setId(id), null);
|
||||
if (tagDtoList.size() == 0) {
|
||||
throw new ClientException("TagNotFound", MessageFormat.format("Tag not found: {0}", id));
|
||||
}
|
||||
|
@ -120,9 +120,9 @@
|
||||
</build>
|
||||
|
||||
<modules>
|
||||
<module>../docs-core</module>
|
||||
<module>../docs-web-common</module>
|
||||
<module>../docs-web</module>
|
||||
<module>docs-core</module>
|
||||
<module>docs-web-common</module>
|
||||
<module>docs-web</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -375,7 +375,8 @@
|
||||
<version>${fr.opensagres.xdocreport.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency> <!-- Servlet listener to register SPI ImageIO plugins -->
|
||||
<!-- Servlet listener to register SPI ImageIO plugins -->
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.servlet</groupId>
|
||||
<artifactId>servlet</artifactId>
|
||||
<version>${com.twelvemonkeys.imageio.version}</version>
|
||||
@ -389,7 +390,8 @@
|
||||
</dependency>
|
||||
|
||||
<!-- ImageIO plugins -->
|
||||
<dependency> <!-- Permissive JPEG plugin -->
|
||||
<!-- Permissive JPEG plugin -->
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-jpeg</artifactId>
|
||||
<version>${com.twelvemonkeys.imageio.version}</version>
|
Loading…
Reference in New Issue
Block a user