Skip to content

Commit

Permalink
ELEMENTS-1660: prevent replacing and removing an attachment under ret…
Browse files Browse the repository at this point in the history
…ention when using nuxeo-file
  • Loading branch information
swarnadipa-dev committed Aug 7, 2023
1 parent 0a45abb commit 4254cda
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
48 changes: 48 additions & 0 deletions ui/test/nuxeo-file.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
@license
(C) Copyright Nuxeo Corp. (http://nuxeo.com/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { fixture, html } from '@nuxeo/testing-helpers';
import '../widgets/nuxeo-file';

suite('nuxeo-file', () => {
let element;
setup(async () => {
element = await fixture(
html`
<nuxeo-file></nuxeo-file>
`,
);
});

suite('should return whether property is under retention', () => {
test('when file:content is a retained property && xpath = file:content', () => {
const document = {
isUnderRetentionOrLegalHold: true,
retainedProperties: ['file:content'],
};
element.xpath = 'file:content';
expect(element._isDropzoneVisible(document)).to.eql(true);
});
test('when file:content is not a retained property && xpath = file:content', () => {
const document = {
isUnderRetentionOrLegalHold: true,
retainedProperties: [],
};
element.xpath = 'file:content';
expect(element._isDropzoneVisible(document)).to.eql(false);
});
});
});
27 changes: 23 additions & 4 deletions ui/widgets/nuxeo-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ import { UploaderBehavior } from './nuxeo-uploader-behavior.js';
required$="[[required]]"
/>
<div id="dropZone" hidden$="[[readonly]]">
<div id="dropZone" hidden$="[[_isDropzoneVisible(document, xpath)]]">
<dom-if if="[[!uploading]]">
<template>
<paper-button id="button" raised on-click="_pick" aria-labelledby="label">
Expand All @@ -118,7 +118,7 @@ import { UploaderBehavior } from './nuxeo-uploader-behavior.js';
<label class="error" hidden$="[[!invalid]]">[[errorMessage]]</label>
<dom-if if="[[_hasSingleValue(multiple, value)]]">
<dom-if if="[[_hasSingleValue(document, multiple, value)]]">
<template>
<div class="file">
<div class="layout horizontal">
Expand All @@ -127,7 +127,7 @@ import { UploaderBehavior } from './nuxeo-uploader-behavior.js';
icon="nuxeo:remove"
title="[[i18n('command.remove')]]"
on-click="remove"
hidden$="[[readonly]]"
hidden$="[[_isDropzoneVisible(document)]]"
>
</iron-icon>
</div>
Expand All @@ -146,7 +146,7 @@ import { UploaderBehavior } from './nuxeo-uploader-behavior.js';
icon="nuxeo:remove"
title="[[i18n('command.remove')]]"
on-click="remove"
hidden$="[[readonly]]"
hidden$="[[_isDropzoneVisible(document)]]"
>
</iron-icon>
</div>
Expand Down Expand Up @@ -195,6 +195,11 @@ import { UploaderBehavior } from './nuxeo-uploader-behavior.js';
reflectToAttribute: true,
},

xpath: {
type: String,
value: 'file:content',
},

/**
* Required.
*/
Expand Down Expand Up @@ -289,6 +294,20 @@ import { UploaderBehavior } from './nuxeo-uploader-behavior.js';
return !this.multiple && this._hasValue();
}

_isDropzoneVisible(document) {
if (
document &&
document.isUnderRetentionOrLegalHold &&
document.retainedProperties &&
document.retainedProperties.length > 0
) {
if (document.retainedProperties.indexOf(this.xpath) !== -1) {
return true;
}
}
return this.readonly;
}

_hasValue() {
return this.multiple ? !!this.value && this.value.length > 0 : !!this.value;
}
Expand Down

0 comments on commit 4254cda

Please sign in to comment.