CCM NG/ccm-cms: Extended named queries for ContentItem to take permissions into account

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4731 8810af33-2d31-482b-a856-94f89814c4df
jensp 2017-05-11 18:13:47 +00:00
parent 6c7022eafc
commit 9084ade61e
1 changed files with 161 additions and 89 deletions

View File

@ -132,10 +132,25 @@ import static org.librecms.CmsConstants.*;
,
@NamedQuery(
name = "ContentItem.countItemsInFolder",
query = "SELECT COUNT(i) FROM ContentItem i "
query
= "SELECT DISTINCT COUNT(i) "
+ "FROM ContentItem i "
+ "JOIN i.categories c "
+ "JOIN i.permissions p "
+ "WHERE c.category = :folder "
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "'")
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' "
+ "AND ("
+ " ("
+ " p.grantee IN :roles "
+ " AND p.grantedPrivilege = "
+ " (CASE WHEN i.version = 'DRAFT' "
+ " THEN '" + ItemPrivileges.PREVIEW + "' "
+ " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' "
+ " END"
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
@NamedQuery(
name = "ContentItem.findByNameInFolder",
@ -162,20 +177,34 @@ import static org.librecms.CmsConstants.*;
,
@NamedQuery(
name = "ContentItem.countByNameInFolder",
query = "SELECT COUNT(i) FROM ContentItem i "
query = "SELECT DISTINCT COUNT(i)"
+ " FROM ContentItem i "
+ "JOIN i.categories c "
+ "JOIN i.permissions p "
+ "WHERE c.category = :folder "
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
+ "' "
+ "AND i.displayName = :name")
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' "
+ "AND i.displayName = :name "
+ "AND ("
+ " ("
+ " p.grantee IN :roles "
+ " AND p.grantedPrivilege = "
+ " (CASE WHEN i.version = 'DRAFT' "
+ " THEN '" + ItemPrivileges.PREVIEW + "' "
+ " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' "
+ " END"
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )")
,
@NamedQuery(
name = "ContentItem.filterByFolderAndName",
query = "SELECT i FROM ContentItem i "
query = "SELECT DISTINCT i "
+ "FROM ContentItem i "
+ "JOIN i.categories c "
+ "JOIN i.permissions p "
+ "WHERE c.category = :folder "
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
+ "' "
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER + "' "
+ "AND LOWER(i.displayName) LIKE CONCAT(LOWER(:name), '%')")
,
@NamedQuery(
@ -186,6 +215,18 @@ import static org.librecms.CmsConstants.*;
+ "AND c.type = '" + CATEGORIZATION_TYPE_FOLDER
+ "' "
+ "AND LOWER(i.displayName) LIKE CONCAT(LOWER(:name), '%') "
+ "AND ("
+ " ("
+ " p.grantee IN :roles "
+ " AND p.grantedPrivilege = "
+ " (CASE WHEN i.version = 'DRAFT' "
+ " THEN '" + ItemPrivileges.PREVIEW + "' "
+ " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' "
+ " END"
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )"
)
,
@NamedQuery(
@ -197,20 +238,51 @@ import static org.librecms.CmsConstants.*;
,
@NamedQuery(
name = "ContentItem.findDraftVersion",
query = "SELECT i FROM ContentItem i "
query
= "SELECT DISTINCT i "
+ "FROM ContentItem i "
+ "JOIN i.permissions p "
+ "WHERE i.itemUuid = :uuid "
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.DRAFT")
+ "AND i.version = 'DRAFT' "
+ "AND "
+ "((p.grantee IN :roles "
+ "AND p.grantedPrivilege = '" + ItemPrivileges.PREVIEW + "' "
+ ") OR true = :isSystemUser OR true = :isAdmin)")
,
@NamedQuery(
name = "ContentItem.findLiveVersion",
query = "SELECT i FROM ContentItem i "
query
= "SELECT DISTINCT i "
+ "FROM ContentItem i "
+ "JOIN i.permissions p "
+ "WHERE i.itemUuid = :uuid "
+ "AND i.version = org.librecms.contentsection.ContentItemVersion.LIVE")
+ "AND i.version = 'LIVE' "
+ "AND "
+ "((p.grantee IN :roles "
+ "AND p.grantedPrivilege = "
+ "'"
+ ItemPrivileges.VIEW_PUBLISHED
+ "' "
+ ") OR true = :isSystemUser OR true = :isAdmin)")
,
@NamedQuery(
name = "ContentItem.findItemWithWorkflow",
query = "SELECT i FROM ContentItem i "
query = "SELECT DISTINCT i "
+ "FROM ContentItem i "
+ "JOIN i.permissions p "
+ "WHERE i.workflow = :workflow "
+ "AND ("
+ " ("
+ " p.grantee IN :roles "
+ " AND p.grantedPrivilege = "
+ " (CASE WHEN i.version = 'DRAFT' "
+ " THEN '" + ItemPrivileges.PREVIEW + "' "
+ " ELSE '" + ItemPrivileges.VIEW_PUBLISHED + "' "
+ " END"
+ " )"
+ " )"
+ " OR true = :isSystemUser OR true = :isAdmin"
+ " )"
)
})
public class ContentItem extends CcmObject implements Serializable {