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 ");
|
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 ");
|
sb.append(" from T_TAG t ");
|
||||||
// TODO Use ACLs
|
|
||||||
|
|
||||||
// Add search criterias
|
// Add search criterias
|
||||||
if (criteria.getId() != null) {
|
if (criteria.getId() != null) {
|
||||||
criteriaList.add("t.TAG_ID_C = :id");
|
criteriaList.add("t.TAG_ID_C = :id");
|
||||||
parameterMap.put("id", criteria.getId());
|
parameterMap.put("id", criteria.getId());
|
||||||
}
|
}
|
||||||
if (criteria.getUserId() != null) {
|
if (criteria.getTargetIdList() != null) {
|
||||||
criteriaList.add("t.TAG_IDUSER_C = :userId");
|
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("userId", criteria.getUserId());
|
parameterMap.put("targetIdList", criteria.getTargetIdList());
|
||||||
}
|
}
|
||||||
if (criteria.getDocumentId() != null) {
|
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 ");
|
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;
|
package com.sismics.docs.core.dao.jpa.criteria;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag criteria.
|
* Tag criteria.
|
||||||
*
|
*
|
||||||
@ -12,9 +14,9 @@ public class TagCriteria {
|
|||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User ID.
|
* ACL target ID list.
|
||||||
*/
|
*/
|
||||||
private String userId;
|
private List<String> targetIdList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document ID.
|
* Document ID.
|
||||||
@ -40,12 +42,12 @@ public class TagCriteria {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserId() {
|
public List<String> getTargetIdList() {
|
||||||
return userId;
|
return targetIdList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagCriteria setUserId(String userId) {
|
public TagCriteria setTargetIdList(List<String> targetIdList) {
|
||||||
this.userId = userId;
|
this.targetIdList = targetIdList;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
} else {
|
} else {
|
||||||
// Add tags added by the current user on this document
|
// Add tags added by the current user on this document
|
||||||
TagDao tagDao = new TagDao();
|
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();
|
JsonArrayBuilder tags = Json.createArrayBuilder();
|
||||||
for (TagDto tagDto : tagDtoList) {
|
for (TagDto tagDto : tagDtoList) {
|
||||||
tags.add(Json.createObjectBuilder()
|
tags.add(Json.createObjectBuilder()
|
||||||
@ -292,7 +292,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
|
|
||||||
for (DocumentDto documentDto : paginatedList.getResultList()) {
|
for (DocumentDto documentDto : paginatedList.getResultList()) {
|
||||||
// Get tags added by the current user on this document
|
// 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();
|
JsonArrayBuilder tags = Json.createArrayBuilder();
|
||||||
for (TagDto tagDto : tagDtoList) {
|
for (TagDto tagDto : tagDtoList) {
|
||||||
tags.add(Json.createObjectBuilder()
|
tags.add(Json.createObjectBuilder()
|
||||||
@ -355,7 +355,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
switch (params[0]) {
|
switch (params[0]) {
|
||||||
case "tag":
|
case "tag":
|
||||||
// New tag criteria
|
// 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) {
|
if (documentCriteria.getTagIdList() == null) {
|
||||||
documentCriteria.setTagIdList(new ArrayList<String>());
|
documentCriteria.setTagIdList(new ArrayList<String>());
|
||||||
}
|
}
|
||||||
@ -657,7 +657,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
TagDao tagDao = new TagDao();
|
TagDao tagDao = new TagDao();
|
||||||
Set<String> tagSet = new HashSet<>();
|
Set<String> tagSet = new HashSet<>();
|
||||||
Set<String> tagIdSet = 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) {
|
for (TagDto tagDto : tagDtoList) {
|
||||||
tagIdSet.add(tagDto.getId());
|
tagIdSet.add(tagDto.getId());
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class TagResource extends BaseResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TagDao tagDao = new TagDao();
|
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();
|
JsonArrayBuilder items = Json.createArrayBuilder();
|
||||||
for (TagDto tagDto : tagDtoList) {
|
for (TagDto tagDto : tagDtoList) {
|
||||||
items.add(Json.createObjectBuilder()
|
items.add(Json.createObjectBuilder()
|
||||||
@ -125,7 +125,7 @@ public class TagResource extends BaseResource {
|
|||||||
if (StringUtils.isEmpty(parentId)) {
|
if (StringUtils.isEmpty(parentId)) {
|
||||||
parentId = null;
|
parentId = null;
|
||||||
} else {
|
} 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) {
|
if (tagDtoList.size() == 0) {
|
||||||
throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId));
|
throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId));
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ public class TagResource extends BaseResource {
|
|||||||
|
|
||||||
// Get the tag
|
// Get the tag
|
||||||
TagDao tagDao = new TagDao();
|
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) {
|
if (tagDtoList.size() == 0) {
|
||||||
throw new ClientException("TagNotFound", MessageFormat.format("Tag not found: {0}", id));
|
throw new ClientException("TagNotFound", MessageFormat.format("Tag not found: {0}", id));
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ public class TagResource extends BaseResource {
|
|||||||
if (StringUtils.isEmpty(parentId)) {
|
if (StringUtils.isEmpty(parentId)) {
|
||||||
parentId = null;
|
parentId = null;
|
||||||
} else {
|
} 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) {
|
if (tagDtoList.size() == 0) {
|
||||||
throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId));
|
throw new ClientException("ParentNotFound", MessageFormat.format("Parent not found: {0}", parentId));
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ public class TagResource extends BaseResource {
|
|||||||
|
|
||||||
// Get the tag
|
// Get the tag
|
||||||
TagDao tagDao = new TagDao();
|
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) {
|
if (tagDtoList.size() == 0) {
|
||||||
throw new ClientException("TagNotFound", MessageFormat.format("Tag not found: {0}", id));
|
throw new ClientException("TagNotFound", MessageFormat.format("Tag not found: {0}", id));
|
||||||
}
|
}
|
||||||
|
@ -120,9 +120,9 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>../docs-core</module>
|
<module>docs-core</module>
|
||||||
<module>../docs-web-common</module>
|
<module>docs-web-common</module>
|
||||||
<module>../docs-web</module>
|
<module>docs-web</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@ -375,7 +375,8 @@
|
|||||||
<version>${fr.opensagres.xdocreport.version}</version>
|
<version>${fr.opensagres.xdocreport.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency> <!-- Servlet listener to register SPI ImageIO plugins -->
|
<!-- Servlet listener to register SPI ImageIO plugins -->
|
||||||
|
<dependency>
|
||||||
<groupId>com.twelvemonkeys.servlet</groupId>
|
<groupId>com.twelvemonkeys.servlet</groupId>
|
||||||
<artifactId>servlet</artifactId>
|
<artifactId>servlet</artifactId>
|
||||||
<version>${com.twelvemonkeys.imageio.version}</version>
|
<version>${com.twelvemonkeys.imageio.version}</version>
|
||||||
@ -389,7 +390,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- ImageIO plugins -->
|
<!-- ImageIO plugins -->
|
||||||
<dependency> <!-- Permissive JPEG plugin -->
|
<!-- Permissive JPEG plugin -->
|
||||||
|
<dependency>
|
||||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||||
<artifactId>imageio-jpeg</artifactId>
|
<artifactId>imageio-jpeg</artifactId>
|
||||||
<version>${com.twelvemonkeys.imageio.version}</version>
|
<version>${com.twelvemonkeys.imageio.version}</version>
|
Loading…
Reference in New Issue
Block a user