Skip to content

Commit

Permalink
WEBUI-990: prevent replacing and removing an attachment under retention
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishant0928 committed Aug 3, 2023
1 parent 4514bb3 commit 7b94d6d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
41 changes: 38 additions & 3 deletions elements/nuxeo-document-actions/nuxeo-replace-blob-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,44 @@ Polymer({
!this.isImmutable(doc) &&
!this.hasType(doc, 'Root') &&
!this.isTrashed(doc) &&
!(doc.isRecord && this.xpath !== 'file:content') &&
!(this.isUnderRetentionOrLegalHold(doc) && this.xpath === 'file:content') &&
!(this.hasFacet(doc, 'ColdStorage') && this.hasContent(doc, 'coldstorage:coldContent'))
!(this.hasFacet(doc, 'ColdStorage') && this.hasContent(doc, 'coldstorage:coldContent')) &&
!this._isPropUnderRetention(doc)
);
},

_isPropUnderRetention(doc) {
if (doc && doc.isUnderRetentionOrLegalHold && doc.retainedProperties && doc.retainedProperties.length > 0) {
const { retainedProperties } = doc;
/* if retained property is multivalued attachment, and all files are to be retained, denoted by ‘*’,
then return true.
if retained property is multivalued attachment, but only a single file is to be retained,
then return true only for that file */
return retainedProperties.find(
(prop) =>
this._transformXpathRegex(prop, this.xpath) ||
prop.startsWith(this.xpath) ||
(prop.includes(this.xpath.split('/')[0]) && !prop.includes('/')),
);
}
return false;
},

_transformXpathRegex(prop, xpath) {
const transformedArray = [];
const splitter = '/';
const star = '*';
if (prop.includes(star)) {
let xpathArray = xpath.split(splitter);

for (let i = 0; i < xpathArray.length; i++) {
if (!Number.isNaN(parseInt(xpathArray[i], 10))) {
xpathArray[i] = star;
}
transformedArray.push(xpathArray[i]);
}
xpathArray = transformedArray;
xpath = xpathArray.join(splitter);
}
return prop === xpath;
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,19 @@ Polymer({
this.hasPermission(doc, 'WriteProperties') &&
!this.isImmutable(doc) &&
!this.hasType(doc, 'Root') &&
!this.isTrashed(doc)
!this.isTrashed(doc) &&
!this._isPropUnderRetention(doc)
);
},

_isPropUnderRetention(doc) {
if (doc && doc.isUnderRetentionOrLegalHold && doc.retainedProperties && doc.retainedProperties.length > 0) {
return doc.retainedProperties.some((prop) => prop.startsWith(this.xpath));
}

return false;
},

_computeFiles() {
if (this._hasFiles(this._attachments)) {
return this._attachments;
Expand Down

0 comments on commit 7b94d6d

Please sign in to comment.