Skip to content

Commit eb5aefe

Browse files
committed
Separate settings for remote share expiration
Added separate settings for default and enforced expiration date for remote shares. Signed-off-by: Vincent Petry <[email protected]>
1 parent 6736e5b commit eb5aefe

File tree

12 files changed

+370
-86
lines changed

12 files changed

+370
-86
lines changed

apps/files_sharing/js/dist/files_sharing_tab.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/dist/files_sharing_tab.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/lib/Capabilities.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ public function getCapabilities() {
8686
$public['expire_date_internal']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
8787
}
8888

89+
$public['expire_date_remote'] = [];
90+
$public['expire_date_remote']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes';
91+
if ($public['expire_date_remote']['enabled']) {
92+
$public['expire_date_remote']['days'] = $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7');
93+
$public['expire_date_remote']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes';
94+
}
95+
8996
$public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
9097
$public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes';
9198
$public['upload_files_drop'] = $public['upload'];

apps/files_sharing/src/components/SharingEntry.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,12 @@ export default {
222222
},
223223
224224
canHaveNote() {
225-
return this.share.type !== this.SHARE_TYPES.SHARE_TYPE_REMOTE
226-
&& this.share.type !== this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP
225+
return !this.isRemote
226+
},
227+
228+
isRemote() {
229+
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE
230+
|| this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP
227231
},
228232
229233
/**
@@ -348,8 +352,13 @@ export default {
348352
},
349353
350354
dateMaxEnforced() {
351-
return this.config.isDefaultInternalExpireDateEnforced
352-
&& moment().add(1 + this.config.defaultInternalExpireDate, 'days')
355+
if (!this.isRemote) {
356+
return this.config.isDefaultInternalExpireDateEnforced
357+
&& moment().add(1 + this.config.defaultInternalExpireDate, 'days')
358+
} else {
359+
return this.config.isDefaultRemoteExpireDateEnforced
360+
&& moment().add(1 + this.config.defaultRemoteExpireDate, 'days')
361+
}
353362
},
354363
355364
/**

apps/files_sharing/src/services/ConfigService.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ export default class Config {
9595
return expireDateString
9696
}
9797

98+
/**
99+
* Get the default remote expiration date as string
100+
*
101+
* @returns {string}
102+
* @readonly
103+
* @memberof Config
104+
*/
105+
get defaultRemoteExpirationDateString() {
106+
let expireDateString = ''
107+
if (this.isDefaultRemoteExpireDateEnabled) {
108+
const date = window.moment.utc()
109+
const expireAfterDays = this.defaultRemoteExpireDate
110+
date.add(expireAfterDays, 'days')
111+
expireDateString = date.format('YYYY-MM-DD')
112+
}
113+
return expireDateString
114+
}
115+
98116
/**
99117
* Are link shares password-enforced ?
100118
*
@@ -150,6 +168,17 @@ export default class Config {
150168
return OC.appConfig.core.defaultInternalExpireDateEnforced === true
151169
}
152170

171+
/**
172+
* Is remote shares expiration enforced ?
173+
*
174+
* @returns {boolean}
175+
* @readonly
176+
* @memberof Config
177+
*/
178+
get isDefaultRemoteExpireDateEnforced() {
179+
return OC.appConfig.core.defaultRemoteExpireDateEnforced === true
180+
}
181+
153182
/**
154183
* Is there a default expiration date for new internal shares ?
155184
*
@@ -209,6 +238,17 @@ export default class Config {
209238
return OC.appConfig.core.defaultInternalExpireDate
210239
}
211240

241+
/**
242+
* Get the default days to remote shares expiration
243+
*
244+
* @returns {int}
245+
* @readonly
246+
* @memberof Config
247+
*/
248+
get defaultRemoteExpireDate() {
249+
return OC.appConfig.core.defaultRemoteExpireDate
250+
}
251+
212252
/**
213253
* Is resharing allowed ?
214254
*

apps/settings/js/admin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ window.addEventListener('DOMContentLoaded', function(){
9090
$("#setDefaultInternalExpireDate").toggleClass('hidden', !this.checked);
9191
});
9292

93+
$('#shareapiDefaultRemoteExpireDate').change(function() {
94+
$("#setDefaultRemoteExpireDate").toggleClass('hidden', !this.checked);
95+
});
96+
9397
$('#publicShareDisclaimer').change(function() {
9498
$("#publicShareDisclaimerText").toggleClass('hidden', !this.checked);
9599
if(!this.checked) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public function getForm() {
9090
'shareDefaultInternalExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no'),
9191
'shareInternalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
9292
'shareInternalEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no'),
93+
'shareDefaultRemoteExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no'),
94+
'shareRemoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'),
95+
'shareRemoteEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no'),
9396
];
9497

9598
return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');

apps/settings/templates/settings/admin/sharing.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,29 @@
6363
<label for="shareapiInternalEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/>
6464
</p>
6565

66+
<p id="remoteShareSettings" class="indent <?php if ($_['shareAPIEnabled'] === 'no') {
67+
p('hidden');
68+
} ?>">
69+
<input type="checkbox" name="shareapi_default_remote_expire_date" id="shareapiDefaultRemoteExpireDate" class="checkbox"
70+
value="1" <?php if ($_['shareDefaultRemoteExpireDateSet'] === 'yes') {
71+
print_unescaped('checked="checked"');
72+
} ?> />
73+
<label for="shareapiDefaultRemoteExpireDate"><?php p($l->t('Set default expiration date for shares to other servers'));?></label><br/>
74+
</p>
75+
<p id="setDefaultRemoteExpireDate" class="double-indent <?php if ($_['shareDefaultRemoteExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') {
76+
p('hidden');
77+
}?>">
78+
<?php p($l->t('Expire after ')); ?>
79+
<input type="text" name='shareapi_remote_expire_after_n_days' id="shareapiRemoteExpireAfterNDays" placeholder="<?php p('7')?>"
80+
value='<?php p($_['shareRemoteExpireAfterNDays']) ?>' />
81+
<?php p($l->t('days')); ?>
82+
<input type="checkbox" name="shareapi_enforce_remote_expire_date" id="shareapiRemoteEnforceExpireDate" class="checkbox"
83+
value="1" <?php if ($_['shareRemoteEnforceExpireDate'] === 'yes') {
84+
print_unescaped('checked="checked"');
85+
} ?> />
86+
<label for="shareapiRemoteEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/>
87+
</p>
88+
6689
<p class="<?php if ($_['shareAPIEnabled'] === 'no') {
6790
p('hidden');
6891
}?>">

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public function testGetFormWithoutExcludedGroups() {
8686
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
8787
['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
8888
['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
89+
['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
90+
['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
91+
['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
8992
]);
9093

9194
$expected = new TemplateResponse(
@@ -115,6 +118,9 @@ public function testGetFormWithoutExcludedGroups() {
115118
'shareDefaultInternalExpireDateSet' => 'no',
116119
'shareInternalExpireAfterNDays' => '7',
117120
'shareInternalEnforceExpireDate' => 'no',
121+
'shareDefaultRemoteExpireDateSet' => 'no',
122+
'shareRemoteExpireAfterNDays' => '7',
123+
'shareRemoteEnforceExpireDate' => 'no',
118124
],
119125
''
120126
);
@@ -146,6 +152,9 @@ public function testGetFormWithExcludedGroups() {
146152
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
147153
['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
148154
['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
155+
['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
156+
['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
157+
['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
149158
]);
150159

151160
$expected = new TemplateResponse(
@@ -175,6 +184,9 @@ public function testGetFormWithExcludedGroups() {
175184
'shareDefaultInternalExpireDateSet' => 'no',
176185
'shareInternalExpireAfterNDays' => '7',
177186
'shareInternalEnforceExpireDate' => 'no',
187+
'shareDefaultRemoteExpireDateSet' => 'no',
188+
'shareRemoteExpireAfterNDays' => '7',
189+
'shareRemoteEnforceExpireDate' => 'no',
178190
],
179191
''
180192
);

lib/private/Share20/Manager.php

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ protected function generalCreateChecks(IShare $share) {
385385
* @throws \Exception
386386
*/
387387
protected function validateExpirationDateInternal(IShare $share) {
388+
$isRemote = $share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP;
389+
388390
$expirationDate = $share->getExpirationDate();
389391

390392
if ($expirationDate !== null) {
@@ -407,28 +409,39 @@ protected function validateExpirationDateInternal(IShare $share) {
407409
// This is a new share
408410
}
409411

410-
if ($fullId === null && $expirationDate === null && $this->shareApiInternalDefaultExpireDate()) {
412+
if ($isRemote) {
413+
$defaultExpireDate = $this->shareApiRemoteDefaultExpireDate();
414+
$defaultExpireDays = $this->shareApiRemoteDefaultExpireDays();
415+
$configProp = 'remote_defaultExpDays';
416+
$isEnforced = $this->shareApiRemoteDefaultExpireDateEnforced();
417+
} else {
418+
$defaultExpireDate = $this->shareApiInternalDefaultExpireDate();
419+
$defaultExpireDays = $this->shareApiInternalDefaultExpireDays();
420+
$configProp = 'internal_defaultExpDays';
421+
$isEnforced = $this->shareApiInternalDefaultExpireDateEnforced();
422+
}
423+
if ($fullId === null && $expirationDate === null && $defaultExpireDate) {
411424
$expirationDate = new \DateTime();
412425
$expirationDate->setTime(0,0,0);
413426

414-
$days = (int)$this->config->getAppValue('core', 'internal_defaultExpDays', (string)$this->shareApiInternalDefaultExpireDays());
415-
if ($days > $this->shareApiInternalDefaultExpireDays()) {
416-
$days = $this->shareApiInternalDefaultExpireDays();
427+
$days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays);
428+
if ($days > $defaultExpireDays) {
429+
$days = $defaultExpireDays;
417430
}
418431
$expirationDate->add(new \DateInterval('P'.$days.'D'));
419432
}
420433

421434
// If we enforce the expiration date check that is does not exceed
422-
if ($this->shareApiInternalDefaultExpireDateEnforced()) {
435+
if ($isEnforced) {
423436
if ($expirationDate === null) {
424437
throw new \InvalidArgumentException('Expiration date is enforced');
425438
}
426439

427440
$date = new \DateTime();
428441
$date->setTime(0, 0, 0);
429-
$date->add(new \DateInterval('P' . $this->shareApiInternalDefaultExpireDays() . 'D'));
442+
$date->add(new \DateInterval('P' . $defaultExpireDays . 'D'));
430443
if ($date < $expirationDate) {
431-
$message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiInternalDefaultExpireDays()]);
444+
$message = $this->l->t('Can’t set expiration date more than %s days in the future', [$defaultExpireDays]);
432445
throw new GenericShareException($message, $message, 404);
433446
}
434447
}
@@ -1792,16 +1805,34 @@ public function shareApiInternalDefaultExpireDate(): bool {
17921805
return $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes';
17931806
}
17941807

1808+
/**
1809+
* Is default remote expire date enabled
1810+
*
1811+
* @return bool
1812+
*/
1813+
public function shareApiRemoteDefaultExpireDate(): bool {
1814+
return $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes';
1815+
}
1816+
17951817
/**
17961818
* Is default expire date enforced
1797-
*`
1819+
*
17981820
* @return bool
17991821
*/
18001822
public function shareApiInternalDefaultExpireDateEnforced(): bool {
18011823
return $this->shareApiInternalDefaultExpireDate() &&
18021824
$this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
18031825
}
18041826

1827+
/**
1828+
* Is default expire date enforced for remote shares
1829+
*
1830+
* @return bool
1831+
*/
1832+
public function shareApiRemoteDefaultExpireDateEnforced(): bool {
1833+
return $this->shareApiRemoteDefaultExpireDate() &&
1834+
$this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes';
1835+
}
18051836

18061837
/**
18071838
* Number of default expire days
@@ -1811,6 +1842,14 @@ public function shareApiInternalDefaultExpireDays(): int {
18111842
return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7');
18121843
}
18131844

1845+
/**
1846+
* Number of default expire days for remote shares
1847+
* @return int
1848+
*/
1849+
public function shareApiRemoteDefaultExpireDays(): int {
1850+
return (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7');
1851+
}
1852+
18141853
/**
18151854
* Allow public upload on link shares
18161855
*

0 commit comments

Comments
 (0)