mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
Closes #13: Don't show tags from other users
This commit is contained in:
parent
072dd7b280
commit
52387d93ac
@ -75,16 +75,18 @@ public class TagDao {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<TagDto> getByDocumentId(String documentId) {
|
public List<TagDto> getByDocumentId(String documentId, String userId) {
|
||||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||||
StringBuilder sb = new StringBuilder("select t.TAG_ID_C, t.TAG_NAME_C, t.TAG_COLOR_C from T_DOCUMENT_TAG dt ");
|
StringBuilder sb = new StringBuilder("select t.TAG_ID_C, t.TAG_NAME_C, t.TAG_COLOR_C from T_DOCUMENT_TAG dt ");
|
||||||
sb.append(" join T_TAG t on t.TAG_ID_C = dt.DOT_IDTAG_C ");
|
sb.append(" join T_TAG t on t.TAG_ID_C = dt.DOT_IDTAG_C ");
|
||||||
sb.append(" where dt.DOT_IDDOCUMENT_C = :documentId and t.TAG_DELETEDATE_D is null ");
|
sb.append(" where dt.DOT_IDDOCUMENT_C = :documentId and t.TAG_DELETEDATE_D is null ");
|
||||||
|
sb.append(" and t.TAG_IDUSER_C = :userId ");
|
||||||
sb.append(" order by t.TAG_NAME_C ");
|
sb.append(" order by t.TAG_NAME_C ");
|
||||||
|
|
||||||
// Perform the query
|
// Perform the query
|
||||||
Query q = em.createNativeQuery(sb.toString());
|
Query q = em.createNativeQuery(sb.toString());
|
||||||
q.setParameter("documentId", documentId);
|
q.setParameter("documentId", documentId);
|
||||||
|
q.setParameter("userId", userId);
|
||||||
List<Object[]> l = q.getResultList();
|
List<Object[]> l = q.getResultList();
|
||||||
|
|
||||||
// Assemble results
|
// Assemble results
|
||||||
|
@ -105,18 +105,23 @@ public class DocumentResource extends BaseResource {
|
|||||||
document.put("language", documentDb.getLanguage());
|
document.put("language", documentDb.getLanguage());
|
||||||
document.put("creator", userDao.getById(documentDb.getUserId()).getUsername());
|
document.put("creator", userDao.getById(documentDb.getUserId()).getUsername());
|
||||||
|
|
||||||
// Add tags
|
if (principal.isAnonymous()) {
|
||||||
TagDao tagDao = new TagDao();
|
// No tags in anonymous mode (sharing)
|
||||||
List<TagDto> tagDtoList = tagDao.getByDocumentId(documentId);
|
document.put("tags", new ArrayList<JSONObject>());
|
||||||
List<JSONObject> tags = new ArrayList<>();
|
} else {
|
||||||
for (TagDto tagDto : tagDtoList) {
|
// Add tags added by the current user on this document
|
||||||
JSONObject tag = new JSONObject();
|
TagDao tagDao = new TagDao();
|
||||||
tag.put("id", tagDto.getId());
|
List<TagDto> tagDtoList = tagDao.getByDocumentId(documentId, principal.getId());
|
||||||
tag.put("name", tagDto.getName());
|
List<JSONObject> tags = new ArrayList<>();
|
||||||
tag.put("color", tagDto.getColor());
|
for (TagDto tagDto : tagDtoList) {
|
||||||
tags.add(tag);
|
JSONObject tag = new JSONObject();
|
||||||
|
tag.put("id", tagDto.getId());
|
||||||
|
tag.put("name", tagDto.getName());
|
||||||
|
tag.put("color", tagDto.getColor());
|
||||||
|
tags.add(tag);
|
||||||
|
}
|
||||||
|
document.put("tags", tags);
|
||||||
}
|
}
|
||||||
document.put("tags", tags);
|
|
||||||
|
|
||||||
// Add ACL
|
// Add ACL
|
||||||
List<AclDto> aclDtoList = aclDao.getBySourceId(documentId);
|
List<AclDto> aclDtoList = aclDao.getBySourceId(documentId);
|
||||||
@ -130,7 +135,10 @@ public class DocumentResource extends BaseResource {
|
|||||||
acl.put("type", aclDto.getTargetType());
|
acl.put("type", aclDto.getTargetType());
|
||||||
aclList.add(acl);
|
aclList.add(acl);
|
||||||
|
|
||||||
if (aclDto.getTargetId().equals(principal.getId()) && aclDto.getPerm() == PermType.WRITE) {
|
if (!principal.isAnonymous()
|
||||||
|
&& aclDto.getTargetId().equals(principal.getId())
|
||||||
|
&& aclDto.getPerm() == PermType.WRITE) {
|
||||||
|
// The document is writable for the current user
|
||||||
writable = true;
|
writable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,8 +194,8 @@ public class DocumentResource extends BaseResource {
|
|||||||
document.put("language", documentDto.getLanguage());
|
document.put("language", documentDto.getLanguage());
|
||||||
document.put("file_count", documentDto.getFileCount());
|
document.put("file_count", documentDto.getFileCount());
|
||||||
|
|
||||||
// Get tags
|
// Get tags added by the current user on this document
|
||||||
List<TagDto> tagDtoList = tagDao.getByDocumentId(documentDto.getId());
|
List<TagDto> tagDtoList = tagDao.getByDocumentId(documentDto.getId(), principal.getId());
|
||||||
List<JSONObject> tags = new ArrayList<>();
|
List<JSONObject> tags = new ArrayList<>();
|
||||||
for (TagDto tagDto : tagDtoList) {
|
for (TagDto tagDto : tagDtoList) {
|
||||||
JSONObject tag = new JSONObject();
|
JSONObject tag = new JSONObject();
|
||||||
|
Loading…
Reference in New Issue
Block a user