Skip to content

Commit b1a0d46

Browse files
Merge pull request #16723 from nextcloud/fix/sharing/unshare-message
Add expiration event for shares
2 parents 40edaba + b557f52 commit b1a0d46

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

apps/files_sharing/lib/Activity/Providers/Groups.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ class Groups extends Base {
3535

3636
const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self';
3737
const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by';
38+
3839
const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
3940
const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';
4041

42+
const SUBJECT_EXPIRED_GROUP = 'expired_group';
43+
4144
/** @var IGroupManager */
4245
protected $groupManager;
4346

@@ -73,6 +76,8 @@ public function parseShortVersion(IEvent $event) {
7376
$subject = $this->l->t('{actor} shared with group {group}');
7477
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
7578
$subject = $this->l->t('{actor} removed share for group {group}');
79+
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) {
80+
$subject = $this->l->t('Share for group {group} expired');
7681
} else {
7782
throw new \InvalidArgumentException();
7883
}
@@ -104,6 +109,8 @@ public function parseLongVersion(IEvent $event) {
104109
$subject = $this->l->t('{actor} shared {file} with group {group}');
105110
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
106111
$subject = $this->l->t('{actor} removed group {group} from {file}');
112+
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) {
113+
$subject = $this->l->t('Share for file {file} with group {group} expired');
107114
} else {
108115
throw new \InvalidArgumentException();
109116
}
@@ -132,6 +139,7 @@ protected function getParsedParameters(IEvent $event) {
132139
];
133140
case self::SUBJECT_SHARED_GROUP_SELF:
134141
case self::SUBJECT_UNSHARED_GROUP_SELF:
142+
case self::SUBJECT_EXPIRED_GROUP:
135143
return [
136144
'file' => $this->getFile($parameters[0], $event),
137145
'group' => $this->generateGroupParameter($parameters[1]),

apps/files_sharing/lib/Activity/Providers/Users.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class Users extends Base {
3838
const SUBJECT_SELF_UNSHARED = 'self_unshared';
3939
const SUBJECT_SELF_UNSHARED_BY = 'self_unshared_by';
4040

41+
const SUBJECT_EXPIRED_USER = 'expired_user';
42+
const SUBJECT_EXPIRED = 'expired';
43+
4144
/**
4245
* @param IEvent $event
4346
* @return IEvent
@@ -63,7 +66,10 @@ public function parseShortVersion(IEvent $event) {
6366
$subject = $this->l->t('Shared by {actor}');
6467
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
6568
$subject = $this->l->t('{actor} removed share');
66-
69+
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_USER) {
70+
$subject = $this->l->t('Share for {user} expired');
71+
} else if ($event->getSubject() === self::SUBJECT_EXPIRED) {
72+
$subject = $this->l->t('Share expired');
6773
} else {
6874
throw new \InvalidArgumentException();
6975
}
@@ -103,6 +109,10 @@ public function parseLongVersion(IEvent $event) {
103109
$subject = $this->l->t('{actor} shared {file} with you');
104110
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
105111
$subject = $this->l->t('{actor} removed you from the share named {file}');
112+
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_USER) {
113+
$subject = $this->l->t('Share for file {file} with {user} expired');
114+
} else if ($event->getSubject() === self::SUBJECT_EXPIRED) {
115+
$subject = $this->l->t('Share for file {file} expired');
106116

107117
} else {
108118
throw new \InvalidArgumentException();
@@ -125,6 +135,8 @@ protected function getParsedParameters(IEvent $event) {
125135
switch ($subject) {
126136
case self::SUBJECT_SHARED_USER_SELF:
127137
case self::SUBJECT_UNSHARED_USER_SELF:
138+
case self::SUBJECT_EXPIRED_USER:
139+
case self::SUBJECT_EXPIRED:
128140
return [
129141
'file' => $this->getFile($parameters[0], $event),
130142
'user' => $this->getUser($parameters[1]),

lib/private/Share20/Manager.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,7 @@ public function getShareByToken($token) {
13131313
}
13141314

13151315
protected function checkExpireDate($share) {
1316-
if ($share->getExpirationDate() !== null &&
1317-
$share->getExpirationDate() <= new \DateTime()) {
1316+
if ($share->isExpired()) {
13181317
$this->deleteShare($share);
13191318
throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
13201319
}

lib/private/Share20/Share.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ public function getExpirationDate() {
368368
return $this->expireDate;
369369
}
370370

371+
/**
372+
* @inheritdoc
373+
*/
374+
public function isExpired() {
375+
return $this->getExpirationDate() !== null &&
376+
$this->getExpirationDate() <= new \DateTime();
377+
}
378+
371379
/**
372380
* @inheritdoc
373381
*/

lib/public/Share/IShare.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ public function setExpirationDate($expireDate);
314314
*/
315315
public function getExpirationDate();
316316

317+
/**
318+
* Is the share expired ?
319+
*
320+
* @return boolean
321+
* @since 18.0.0
322+
*/
323+
public function isExpired();
324+
317325
/**
318326
* set a label for a share, some shares, e.g. public links can have a label
319327
*

0 commit comments

Comments
 (0)