Skip to content

Commit

Permalink
Merge pull request #1471 from nextcloud/backport/1457/1457-stable25
Browse files Browse the repository at this point in the history
[stable25] share expiration date
  • Loading branch information
juliusknorr authored Dec 28, 2023
2 parents ffe207f + 4e19bdb commit a55aae5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
39 changes: 21 additions & 18 deletions lib/Db/ShareWrapperRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
use OCA\Circles\Model\Membership;
use OCA\Circles\Model\Probes\CircleProbe;
use OCA\Circles\Model\ShareWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\Share\Exceptions\IllegalIDChangeException;
use OCP\Share\IShare;
use OCP\Files\Folder;

/**
* Class ShareWrapperRequest
Expand All @@ -64,18 +65,19 @@ public function save(IShare $share, int $parentId = 0): int {

$qb = $this->getShareInsertSql();
$qb->setValue('share_type', $qb->createNamedParameter($share->getShareType()))
->setValue('item_type', $qb->createNamedParameter($share->getNodeType()))
->setValue('item_source', $qb->createNamedParameter($share->getNodeId()))
->setValue('file_source', $qb->createNamedParameter($share->getNodeId()))
->setValue('file_target', $qb->createNamedParameter($share->getTarget()))
->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()))
->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->setValue('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED))
->setValue('password', $qb->createNamedParameter($password))
->setValue('permissions', $qb->createNamedParameter($share->getPermissions()))
->setValue('token', $qb->createNamedParameter($share->getToken()))
->setValue('stime', $qb->createFunction('UNIX_TIMESTAMP()'));
->setValue('item_type', $qb->createNamedParameter($share->getNodeType()))
->setValue('item_source', $qb->createNamedParameter($share->getNodeId()))
->setValue('file_source', $qb->createNamedParameter($share->getNodeId()))
->setValue('file_target', $qb->createNamedParameter($share->getTarget()))
->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()))
->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
->setValue('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED))
->setValue('password', $qb->createNamedParameter($password))
->setValue('permissions', $qb->createNamedParameter($share->getPermissions()))
->setValue('token', $qb->createNamedParameter($share->getToken()))
->setValue('stime', $qb->createFunction('UNIX_TIMESTAMP()'));

if ($parentId > 0) {
$qb->setValue('parent', $qb->createNamedParameter($parentId));
Expand All @@ -98,11 +100,12 @@ public function save(IShare $share, int $parentId = 0): int {
public function update(ShareWrapper $shareWrapper): void {
$qb = $this->getShareUpdateSql();
$qb->set('file_target', $qb->createNamedParameter($shareWrapper->getFileTarget()))
->set('share_with', $qb->createNamedParameter($shareWrapper->getSharedWith()))
->set('uid_owner', $qb->createNamedParameter($shareWrapper->getShareOwner()))
->set('uid_initiator', $qb->createNamedParameter($shareWrapper->getSharedBy()))
->set('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED))
->set('permissions', $qb->createNamedParameter($shareWrapper->getPermissions()));
->set('share_with', $qb->createNamedParameter($shareWrapper->getSharedWith()))
->set('uid_owner', $qb->createNamedParameter($shareWrapper->getShareOwner()))
->set('uid_initiator', $qb->createNamedParameter($shareWrapper->getSharedBy()))
->set('accepted', $qb->createNamedParameter(IShare::STATUS_ACCEPTED))
->set('permissions', $qb->createNamedParameter($shareWrapper->getPermissions()))
->set('expiration', $qb->createNamedParameter($shareWrapper->getExpirationDate(), IQueryBuilder::PARAM_DATE));

$qb->limitToId((int)$shareWrapper->getId());

Expand Down
16 changes: 16 additions & 0 deletions lib/Model/ShareWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ShareWrapper extends ManagedModel implements IDeserializable, IQueryRow, J
private DateTimeInterface $shareTime;
private string $sharedWith = '';
private string $sharedBy = '';
private ?DateTime $expirationDate = null;
private string $shareOwner = '';
private int $shareType = 0;
private ?Circle $circle = null;
Expand Down Expand Up @@ -214,6 +215,16 @@ public function setSharedBy(string $sharedBy): self {
return $this;
}

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

public function setExpirationDate(?DateTime $date):self {
$this->expirationDate = $date;

return $this;
}

public function getSharedBy(): string {
return $this->sharedBy;
}
Expand Down Expand Up @@ -463,6 +474,11 @@ public function import(array $data): IDeserializable {
->setToken($this->get('token', $data))
->setShareTime($shareTime);

try {
$this->setExpirationDate(new DateTime($this->get('expiration', $data)));
} catch (\Exception $e) {
}

$this->setChildId($this->getInt('childId', $data))
->setChildFileTarget($this->get('childFileTarget', $data))
->setChildPermissions($this->getInt('childPermissions', $data))
Expand Down
5 changes: 3 additions & 2 deletions lib/ShareByCircleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ public function create(IShare $share): IShare {
public function update(IShare $share): IShare {
$wrappedShare = $this->shareWrapperService->getShareById((int)$share->getId());
$wrappedShare->setPermissions($share->getPermissions())
->setShareOwner($share->getShareOwner())
->setSharedBy($share->getSharedBy());
->setShareOwner($share->getShareOwner())
->setSharedBy($share->getSharedBy())
->setExpirationDate($share->getExpirationDate());

$this->shareWrapperService->update($wrappedShare);

Expand Down

0 comments on commit a55aae5

Please sign in to comment.