Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix public link share, default expiration behavior #34960

Merged
merged 2 commits into from
Apr 5, 2019
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
14 changes: 0 additions & 14 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,6 @@ protected function validateExpirationDate(\OCP\Share\IShare $share) {
}
}

// If expiredate is empty set a default one if there is a default
$fullId = null;
try {
$fullId = $share->getFullId();
} catch (\UnexpectedValueException $e) {
// This is a new share
}

if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
$expirationDate = new \DateTime();
$expirationDate->setTime(0, 0, 0);
$expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D'));
}

// If we enforce the expiration date check that is does not exceed
if ($this->shareApiLinkDefaultExpireDateEnforced()) {
if ($expirationDate === null) {
Expand Down
39 changes: 19 additions & 20 deletions settings/templates/panels/admin/filesharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,31 @@
print_unescaped('checked="checked"');
} ?> />
<label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date'));?></label><br/>
<span id="setDefaultExpireDate" class="indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') {
p('hidden');
}?>">
<?php p($l->t('Expire after ')); ?>
<input type="text" name='shareapi_expire_after_n_days' id="shareapiExpireAfterNDays" placeholder="<?php p('7')?>"
value='<?php p($_['shareExpireAfterNDays']) ?>' />
<?php p($l->t('days')); ?><br/>
<?php if ($_['shareEnforceExpireDate'] === 'yes'): ?>
<input type="checkbox" name="shareapi_enforce_expire_date" id="shareapiEnforceExpireDate" class="checkbox" value="1" checked="checked" />
<?php else: ?>
<input type="checkbox" name="shareapi_enforce_expire_date" id="shareapiEnforceExpireDate" class="checkbox" value="1" />
<?php endif; ?>
<label class="indent" for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/>
</span>

<input type="checkbox" name="shareapi_allow_public_notification" id="allowPublicMailNotification" class="checkbox"
value="1" <?php if ($_['allowPublicMailNotification'] == 'yes') {
print_unescaped('checked="checked"');
} ?> />
<label for="allowPublicMailNotification"><?php p($l->t('Allow users to send mail notification for shared files'));?></label><br/>
<span id="publicMailNotificationLang" <?php if ($_['allowPublicMailNotification'] == 'no') {
print_unescaped('class="hidden"');
} ?>>
<label><?php p($l->t('Language used for public mail notifications for shared files'));?></label>
<?php print_unescaped($_['publicMailNotificationLang']); ?>
<br>
</span>
<span id="publicMailNotificationLang" class="indent <?php if ($_['allowPublicMailNotification'] == 'no'): ?>hidden<?php endif; ?>">
<label><?php p($l->t('Language used for public mail notifications for shared files'));?></label>
<?php print_unescaped($_['publicMailNotificationLang']); ?>
<br>
</span>


<input type="checkbox" name="shareapi_allow_social_share" id="allowSocialShare" class="checkbox"
Expand All @@ -78,19 +90,6 @@
<label for="allowSocialShare"><?php p($l->t('Allow users to share file via social media'));?></label><br/>

</p>
<p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') {
p('hidden');
}?>">
<?php p($l->t('Expire after ')); ?>
<input type="text" name='shareapi_expire_after_n_days' id="shareapiExpireAfterNDays" placeholder="<?php p('7')?>"
value='<?php p($_['shareExpireAfterNDays']) ?>' />
<?php p($l->t('days')); ?>
<input type="checkbox" name="shareapi_enforce_expire_date" id="shareapiEnforceExpireDate" class="checkbox"
value="1" <?php if ($_['shareEnforceExpireDate'] === 'yes') {
print_unescaped('checked="checked"');
} ?> />
<label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/>
</p>
<p class="<?php if ($_['shareAPIEnabled'] === 'no') {
p('hidden');
}?>">
Expand Down
14 changes: 5 additions & 9 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -939,24 +939,19 @@ public function testvalidateExpirationDateEnforceButNotEnabledAndNotSet() {
$this->assertNull($share->getExpirationDate());
}

/**
* @expectedException \InvalidArgumentException
*/
public function testvalidateExpirationDateEnforceButNotSetNewShare() {
$share = $this->manager->newShare();

$this->config->method('getAppValue')
->will($this->returnValueMap([
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
]));

$expected = new \DateTime();
$expected->setTime(0, 0, 0);
$expected->add(new \DateInterval('P3D'));

$this->invokePrivate($this->manager, 'validateExpirationDate', [$share]);

$this->assertNotNull($share->getExpirationDate());
$this->assertEquals($expected, $share->getExpirationDate());
}

public function testvalidateExpirationDateEnforceToFarIntoFuture() {
Expand All @@ -969,6 +964,7 @@ public function testvalidateExpirationDateEnforceToFarIntoFuture() {

$this->config->method('getAppValue')
->will($this->returnValueMap([
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
]));
Expand Down