Skip to content

Commit

Permalink
Expiration date option for user and group shares
Browse files Browse the repository at this point in the history
  • Loading branch information
jvillafanez authored and phil-davis committed Dec 19, 2019
1 parent 98fc511 commit 4319548
Show file tree
Hide file tree
Showing 45 changed files with 3,382 additions and 388 deletions.
9 changes: 9 additions & 0 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1090,4 +1090,13 @@ public function getAccepted($remote, $shareWith) {

return $event->getArgument('isRemoteTrusted') === true;
}

/**
* @inheritdoc
*/
public function getProviderCapabilities() {
return [
\OCP\Share::CONVERT_SHARE_TYPE_TO_STRING[\OCP\Share::SHARE_TYPE_REMOTE] => [],
];
}
}
136 changes: 99 additions & 37 deletions apps/files_sharing/css/sharetabview.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,6 @@
margin-right: 0;
}

#shareWithList {
list-style-type: none;
padding : 0 0 16px;
}

#shareWithList li {
padding-top : 5px;
padding-bottom: 5px;
font-weight : bold;
white-space : normal;
}

#shareWithList .showCruds img,
#shareWithList .unshare img {
vertical-align: text-bottom;
/* properly align icons */
}

#shareWithList label input[type=checkbox] {
margin-left: 0;
position : relative;
}

#shareWithList .username {
padding-right : 8px;
white-space : nowrap;
text-overflow : ellipsis;
max-width : 254px;
display : inline-block;
overflow : hidden;
vertical-align: middle;
}

#shareWithList li label {
margin-right: 8px;
}

#shareDialogLinkList .link-shares + #shareTreeUserGroupList {
margin-top: -20px;
}
Expand Down Expand Up @@ -136,6 +99,15 @@
background-size: 16px 16px;
}

.shareTabView .action-item {
display: inherit;
opacity: .5;
}

.shareTabView .action-item + .action-item {
margin-left: 5px;
}

.shareTabView .privacyWarningMessage {
margin-top: 20px;
}
Expand Down Expand Up @@ -344,4 +316,94 @@
color: red;
padding: 4px;
display: block;
}

/* ---------------------------------------------------- ShareWithList --- */

.shareWithList {
list-style-type : none;
padding : 0 0 16px;
}

[class^='shareWithList__item'] {
display : flex;
justify-content : space-between;
flex-wrap : wrap;
padding-top : 10px;
padding-bottom : 10px;
font-weight : bold;
}

.shareWithList__item--detailed {
background-color: #f8f8f8;
margin-left: -15px;
margin-right: -15px;
padding: 10px 15px;
}

.shareWithList__item--detailed + .shareWithList__item--detailed {
border-top: 1px solid #eee
}

[class^='shareWithList__container'] {
display : flex;
align-items : center;
}

.shareWithList__container--left {
justify-content: flex-start;
}

.shareWithList__container--right {
justify-content: flex-end;
}

.shareWithList__item label input[type=checkbox] {
margin-left: 0;
position : relative;
}

.shareWithList__item .username {
padding-right : 8px;
white-space : nowrap;
text-overflow : ellipsis;
max-width : 254px;
display : inline-block;
overflow : hidden;
vertical-align: middle;
}

.shareWithList__item label {
margin-right: 8px;
}

.shareWithList__item .expiration {
max-width: 190px;
text-align: left;
margin: 0 0 0 5px;
}

.shareWithList__item .removeExpiration {
text-indent: -9999px;
border: 0 none;
transform: translate(calc(-100% - 5px), -1px);
background-color: #F8F8F8;
background-position: center;
background-repeat: no-repeat;
background-image: url('../../../core/img/actions/close.svg');
}

.shareWithList__item .toggleShareDetails {
display: inherit;
opacity: 0.5;
}

.shareWithList__details {
width: 100%;
background-color: #f8f8f8;
}

.shareWithList__details-group:first-of-type,
.shareWithList__details-group + .shareWithList__details-group {
margin-top: 10px;
}
21 changes: 20 additions & 1 deletion apps/files_sharing/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\Util\UserSearch;
use OCP\Share\IManager;

