Added support for deleting assets to trash

This commit is contained in:
Rick Rongen
2019-05-20 14:42:40 +02:00
parent 3ba0d948f6
commit 21a23a70cc
2 changed files with 32 additions and 2 deletions

View File

@@ -20,6 +20,9 @@ Download:
http://app30-prd-asd.sbnl.vancis.nl:4502/crx/server/crx.default/jcr:root/content/dam/beeldbank/vrouw-direct-naar.jpg/jcr:content/renditions/original/jcr:content/jcr:data
OR
download.jsp?path=%2Fcontent%2Fdam%2Fbeeldbank%2Fvrouw-direct-naar.jpg%2Fjcr%3Acontent%2Frenditions%2Foriginal%2Fjcr%3Acontent%2Fjcr%3Adata&index=0
Delete asset via trash
/bin/wcmcommand --data "path="%"2Fcontent"%"2Fdam"%"2Flandelijk"%"2Fjeugdbibliotheek15-18"%"2F615.swf&_charset_=utf-8&cmd=deletePage&force=true"
"""
CRX_SERVER_ROOT = '/crx/server/crx.default/jcr:root/'
@@ -28,6 +31,7 @@ CRX_QUERY = '/crx/de/query.jsp'
PACKMGR_EXEC = '/crx/packmgr/service/exec.json'
PACKMGR_UPDATE = '/crx/packmgr/update.jsp'
WCM_COMMAND = '/bin/wcmcommand'
WCM_REFERENCES = '/bin/wcm/references.json'
WCM_PAGE_REFERENCES = '/libs/wcm/core/content/reference.json'
WCM_REPLICATE = '/bin/replicate.json'
@@ -56,6 +60,12 @@ class CrxNodeNotFound(CrxException):
self.response = response
class CrxCantDeleteAsset(CrxException):
def __init__(self, response_body: str, message: str):
super(CrxCantDeleteAsset, self).__init__(message)
self.response = response_body
class Connection:
def __init__(self,
host: str = 'localhost',
@@ -177,6 +187,26 @@ class Connection:
resp = self._session.post(url, files=files)
resp.raise_for_status()
def delete_asset(self, dam_path: str, force: bool = False):
"""
Delete an asset to the trash. If force is False (default) don't delete it if it has remaining references
Args:
dam_path: The path of the asset to delete
force: Whether or not to force delete it.
Returns:
True when the asset has been deleted
Raises CrxCantDeleteAsset:
When the asset can't be deleted (for example, insufficient rights or remaining references without force)
"""
url: str = self._host + WCM_COMMAND
response = self._session.post(url, data={'path': dam_path, 'cmd': 'deletePage', 'force': json.dumps(force)})
if not response.ok:
raise CrxCantDeleteAsset(response.text, response.reason)
return True
def get_node_raw(self, path: str):
"""
Get the raw JSON dictionary of a node.