Skip to content
Draft
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
24 changes: 17 additions & 7 deletions lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ public function __construct(
public function getCollectiveShares(int $collectiveId): DataResponse {
$share = $this->handleErrorResponse(function () use ($collectiveId): array {
$userId = $this->userId;
$collective = $this->collectiveService->getCollective($collectiveId, $userId);
return $this->shareService->getSharesByCollectiveAndUser($userId, $collective->getId());
$this->collectiveService->getCollective($collectiveId, $userId);
$shares = $this->shareService->getSharesByCollectiveAndUser($userId, $collectiveId);

// Get global expiry configuration
return [
'shares' => $shares,
'expiryConfig' => [
'hasDefaultExpireDate' => $this->shareService->hasDefaultExpireDate(),
'isExpireDateEnforced' => $this->shareService->isExpireDateEnforced(),
'defaultExpireDays' => $this->shareService->getDefaultExpireDays(),
],
];
}, $this->logger);
return new DataResponse($share);
}
Expand Down Expand Up @@ -96,8 +106,8 @@ public function createCollectiveShare(int $collectiveId, string $password = ''):
* 200: Share updated
*/
#[NoAdminRequired]
public function updateCollectiveShare(int $collectiveId, string $token, bool $editable, string $password = ''): DataResponse {
return $this->updatePageShare($collectiveId, 0, $token, $editable, $password);
public function updateCollectiveShare(int $collectiveId, string $token, bool $editable, string $password = '', ?string $expiryDate = null): DataResponse {
return $this->updatePageShare($collectiveId, 0, $token, $editable, $password, $expiryDate);
}

/**
Expand Down Expand Up @@ -159,15 +169,15 @@ public function createPageShare(int $collectiveId, int $pageId = 0, string $pass
* 200: Share updated
*/
#[NoAdminRequired]
public function updatePageShare(int $collectiveId, int $pageId, string $token, bool $editable, ?string $password = null): DataResponse {
$share = $this->handleErrorResponse(function () use ($collectiveId, $pageId, $token, $editable, $password): CollectiveShare {
public function updatePageShare(int $collectiveId, int $pageId, string $token, bool $editable, ?string $password = null, ?string $expiryDate = null): DataResponse {
$share = $this->handleErrorResponse(function () use ($collectiveId, $pageId, $token, $editable, $password, $expiryDate): CollectiveShare {
$userId = $this->userId;
$collective = $this->collectiveService->getCollective($collectiveId, $userId);
$pageInfo = null;
if ($pageId !== 0) {
$pageInfo = $this->pageService->findByFileId($collectiveId, $pageId, $userId);
}
return $this->shareService->updateShare($userId, $collective, $pageInfo, $token, $editable, $password);
return $this->shareService->updateShare($userId, $collective, $pageInfo, $token, $editable, $password, $expiryDate);
}, $this->logger);
return new DataResponse($share);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/Db/CollectiveShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CollectiveShare extends Entity implements JsonSerializable {
/** transient attributes, not persisted in database */
protected bool $editable = false;
protected string $password = '';
protected ?\DateTime $expirationDate = null;

public function getEditable(): bool {
return $this->editable;
Expand All @@ -51,6 +52,14 @@ public function setPassword(string $password): void {
$this->password = $password;
}

public function getExpirationDate(): ?\DateTime {
return $this->expirationDate;
}

public function setExpirationDate(?\DateTime $expirationDate): void {
$this->expirationDate = $expirationDate;
}

public function jsonSerialize(): array {
return [
'id' => $this->id,
Expand All @@ -60,6 +69,7 @@ public function jsonSerialize(): array {
'owner' => $this->owner,
'editable' => $this->editable,
'password' => $this->password,
'expirationDate' => $this->expirationDate?->format(\DateTime::ATOM),
];
}
}
1 change: 1 addition & 0 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* owner: string,
* editable: bool,
* password: string,
* expirationDate: string|null,
* }
*
* @psalm-type CollectivesPageInfo = array{
Expand Down
35 changes: 34 additions & 1 deletion lib/Service/CollectiveShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public function findShare(string $userId, int $collectiveId, int $pageId): ?Coll
if ($folderShare->getPassword()) {
$collectiveShare->setPassword($folderShare->getPassword());
}

$collectiveShare->setExpirationDate($folderShare->getExpirationDate());
return $collectiveShare;
}

Expand All @@ -150,6 +152,8 @@ public function findShareByToken(string $token, bool $getPermissionInfo = true):
if ($folderShare->getPassword()) {
$collectiveShare->setPassword($folderShare->getPassword());
}

$collectiveShare->setExpirationDate($folderShare->getExpirationDate());
return $collectiveShare;
}

Expand All @@ -168,6 +172,8 @@ public function getSharesByCollectiveAndUser(string $userId, int $collectiveId):
if ($folderShare->getPassword()) {
$share->setPassword($folderShare->getPassword());
}

$share->setExpirationDate($folderShare->getExpirationDate());
$shares[] = $share;
}

Expand All @@ -179,6 +185,18 @@ private function isShareEditable(IShare $folderShare): bool {
return ($folderShare->getPermissions() & Collective::editPermissions) === Collective::editPermissions;
}

public function isExpireDateEnforced(): bool {
return $this->shareManager->shareApiLinkDefaultExpireDateEnforced();
}

public function getDefaultExpireDays(): int {
return $this->shareManager->shareApiLinkDefaultExpireDays();
}

public function hasDefaultExpireDate(): bool {
return $this->shareManager->shareApiLinkDefaultExpireDate();
}

/**
* @throws NotFoundException
* @throws NotPermittedException
Expand Down Expand Up @@ -207,6 +225,7 @@ public function createShare(string $userId, Collective $collective, ?PageInfo $p
if ($password != '') {
$collectiveShare->setPassword($folderShare->getPassword());
}
$collectiveShare->setExpirationDate($folderShare->getExpirationDate());
return $collectiveShare;
}

Expand All @@ -217,7 +236,7 @@ public function createShare(string $userId, Collective $collective, ?PageInfo $p
* @throws NotFoundException
* @throws NotPermittedException
*/
public function updateShare(string $userId, Collective $collective, ?PageInfo $pageInfo, string $token, bool $editable, ?string $password): CollectiveShare {
public function updateShare(string $userId, Collective $collective, ?PageInfo $pageInfo, string $token, bool $editable, ?string $password, ?string $expiryDate = null): CollectiveShare {
if (!$collective->canShare()) {
throw new NotPermittedException($this->l10n->t('You are not allowed to share %s', $collective->getName()));
}
Expand Down Expand Up @@ -250,10 +269,24 @@ public function updateShare(string $userId, Collective $collective, ?PageInfo $p
$password = null;
}
$folderShare->setPassword($password);

if ($expiryDate !== null) {
if ($expiryDate === '') {
// Empty string means remove expiration date
$folderShare->setExpirationDate(null);
} else {
$folderShare->setExpirationDate(new \DateTime($expiryDate));
}
}
// If $expiryDate === null, don't change existing expiry date

$this->shareManager->updateShare($folderShare);

$share->setEditable($this->isShareEditable($folderShare));
$share->setPassword($folderShare->getPassword() ?? '');

$share->setExpirationDate($folderShare->getExpirationDate());

return $share;
}

Expand Down
Loading