Skip to content

Commit

Permalink
DLP: Disable OK button if blocked file is selected
Browse files Browse the repository at this point in the history
In file open dialogs, we allow the user to select DLP blocked files,
but in that case disable the OK button, as well as proceeding with the
default action/Enter key.

R=lucmult@chromium.org

Bug: b:259183224
Change-Id: I16a87862e4d5040cd6da18c6e9f70d4b0bee9567
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4047721
Commit-Queue: Wenbo Jie <wenbojie@chromium.org>
Auto-Submit: Aida Zolic <aidazolic@chromium.org>
Reviewed-by: Wenbo Jie <wenbojie@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1085170}
  • Loading branch information
Aida Zolic authored and Chromium LUCI CQ committed Dec 19, 2022
1 parent 6f3beca commit 09a4087
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,16 @@ export class DialogActionController {
if (this.dialogType_ === DialogType.SELECT_OPEN_FILE) {
this.dialogFooter_.okButton.disabled = selection.directoryCount !== 0 ||
selection.fileCount !== 1 ||
!this.fileSelectionHandler_.isAvailable();
!this.fileSelectionHandler_.isAvailable() ||
this.fileSelectionHandler_.isDlpBlocked();
return;
}

if (this.dialogType_ === DialogType.SELECT_OPEN_MULTI_FILE) {
this.dialogFooter_.okButton.disabled = selection.directoryCount !== 0 ||
selection.fileCount === 0 ||
!this.fileSelectionHandler_.isAvailable();
!this.fileSelectionHandler_.isAvailable() ||
this.fileSelectionHandler_.isDlpBlocked();
return;
}

Expand Down
26 changes: 12 additions & 14 deletions ui/file_manager/file_manager/foreground/js/file_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,29 +338,27 @@ export class FileSelectionHandler extends EventTarget {
* @return {boolean}
*/
isDlpBlocked() {
if (!util.isDlpEnabled()) {
return false;
}

const selectedIndexes =
this.directoryModel_.getFileListSelection().selectedIndexes;
const selectedEntries = selectedIndexes.map(index => {
return /** @type {!Entry} */ (
this.directoryModel_.getFileList().item(index));
});

// Check if any of the selected entries are blocked by DLP:
// a volume/directory in case of file-saveas (managed by the VolumeManager),
// or a file in case file-open dialogs (stored in the metadata).
for (const entry of selectedEntries) {
if (!entry.isDirectory) {
// TODO(b/259183224): Add proper checks; files are blocked if their
// source is not allowed to be opened by the files app dialog caller.
return false;
}
// The entry is a directory, which can only be blocked if it's a
// disabled volume/DLP component.
// TODO(b/259184588): Properly handle case when VolumeInfo is not
// available. E.g. for Crostini we might not have VolumeInfo before it's
// mounted.
const volumeInfo = this.volumeManager_.getVolumeInfo(entry);
if (!volumeInfo) {
continue;
if (volumeInfo && this.volumeManager_.isDisabled(volumeInfo.volumeType)) {
return true;
}
if (this.volumeManager_.isDisabled(volumeInfo.volumeType)) {
const metadata = this.metadataModel_.getCache(
[entry], ['isRestrictedForDestination'])[0];
if (metadata && !!metadata.isRestrictedForDestination) {
return true;
}
}
Expand Down
28 changes: 20 additions & 8 deletions ui/file_manager/integration_tests/file_manager/dlp.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,29 +318,41 @@ testcase.saveAsDlpRestrictedRedirectsToMyFiles = async () => {
/**
* Tests the open file dialogs properly show DLP blocked files. If a file cannot
* be opened by the caller of the dialog, it should be marked as disabled in the
* details list.
* details list. If such a file is selected, the "Open" dialog button should be
* disabled.
*/
testcase.openDlpRestrictedFile = async () => {
// Setup the restrictions.
await sendTestMessage({name: 'setIsRestrictedByAnyRuleBlocked'});
await sendTestMessage({name: 'setIsRestrictedByAnyRuleRestrictions'});
await sendTestMessage({name: 'setIsRestrictedDestinationRestriction'});

// TODO(b/263079195): Add mix of dirs and files when mocking is improved.
// Add entries to Downloads.
await addEntries(['local'], [ENTRIES.hello]);
const entries = [
ENTRIES.hello, /** blocked */
ENTRIES.world, /** not blocked */
ENTRIES.beautiful, /** not blocked */
ENTRIES.desktop, /** blocked */
];
await addEntries(['local'], entries);

const disabledOkButton = '.button-panel button.ok:disabled';
const cancelButton = '.button-panel button.cancel';

const closer = async (dialog) => {
// Wait for the file list to appear.
await remoteCall.waitForElement(dialog, '#file-list');
await remoteCall.waitForFiles(
dialog, TestEntryInfo.getExpectedRows([ENTRIES.hello]));
// Wait for the DLP managed icon to be shown - this means that metadata has
// been fetched and we can check the disabled status as well.
await remoteCall.waitForElementsCount(
dialog, ['#file-list .dlp-managed-icon'], 1);
dialog, ['#file-list .dlp-managed-icon'], 2);

await remoteCall.waitForElementsCount(
dialog, ['#file-list .file[disabled]'], 1);
dialog, ['#file-list .file[disabled]'], 2);

// Verify that the button is disabled when a blocked file is selected.
await remoteCall.waitUntilSelected(dialog, entries[3].nameText);
await remoteCall.waitForElement(dialog, disabledOkButton);

// Click the close button to dismiss the dialog.
await remoteCall.waitForElement(dialog, cancelButton);
Expand All @@ -351,5 +363,5 @@ testcase.openDlpRestrictedFile = async () => {
chrome.test.assertEq(
undefined,
await openAndWaitForClosingDialog(
{type: 'openFile'}, 'downloads', [ENTRIES.hello], closer));
{type: 'openFile'}, 'downloads', entries, closer));
};

0 comments on commit 09a4087

Please sign in to comment.