Merge pull request #16723 from nextcloud/fix/sharing/unshare-message

Add expiration event for shares
This commit is contained in:
Joas Schilling 2019-08-26 12:58:51 +02:00 committed by GitHub
commit b1a0d464ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 3 deletions

View File

@ -35,9 +35,12 @@ class Groups extends Base {
const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self'; const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self';
const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by'; const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by';
const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self'; const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self';
const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by'; const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by';
const SUBJECT_EXPIRED_GROUP = 'expired_group';
/** @var IGroupManager */ /** @var IGroupManager */
protected $groupManager; protected $groupManager;
@ -73,6 +76,8 @@ class Groups extends Base {
$subject = $this->l->t('{actor} shared with group {group}'); $subject = $this->l->t('{actor} shared with group {group}');
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
$subject = $this->l->t('{actor} removed share for group {group}'); $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 { } else {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
} }
@ -104,6 +109,8 @@ class Groups extends Base {
$subject = $this->l->t('{actor} shared {file} with group {group}'); $subject = $this->l->t('{actor} shared {file} with group {group}');
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { } else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) {
$subject = $this->l->t('{actor} removed group {group} from {file}'); $subject = $this->l->t('{actor} removed group {group} from {file}');
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_GROUP) {
$subject = $this->l->t('Share for file {file} with group {group} expired');
} else { } else {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
} }
@ -132,6 +139,7 @@ class Groups extends Base {
]; ];
case self::SUBJECT_SHARED_GROUP_SELF: case self::SUBJECT_SHARED_GROUP_SELF:
case self::SUBJECT_UNSHARED_GROUP_SELF: case self::SUBJECT_UNSHARED_GROUP_SELF:
case self::SUBJECT_EXPIRED_GROUP:
return [ return [
'file' => $this->getFile($parameters[0], $event), 'file' => $this->getFile($parameters[0], $event),
'group' => $this->generateGroupParameter($parameters[1]), 'group' => $this->generateGroupParameter($parameters[1]),

View File

@ -38,6 +38,9 @@ class Users extends Base {
const SUBJECT_SELF_UNSHARED = 'self_unshared'; const SUBJECT_SELF_UNSHARED = 'self_unshared';
const SUBJECT_SELF_UNSHARED_BY = 'self_unshared_by'; const SUBJECT_SELF_UNSHARED_BY = 'self_unshared_by';
const SUBJECT_EXPIRED_USER = 'expired_user';
const SUBJECT_EXPIRED = 'expired';
/** /**
* @param IEvent $event * @param IEvent $event
* @return IEvent * @return IEvent
@ -63,7 +66,10 @@ class Users extends Base {
$subject = $this->l->t('Shared by {actor}'); $subject = $this->l->t('Shared by {actor}');
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
$subject = $this->l->t('{actor} removed share'); $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) {
$subject = $this->l->t('Share expired');
} else { } else {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
} }
@ -103,6 +109,10 @@ class Users extends Base {
$subject = $this->l->t('{actor} shared {file} with you'); $subject = $this->l->t('{actor} shared {file} with you');
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) { } else if ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
$subject = $this->l->t('{actor} removed you from the share named {file}'); $subject = $this->l->t('{actor} removed you from the share named {file}');
} else if ($event->getSubject() === self::SUBJECT_EXPIRED_USER) {
$subject = $this->l->t('Share for file {file} with {user} expired');
} else if ($event->getSubject() === self::SUBJECT_EXPIRED) {
$subject = $this->l->t('Share for file {file} expired');
} else { } else {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
@ -125,6 +135,8 @@ class Users extends Base {
switch ($subject) { switch ($subject) {
case self::SUBJECT_SHARED_USER_SELF: case self::SUBJECT_SHARED_USER_SELF:
case self::SUBJECT_UNSHARED_USER_SELF: case self::SUBJECT_UNSHARED_USER_SELF:
case self::SUBJECT_EXPIRED_USER:
case self::SUBJECT_EXPIRED:
return [ return [
'file' => $this->getFile($parameters[0], $event), 'file' => $this->getFile($parameters[0], $event),
'user' => $this->getUser($parameters[1]), 'user' => $this->getUser($parameters[1]),

View File

@ -1313,8 +1313,7 @@ class Manager implements IManager {
} }
protected function checkExpireDate($share) { protected function checkExpireDate($share) {
if ($share->getExpirationDate() !== null && if ($share->isExpired()) {
$share->getExpirationDate() <= new \DateTime()) {
$this->deleteShare($share); $this->deleteShare($share);
throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); throw new ShareNotFound($this->l->t('The requested share does not exist anymore'));
} }

View File

@ -368,6 +368,14 @@ class Share implements \OCP\Share\IShare {
return $this->expireDate; return $this->expireDate;
} }
/**
* @inheritdoc
*/
public function isExpired() {
return $this->getExpirationDate() !== null &&
$this->getExpirationDate() <= new \DateTime();
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@ -314,6 +314,14 @@ interface IShare {
*/ */
public function getExpirationDate(); 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 * set a label for a share, some shares, e.g. public links can have a label
* *