Skip to content

Commit

Permalink
Add expiration event for shares
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv authored and nickvergessen committed Aug 20, 2019
1 parent 650e4f9 commit 1e804d2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
9 changes: 9 additions & 0 deletions apps/files_sharing/lib/Activity/Providers/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ class Groups extends Base {

const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self';
const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by';

const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';

const SUBJECT_EXPIRED_GROUP = 'expired_group_by';

/** @var IGroupManager */
protected $groupManager;

Expand Down Expand Up @@ -73,6 +76,8 @@ public function parseShortVersion(IEvent $event) {
$subject = $this->l->t('{actor} shared with group {group}');
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
$subject = $this->l->t('{actor} removed share for group {group}');
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) {
$subject = $this->l->t('Share for group {group} expired');
} else {
throw new \InvalidArgumentException();
}
Expand Down Expand Up @@ -104,6 +109,8 @@ public function parseLongVersion(IEvent $event) {
$subject = $this->l->t('{actor} shared {file} with group {group}');
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
$subject = $this->l->t('{actor} removed group {group} from {file}');
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) {
$subject = $this->l->t('Shared file {file} with group {group} expired');
} else {
throw new \InvalidArgumentException();
}
Expand Down Expand Up @@ -132,6 +139,8 @@ protected function getParsedParameters(IEvent $event) {
];
case self::SUBJECT_SHARED_GROUP_SELF:
case self::SUBJECT_UNSHARED_GROUP_SELF:
case self::SUBJECT_UNSHARED_GROUP_BY:
case self::SUBJECT_EXPIRED_GROUP:
return [
'file' => $this->getFile($parameters[0], $event),
'group' => $this->generateGroupParameter($parameters[1]),
Expand Down
14 changes: 13 additions & 1 deletion apps/files_sharing/lib/Activity/Providers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class Users extends Base {
const SUBJECT_SELF_UNSHARED = 'self_unshared';
const SUBJECT_SELF_UNSHARED_BY = 'self_unshared_by';

const SUBJECT_EXPIRED_USER = 'expired_user_by';
const SUBJECT_EXPIRED_BY = 'expired_by';

/**
* @param IEvent $event
* @return IEvent
Expand All @@ -63,7 +66,10 @@ public function parseShortVersion(IEvent $event) {
$subject = $this->l->t('Shared by {actor}');
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
$subject = $this->l->t('{actor} removed share');

} else if ($event->getSubject() === self::SUBJECT_EXPIRED_USER) {
$subject = $this->l->t('Share for {user} expired');
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_BY) {
$subject = $this->l->t('Share expired');
} else {
throw new \InvalidArgumentException();
}
Expand Down Expand Up @@ -103,6 +109,10 @@ public function parseLongVersion(IEvent $event) {
$subject = $this->l->t('{actor} shared {file} with you');
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
$subject = $this->l->t('{actor} removed you from the share named {file}');
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_USER) {
$subject = $this->l->t('Shared file {file} with {user} expired');
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_BY) {
$subject = $this->l->t('Shared file {file} expired');

} else {
throw new \InvalidArgumentException();
Expand All @@ -125,6 +135,8 @@ protected function getParsedParameters(IEvent $event) {
switch ($subject) {
case self::SUBJECT_SHARED_USER_SELF:
case self::SUBJECT_UNSHARED_USER_SELF:
case self::SUBJECT_EXPIRED_USER:
case self::SUBJECT_EXPIRED_BY:
return [
'file' => $this->getFile($parameters[0], $event),
'user' => $this->getUser($parameters[1]),
Expand Down
3 changes: 1 addition & 2 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,7 @@ public function getShareByToken($token) {
}

protected function checkExpireDate($share) {
if ($share->getExpirationDate() !== null &&
$share->getExpirationDate() <= new \DateTime()) {
if ($share->isExpired()) {
$this->deleteShare($share);
throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
}
Expand Down
8 changes: 8 additions & 0 deletions lib/private/Share20/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ public function getExpirationDate() {
return $this->expireDate;
}

/**
* @inheritdoc
*/
public function isExpired() {
return $this->getExpirationDate() !== null &&
$this->getExpirationDate() <= new \DateTime();
}

/**
* @inheritdoc
*/
Expand Down
8 changes: 8 additions & 0 deletions lib/public/Share/IShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ public function setExpirationDate($expireDate);
*/
public function getExpirationDate();

/**
* Is the share expired ?
*
* @return boolean
* @since 18.0.0
*/
public function isExpired();

/**
* set a label for a share, some shares, e.g. public links can have a label
*
Expand Down

0 comments on commit 1e804d2

Please sign in to comment.