Skip to content

Commit 9b84831

Browse files
committed
fix(files_sharing): adjust IAttributes API and files_versions
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 62defbd commit 9b84831

File tree

15 files changed

+40
-43
lines changed

15 files changed

+40
-43
lines changed

apps/files/js/fileinfomodel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
for (const i in this.attributes.shareAttributes) {
129129
const attr = this.attributes.shareAttributes[i]
130130
if (attr.scope === 'permissions' && attr.key === 'download') {
131-
return attr.enabled
131+
return attr.value === true
132132
}
133133
}
134134

apps/files/src/actions/downloadAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const isDownloadable = function(node: Node) {
3333
if (node.attributes['mount-type'] === 'shared') {
3434
const shareAttributes = JSON.parse(node.attributes['share-attributes'] ?? 'null')
3535
const downloadAttribute = shareAttributes?.find?.((attribute: { scope: string; key: string }) => attribute.scope === 'permissions' && attribute.key === 'download')
36-
if (downloadAttribute !== undefined && downloadAttribute.enabled === false) {
36+
if (downloadAttribute !== undefined && downloadAttribute.value === false) {
3737
return false
3838
}
3939
}

apps/files/src/actions/moveOrCopyActionUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getQueue = () => {
2424
}
2525

2626
type ShareAttribute = {
27-
enabled: boolean
27+
value: any
2828
key: string
2929
scope: string
3030
}
@@ -48,7 +48,7 @@ export const canMove = (nodes: Node[]) => {
4848
export const canDownload = (nodes: Node[]) => {
4949
return nodes.every(node => {
5050
const shareAttributes = JSON.parse(node.attributes?.['share-attributes'] ?? '[]') as Array<ShareAttribute>
51-
return !shareAttributes.some(attribute => attribute.scope === 'permissions' && attribute.enabled === false && attribute.key === 'download')
51+
return !shareAttributes.some(attribute => attribute.scope === 'permissions' && attribute.value === false && attribute.key === 'download')
5252

5353
})
5454
}

apps/files/src/views/FilesList.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,14 @@ export default defineComponent({
396396
return { ...this.$route, query: { dir } }
397397
},
398398
399-
shareAttributes(): number[] | undefined {
399+
shareTypesAttributes(): number[] | undefined {
400400
if (!this.currentFolder?.attributes?.['share-types']) {
401401
return undefined
402402
}
403403
return Object.values(this.currentFolder?.attributes?.['share-types'] || {}).flat() as number[]
404404
},
405405
shareButtonLabel() {
406-
if (!this.shareAttributes) {
406+
if (!this.shareTypesAttributes) {
407407
return t('files', 'Share')
408408
}
409409
@@ -413,12 +413,12 @@ export default defineComponent({
413413
return t('files', 'Shared')
414414
},
415415
shareButtonType(): Type | null {
416-
if (!this.shareAttributes) {
416+
if (!this.shareTypesAttributes) {
417417
return null
418418
}
419419
420420
// If all types are links, show the link icon
421-
if (this.shareAttributes.some(type => type === Type.SHARE_TYPE_LINK)) {
421+
if (this.shareTypesAttributes.some(type => type === Type.SHARE_TYPE_LINK)) {
422422
return Type.SHARE_TYPE_LINK
423423
}
424424

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ public function getInheritedShares(string $path): DataResponse {
10551055
}
10561056

10571057
if (!($node->getPermissions() & Constants::PERMISSION_SHARE)) {
1058-
throw new SharingRightsException('no sharing rights on this item');
1058+
throw new SharingRightsException($this->l->t('no sharing rights on this item'));
10591059
}
10601060

10611061
// The current top parent we have access to
@@ -1171,7 +1171,7 @@ public function updateShare(
11711171
}
11721172

11731173
if (!$this->canEditShare($share)) {
1174-
throw new OCSForbiddenException('You are not allowed to edit incoming shares');
1174+
throw new OCSForbiddenException($this->l->t('You are not allowed to edit incoming shares'));
11751175
}
11761176

11771177
if (
@@ -1218,7 +1218,7 @@ public function updateShare(
12181218
*/
12191219

12201220
if ($share->getSharedBy() !== $this->currentUser) {
1221-
throw new OCSForbiddenException('You are not allowed to edit link shares that you don\'t own');
1221+
throw new OCSForbiddenException($this->l->t('You are not allowed to edit link shares that you don\'t own'));
12221222
}
12231223

12241224
// Update hide download state
@@ -1640,7 +1640,7 @@ private function parseDate(string $expireDate): \DateTime {
16401640
// Make sure it expires at midnight in owner timezone
16411641
$date->setTime(0, 0, 0);
16421642
} catch (\Exception $e) {
1643-
throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
1643+
throw new \Exception($this->l->t('Invalid date. Format must be YYYY-MM-DD'));
16441644
}
16451645

16461646
return $date;
@@ -1845,7 +1845,7 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array
18451845
*/
18461846
private function confirmSharingRights(Node $node): void {
18471847
if (!$this->hasResharingRights($this->currentUser, $node)) {
1848-
throw new SharingRightsException('no sharing rights on this item');
1848+
throw new SharingRightsException($this->l->t('No sharing rights on this item'));
18491849
}
18501850
}
18511851

@@ -2008,21 +2008,14 @@ private function setShareAttributes(IShare $share, ?string $attributesString) {
20082008
$formattedShareAttributes = \json_decode($attributesString, true);
20092009
if (is_array($formattedShareAttributes)) {
20102010
foreach ($formattedShareAttributes as $formattedAttr) {
2011-
// Legacy handling of the 'enabled' attribute
2012-
if (array_key_exists('enabled', $formattedAttr)) {
2013-
$formattedAttr['value'] = is_string($formattedAttr['enabled'])
2014-
? (bool) \json_decode($formattedAttr['enabled'])
2015-
: $formattedAttr['enabled'];
2016-
}
2017-
20182011
$newShareAttributes->setAttribute(
20192012
$formattedAttr['scope'],
20202013
$formattedAttr['key'],
20212014
$formattedAttr['value'],
20222015
);
20232016
}
20242017
} else {
2025-
throw new OCSBadRequestException('Invalid share attributes provided: \"' . $attributesString . '\"');
2018+
throw new OCSBadRequestException($this->l->t('Invalid share attributes provided: "%s"', [$attributesString]));
20262019
}
20272020
}
20282021
$share->setAttributes($newShareAttributes);
@@ -2044,10 +2037,10 @@ private function checkInheritedAttributes(IShare $share): void {
20442037
if ($storage instanceof Wrapper) {
20452038
$storage = $storage->getInstanceOfStorage(SharedStorage::class);
20462039
if ($storage === null) {
2047-
throw new \RuntimeException('Should not happen, instanceOfStorage but getInstanceOfStorage return null');
2040+
throw new \RuntimeException($this->l->t('Should not happen, instanceOfStorage but getInstanceOfStorage return null'));
20482041
}
20492042
} else {
2050-
throw new \RuntimeException('Should not happen, instanceOfStorage but not a wrapper');
2043+
throw new \RuntimeException($this->l->t('Should not happen, instanceOfStorage but not a wrapper'));
20512044
}
20522045
/** @var \OCA\Files_Sharing\SharedStorage $storage */
20532046
$inheritedAttributes = $storage->getShare()->getAttributes();
@@ -2085,15 +2078,15 @@ public function sendShareEmail(string $id, $password = ''): DataResponse {
20852078
}
20862079

20872080
if (!$this->canEditShare($share)) {
2088-
throw new OCSForbiddenException('You are not allowed to send mail notifications');
2081+
throw new OCSForbiddenException($this->l->t('You are not allowed to send mail notifications'));
20892082
}
20902083

20912084
// For mail and link shares, the user must be
20922085
// the owner of the share, not only the file owner.
20932086
if ($share->getShareType() === IShare::TYPE_EMAIL
20942087
|| $share->getShareType() === IShare::TYPE_LINK) {
20952088
if ($share->getSharedBy() !== $this->currentUser) {
2096-
throw new OCSForbiddenException('You are not allowed to send mail notifications');
2089+
throw new OCSForbiddenException($this->l->t('You are not allowed to send mail notifications'));
20972090
}
20982091
}
20992092

apps/files_sharing/tests/ApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ public function testUpdateShare() {
960960
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
961961
$ocs->updateShare(
962962
$share1->getId(), 1, null, null, null, null, null, null, null,
963-
'[{"scope": "app1", "key": "attr1", "enabled": true}]'
963+
'[{"scope": "app1", "key": "attr1", "value": true}]'
964964
);
965965
$ocs->cleanup();
966966

apps/files_versions/src/components/Version.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export default defineComponent({
259259
const downloadAttribute = this.fileInfo.shareAttributes
260260
.find((attribute) => attribute.scope === 'permissions' && attribute.key === 'download') || {}
261261
// If the download attribute is set to false, the file is not downloadable
262-
if (downloadAttribute?.enabled === false) {
262+
if (downloadAttribute?.value === false) {
263263
return false
264264
}
265265
}

build/integration/features/bootstrap/Sharing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public function createShare($user,
286286
}
287287

288288
if ($viewOnly === true) {
289-
$body['attributes'] = json_encode([['scope' => 'permissions', 'key' => 'download', 'enabled' => false]]);
289+
$body['attributes'] = json_encode([['scope' => 'permissions', 'key' => 'download', 'value' => false]]);
290290
}
291291

292292
$options['form_params'] = $body;

core/src/files/fileinfo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
for (const i in this.shareAttributes) {
148148
const attr = this.shareAttributes[i]
149149
if (attr.scope === 'permissions' && attr.key === 'download') {
150-
return attr.enabled
150+
return attr.value === true
151151
}
152152
}
153153

cypress/e2e/files_sharing/filesSharingUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export function createShare(fileName: string, username: string, shareSettings: P
3333
export function updateShare(fileName: string, index: number, shareSettings: Partial<ShareSetting> = {}) {
3434
openSharingPanel(fileName)
3535

36+
cy.intercept({ times: 1, method: 'PUT', url: '**/apps/files_sharing/api/v1/shares/*' }).as('updateShare')
37+
3638
cy.get('#app-sidebar-vue').within(() => {
3739
cy.get('[data-cy-files-sharing-share-actions]').eq(index).click()
3840
cy.get('[data-cy-files-sharing-share-permissions-bundle="custom"]').click()
@@ -82,6 +84,8 @@ export function updateShare(fileName: string, index: number, shareSettings: Part
8284
}
8385

8486
cy.get('[data-cy-files-sharing-share-editor-action="save"]').click({ scrollBehavior: 'nearest' })
87+
88+
cy.wait('@updateShare')
8589
})
8690
}
8791

0 commit comments

Comments
 (0)