/**
* Class Capabilities
Expand All @@ -32,6 +33,8 @@
*/
class Capabilities implements ICapability {

/** @var IManager */
private $shareManager;
/** @var IConfig */
private $config;

Expand All @@ -49,7 +52,8 @@ class Capabilities implements ICapability {
* @param IConfig $config
* @param UserSearch $userSearch
*/
public function __construct(IConfig $config, UserSearch $userSearch, IL10N $l10n) {
public function __construct(IManager $shareManager, IConfig $config, UserSearch $userSearch, IL10N $l10n) {
$this->shareManager = $shareManager;
$this->config = $config;
$this->userSearch = $userSearch;
$this->l10n = $l10n;
Expand All @@ -69,6 +73,7 @@ public function getCapabilities() {
$res['user'] = ['send_mail' => false];
$res['resharing'] = false;
$res['can_share'] = false;
$res['providers_capabilities'] = false;
} else {
$res['api_enabled'] = true;

Expand Down Expand Up @@ -106,6 +111,19 @@ public function getCapabilities() {
$res["public"] = $public;

$res['user']['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_mail_notification', 'no') === 'yes';
$res['user']['expire_date'] = [];
$res['user']['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date_user_share', 'no') === 'yes';
if ($res['user']['expire_date']['enabled']) {
$res['user']['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days_user_share', '7');
$res['user']['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date_user_share', 'no') === 'yes';
}

$res['group']['expire_date'] = [];
$res['group']['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date_group_share', 'no') === 'yes';
if ($res['group']['expire_date']['enabled']) {
$res['group']['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days_group_share', '7');
$res['group']['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date_group_share', 'no') === 'yes';
}

$res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';

Expand All @@ -130,6 +148,7 @@ public function getCapabilities() {
$res["user_enumeration"] = $user_enumeration;

$res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', \OCP\Constants::PERMISSION_ALL);
$res['providers_capabilities'] = $this->shareManager->getProvidersCapabilities();
}

//Federated sharing
Expand Down
66 changes: 31 additions & 35 deletions apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ protected function formatShare(IShare $share, $received = false) {
$result['file_parent'] = $node->getParent()->getId();
$result['file_target'] = $share->getTarget();

$expiration = $share->getExpirationDate();
if ($expiration !== null) {
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
}

if ($share->getShareType() === Share::SHARE_TYPE_USER) {
$sharedWith = $this->userManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
Expand All @@ -220,11 +225,6 @@ protected function formatShare(IShare $share, $received = false) {
if ($share->getToken() !== null) {
$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
}

$expiration = $share->getExpirationDate();
if ($expiration !== null) {
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
}
} elseif ($share->getShareType() === Share::SHARE_TYPE_REMOTE) {
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $share->getSharedWith();
Expand All @@ -235,7 +235,7 @@ protected function formatShare(IShare $share, $received = false) {

$result['attributes'] = null;
if ($attributes = $share->getAttributes()) {
$result['attributes'] = \json_encode($attributes->toArray());
$result['attributes'] = \json_encode($attributes->toArray());
}

return $result;
Expand Down Expand Up @@ -377,6 +377,18 @@ public function createShare() {
$permissions &= ~($permissions & ~$path->getPermissions());
}

//Expire date
$expireDate = $this->request->getParam('expireDate', '');
if ($expireDate !== '') {
try {
$expireDate = $this->parseDate($expireDate);
$share->setExpirationDate($expireDate);
} catch (Exception $e) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 404, $this->l->t('Invalid date, date format must be YYYY-MM-DD'));
}
}

$shareWith = $this->request->getParam('shareWith', null);

$globalAutoAccept = $this->config->getAppValue('core', 'shareapi_auto_accept_share', 'yes') === 'yes';
Expand Down Expand Up @@ -471,19 +483,6 @@ public function createShare() {
if ($password !== '') {
$share->setPassword($password);
}

//Expire date
$expireDate = $this->request->getParam('expireDate', '');

if ($expireDate !== '') {
try {
$expireDate = $this->parseDate($expireDate);
$share->setExpirationDate($expireDate);
} catch (Exception $e) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 404, $this->l->t('Invalid date, date format must be YYYY-MM-DD'));
}
}
} elseif ($shareType === Share::SHARE_TYPE_REMOTE) {
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
Expand Down Expand Up @@ -822,34 +821,31 @@ public function updateShare($id) {
$share->setPermissions($newPermissions);
}

if ($expireDate === '') {
$share->setExpirationDate(null);
} elseif ($expireDate !== null) {
try {
$expireDate = $this->parseDate($expireDate);
} catch (Exception $e) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 400, $e->getMessage());
}
$share->setExpirationDate($expireDate);
}

if ($password === '') {
$share->setPassword(null);
} elseif ($password !== null) {
$share->setPassword($password);
}
} else {
// For other shares only permissions is valid.
if ($permissions === null) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 400, $this->l->t('Wrong or no update parameter given'));
} else {
if ($permissions !== null) {
$newPermissions = (int)$permissions;
$share->setPermissions($newPermissions);
}
}

if ($expireDate === '') {
$share->setExpirationDate(null);
} elseif ($expireDate !== null) {
try {
$expireDate = $this->parseDate($expireDate);
} catch (Exception $e) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 400, $e->getMessage());
}
$share->setExpirationDate($expireDate);
}

$share = $this->setShareAttributes($share, $this->request->getParam('attributes', null));

try {
Expand Down
7 changes: 6 additions & 1 deletion apps/files_sharing/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use OCA\Files_Sharing\Capabilities;
use OCP\IL10N;
use OCP\Share\IManager;

/**
* Class CapabilitiesTest
Expand All @@ -39,6 +40,8 @@ class CapabilitiesTest extends \Test\TestCase {

/** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
private $l10n;
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
private $shareManager;

/**
*
Expand All @@ -56,6 +59,8 @@ protected function setUp(): void {
$this->l10n = $this->createMock(IL10N::class);
$this->l10n->method('t')
->willReturn('Public link');

$this->shareManager = $this->createMock(IManager::class);
}

/**
Expand All @@ -81,7 +86,7 @@ private function getFilesSharingPart(array $data) {
private function getResults(array $map) {
$stub = $this->getMockBuilder('\OCP\IConfig')->disableOriginalConstructor()->getMock();
$stub->method('getAppValue')->will($this->returnValueMap($map));
$cap = new Capabilities($stub, $this->userSearch, $this->l10n);
$cap = new Capabilities($this->shareManager, $stub, $this->userSearch, $this->l10n);
$result = $this->getFilesSharingPart($cap->getCapabilities());
return $result;
}
Expand Down
Loading

0 comments on commit 4319548

Please sign in to comment.