Skip to content

Commit f5a819a

Browse files
committed
feat(preset): share link expiration date
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent cb84ccc commit f5a819a

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

apps/settings/lib/Settings/Admin/Sharing.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public function getForm() {
6262
'enforceLinksPasswordExcludedGroupsEnabled' => $this->config->getSystemValueBool('sharing.allow_disabled_password_enforcement_groups', false),
6363
'onlyShareWithGroupMembers' => $this->shareManager->shareWithGroupMembersOnly(),
6464
'onlyShareWithGroupMembersExcludeGroupList' => json_decode($onlyShareWithGroupMembersExcludeGroupList) ?? [],
65-
'defaultExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_default_expire_date'),
65+
'defaultExpireDate' => $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_EXPIRE_DATE_DEFAULT),
6666
'expireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'),
67-
'enforceExpireDate' => $this->getHumanBooleanConfig('core', 'shareapi_enforce_expire_date'),
67+
'enforceExpireDate' => $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_EXPIRE_DATE_ENFORCED),
6868
'excludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no'),
6969
'excludeGroupsList' => json_decode($excludedGroups, true) ?? [],
7070
'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext'),

apps/settings/tests/Settings/Admin/SharingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public function testGetFormWithoutExcludedGroups(): void {
5959
->willReturnMap([
6060
['core', 'shareapi_allow_federation_on_public_shares', true],
6161
['core', 'shareapi_enable_link_password_by_default', true],
62+
['core', 'shareapi_default_expire_date', false],
63+
['core', 'shareapi_enforce_expire_date', false],
6264
]);
6365

6466
$this->config
@@ -78,9 +80,7 @@ public function testGetFormWithoutExcludedGroups(): void {
7880
['core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes', 'yes'],
7981
['core', 'shareapi_restrict_user_enumeration_full_match_ignore_second_dn', 'no', 'no'],
8082
['core', 'shareapi_enabled', 'yes', 'yes'],
81-
['core', 'shareapi_default_expire_date', 'no', 'no'],
8283
['core', 'shareapi_expire_after_n_days', '7', '7'],
83-
['core', 'shareapi_enforce_expire_date', 'no', 'no'],
8484
['core', 'shareapi_exclude_groups', 'no', 'no'],
8585
['core', 'shareapi_public_link_disclaimertext', '', 'Lorem ipsum'],
8686
['core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL, Constants::PERMISSION_ALL],

core/AppInfo/ConfigLexicon.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class ConfigLexicon implements ILexicon {
2424
public const SHARE_CUSTOM_TOKEN = 'shareapi_allow_custom_tokens';
2525
public const SHARE_LINK_PASSWORD_DEFAULT = 'shareapi_enable_link_password_by_default';
2626
public const SHARE_LINK_PASSWORD_ENFORCED = 'shareapi_enforce_links_password';
27-
27+
public const SHARE_LINK_EXPIRE_DATE_DEFAULT = 'shareapi_default_expire_date';
28+
public const SHARE_LINK_EXPIRE_DATE_ENFORCED = 'shareapi_enforce_expire_date';
2829
public const USER_LANGUAGE = 'lang';
2930
public const LASTCRON_TIMESTAMP = 'lastcron';
3031

@@ -62,6 +63,24 @@ public function getAppConfigs(): array {
6263
},
6364
definition: 'Enforce password protection when sharing document'
6465
),
66+
new Entry(
67+
key: self::SHARE_LINK_EXPIRE_DATE_DEFAULT,
68+
type: ValueType::BOOL,
69+
defaultRaw: fn (Preset $p): bool => match ($p) {
70+
Preset::SHARED, Preset::SMALL, Preset::MEDIUM, Preset::LARGE => true,
71+
default => false,
72+
},
73+
definition: 'Set default expiration date for shares via link or mail'
74+
),
75+
new Entry(
76+
key: self::SHARE_LINK_EXPIRE_DATE_ENFORCED,
77+
type: ValueType::BOOL,
78+
defaultRaw: fn (Preset $p): bool => match ($p) {
79+
Preset::SHARED, Preset::SMALL, Preset::MEDIUM, Preset::LARGE => true,
80+
default => false,
81+
},
82+
definition: 'Enforce expiration date for shares via link or mail'
83+
),
6584
new Entry(self::LASTCRON_TIMESTAMP, ValueType::INT, 0, 'timestamp of last cron execution'),
6685
];
6786
}

lib/private/Share/Helper.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@
77
*/
88
namespace OC\Share;
99

10+
use OC\AppConfig;
11+
use OC\Core\AppInfo\ConfigLexicon;
12+
1013
class Helper extends \OC\Share\Constants {
1114
/**
1215
* get default expire settings defined by the admin
1316
* @return array contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays'
1417
*/
1518
public static function getDefaultExpireSetting() {
1619
$config = \OC::$server->getConfig();
20+
$appConfig = \OCP\Server::get(AppConfig::class);
1721

1822
$defaultExpireSettings = ['defaultExpireDateSet' => false];
1923

2024
// get default expire settings
21-
$defaultExpireDate = $config->getAppValue('core', 'shareapi_default_expire_date', 'no');
22-
if ($defaultExpireDate === 'yes') {
23-
$enforceExpireDate = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no');
25+
if ($appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_EXPIRE_DATE_DEFAULT)) {
2426
$defaultExpireSettings['defaultExpireDateSet'] = true;
2527
$defaultExpireSettings['expireAfterDays'] = (int)$config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
26-
$defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes';
28+
$defaultExpireSettings['enforceExpireDate'] = $appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_EXPIRE_DATE_ENFORCED);
2729
}
2830

2931
return $defaultExpireSettings;

lib/private/Share20/Manager.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,18 +1787,17 @@ public function shareApiLinkEnforcePassword(bool $checkGroupMembership = true) {
17871787
* @return bool
17881788
*/
17891789
public function shareApiLinkDefaultExpireDate() {
1790-
return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
1790+
return $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_EXPIRE_DATE_DEFAULT);
17911791
}
17921792

17931793
/**
17941794
* Is default link expire date enforced
1795-
*`
17961795
*
17971796
* @return bool
17981797
*/
17991798
public function shareApiLinkDefaultExpireDateEnforced() {
18001799
return $this->shareApiLinkDefaultExpireDate()
1801-
&& $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
1800+
&& $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_EXPIRE_DATE_ENFORCED);
18021801
}
18031802

18041803

lib/private/Template/JSConfigHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ public function getConfig(): string {
9898
}
9999

100100
$enableLinkPasswordByDefault = $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_PASSWORD_DEFAULT);
101-
$defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
101+
$defaultExpireDateEnabled = $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_EXPIRE_DATE_DEFAULT);
102102
$defaultExpireDate = $enforceDefaultExpireDate = null;
103103
if ($defaultExpireDateEnabled) {
104104
$defaultExpireDate = (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
105-
$enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
105+
$enforceDefaultExpireDate = $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_LINK_EXPIRE_DATE_ENFORCED);
106106
}
107107
$outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
108108

0 commit comments

Comments
 (0)