Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/end_to_end_encryption-files.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/end_to_end_encryption-files.mjs.map

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions lib/Connector/Sabre/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
private UserAgentManager $userAgentManager,
private IRequest $request,
private IMetaDataStorage $metaDataStorage,
private Folder $userFolder,
private ?Folder $userFolder,
) {
parent::__construct($rootFolder, $userSession, $pathCache);
}
Expand Down Expand Up @@ -83,15 +83,17 @@ public function setE2EEProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
});
}

$propFind->handle(self::E2EE_IS_ENCRYPTED, function () use ($node) {
if ($node instanceof File) {
$isEncrypted = $this->userFolder->getFirstNodeById($node->getFileInfo()->getParentId())->isEncrypted() ? '1' : '0';
} else {
$isEncrypted = $node->getFileInfo()->isEncrypted();
}
if ($this->userFolder !== null) {
$propFind->handle(self::E2EE_IS_ENCRYPTED, function () use ($node) {
if ($node instanceof File) {
$isEncrypted = $this->userFolder->getFirstNodeById($node->getFileInfo()->getParentId())->isEncrypted() ? '1' : '0';
} else {
$isEncrypted = $node->getFileInfo()->isEncrypted();
}

return $isEncrypted ? '1' : '0';
});
return $isEncrypted ? '1' : '0';
});
}
}

/**
Expand Down
24 changes: 23 additions & 1 deletion src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,40 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

/* eslint-disable jsdoc/require-jsdoc */

import { loadState } from '@nextcloud/initial-state'
import { registerFileAction } from '@nextcloud/files'
import { registerFileAction, getFileActions, Node, View } from '@nextcloud/files'

Check warning on line 9 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L9

Added line #L9 was not covered by tests
import { registerDavProperty } from '@nextcloud/files/dav'

import { setupWebDavDecryptionProxy } from './services/webDavProxy.ts'
import downloadUnencryptedAction from './services/downloadUnencryptedAction.ts'
import logger from './services/logger.ts'

Check warning on line 14 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L14

Added line #L14 was not covered by tests

const userConfig = loadState('end_to_end_encryption', 'userConfig', { e2eeInBrowserEnabled: false })

if (userConfig.e2eeInBrowserEnabled) {
setupWebDavDecryptionProxy()
registerDavProperty('nc:e2ee-is-encrypted', { nc: 'http://nextcloud.org/ns' })

Check warning on line 20 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L20

Added line #L20 was not covered by tests
registerDavProperty('nc:e2ee-metadata', { nc: 'http://nextcloud.org/ns' })
registerDavProperty('nc:e2ee-metadata-signature', { nc: 'http://nextcloud.org/ns' })
registerFileAction(downloadUnencryptedAction)
disableFileAction('download')
disableFileAction('move-copy')
}

Check warning on line 26 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L24-L26

Added lines #L24 - L26 were not covered by tests

function disableFileAction(actionId: string) {
logger.debug('Disabling file action', { actionId })
const actions = getFileActions()

Check warning on line 30 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L28-L30

Added lines #L28 - L30 were not covered by tests

const action = actions.find(action => action.id === actionId) as any
const originalEnabled = action._action.enabled

Check warning on line 33 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L32-L33

Added lines #L32 - L33 were not covered by tests

action._action.enabled = (nodes: Node[], view: View) => {
if (nodes.some(node => node.attributes['e2ee-is-encrypted'] === 1)) {
return false
}

Check warning on line 38 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L35-L38

Added lines #L35 - L38 were not covered by tests

return originalEnabled(nodes, view)
}

Check warning on line 41 in src/files.ts

View check run for this annotation

Codecov / codecov/patch

src/files.ts#L40-L41

Added lines #L40 - L41 were not covered by tests
}
4 changes: 4 additions & 0 deletions src/services/downloadUnencryptedAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
return false
}

if (nodes.some(node => node.attributes['e2ee-is-encrypted'] !== 1)) {
return false
}

Check warning on line 40 in src/services/downloadUnencryptedAction.ts

View check run for this annotation

Codecov / codecov/patch

src/services/downloadUnencryptedAction.ts#L38-L40

Added lines #L38 - L40 were not covered by tests

// We can only download dav ressource
if (nodes.some(node => !node.isDavRessource)) {
return false
Expand Down
Loading