Skip to content
Open
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
9 changes: 8 additions & 1 deletion apps/files_sharing/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function __construct(
* expire_date?: array{
* enabled: bool,
* days?: int,
* default_days?: int,
* enforced?: bool,
* },
* expire_date_internal?: array{
Expand Down Expand Up @@ -123,7 +124,13 @@ public function getCapabilities() {
$public['multiple_links'] = true;
$public['expire_date']['enabled'] = $this->shareManager->shareApiLinkDefaultExpireDate();
if ($public['expire_date']['enabled']) {
$public['expire_date']['days'] = $this->shareManager->shareApiLinkDefaultExpireDays();
$maxDays = $this->shareManager->shareApiLinkDefaultExpireDays();
$defaultDays = (int)$this->config->getAppValue('core', 'link_defaultExpDays', (string)$maxDays);
if ($defaultDays > $maxDays) {
$defaultDays = $maxDays;
}
$public['expire_date']['days'] = $maxDays;
$public['expire_date']['default_days'] = $defaultDays;
$public['expire_date']['enforced'] = $this->shareManager->shareApiLinkDefaultExpireDateEnforced();
}

Expand Down
4 changes: 4 additions & 0 deletions apps/files_sharing/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
"type": "integer",
"format": "int64"
},
"default_days": {
"type": "integer",
"format": "int64"
},
"enforced": {
"type": "boolean"
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default {
maxExpirationDateEnforced() {
if (this.isExpiryDateEnforced) {
if (this.isPublicShare) {
return this.config.defaultExpirationDate
return this.config.maxExpirationDate
}
if (this.isRemoteShare) {
return this.config.defaultRemoteExpirationDateString
Expand Down
23 changes: 22 additions & 1 deletion apps/files_sharing/src/services/ConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type FileSharingCapabilities = {
expire_date: {
enabled: boolean
days: number
default_days: number
enforced: boolean
}
multiple_links: boolean
Expand Down Expand Up @@ -130,6 +131,19 @@ export default class Config {
* Get the default link share expiration date
*/
get defaultExpirationDate(): Date | null {
if (this.isDefaultExpireDateEnabled) {
const days = this.linkDefaultExpDays ?? this.defaultExpireDate
if (days !== null) {
return new Date(new Date().setDate(new Date().getDate() + days))
}
}
return null
}

/**
* Get the maximum link share expiration date
*/
get maxExpirationDate(): Date | null {
if (this.isDefaultExpireDateEnabled && this.defaultExpireDate !== null) {
return new Date(new Date().setDate(new Date().getDate() + this.defaultExpireDate))
}
Expand Down Expand Up @@ -243,12 +257,19 @@ export default class Config {
}

/**
* Get the default days to link shares expiration
* Get the maximum days to link shares expiration
*/
get defaultExpireDate(): number | null {
return window.OC.appConfig.core.defaultExpireDate
}

/**
* Get the default days to link shares expiration
*/
get linkDefaultExpDays(): number | null {
return this._capabilities?.files_sharing?.public?.expire_date?.default_days ?? null
}

/**
* Get the default days to internal shares expiration
*/
Expand Down
24 changes: 23 additions & 1 deletion apps/files_sharing/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public function testLinkExpireDate(): void {
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
['core', 'link_defaultExpDays', '7', '7'],
];

$typedMap = [
Expand All @@ -199,7 +200,28 @@ public function testLinkExpireDate(): void {
$this->assertArrayHasKey('expire_date', $result['public']);
$this->assertIsArray($result['public']['expire_date']);
$this->assertTrue($result['public']['expire_date']['enabled']);
$this->assertArrayHasKey('days', $result['public']['expire_date']);
$this->assertSame(7, $result['public']['expire_date']['days']);
$this->assertSame(7, $result['public']['expire_date']['default_days']);
$this->assertFalse($result['public']['expire_date']['enforced']);
}

public function testLinkExpireDateWithDefaultDays(): void {
$map = [
['core', 'shareapi_enabled', 'yes', 'yes'],
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_links_password_excluded_groups', '', ''],
['core', 'link_defaultExpDays', '7', '3'],
];

$typedMap = [
['core', 'shareapi_default_expire_date', true],
['core', 'shareapi_enforce_expire_date', false],
];

$result = $this->getResults($map, $typedMap);
$this->assertSame(7, $result['public']['expire_date']['days']);
$this->assertSame(3, $result['public']['expire_date']['default_days']);
$this->assertFalse($result['public']['expire_date']['enforced']);
}

Expand Down
1 change: 1 addition & 0 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,7 @@
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_sharing/lib/Controller/DeletedShareAPIController.php">
Expand Down
4 changes: 2 additions & 2 deletions dist/6980-6980.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/6980-6980.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_sharing-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-init.js.map

Large diffs are not rendered by default.

Loading
Loading