Skip to content

Commit 4b8351a

Browse files
committed
Add expiration event for shares
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent a3d0a5c commit 4b8351a

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

lib/FilesHooks.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -793,17 +793,28 @@ protected function unshareFromUser(IShare $share) {
793793
return;
794794
}
795795

796+
if ($share->isExpired()) {
797+
// Link expired
798+
$actionSharer = 'expired_user_by';
799+
$actionOwner = 'expired_user_by';
800+
$actionUser = 'expired_by';
801+
} else {
802+
$actionSharer = 'unshared_user_self';
803+
$actionOwner = 'unshared_user_by';
804+
$actionUser = 'unshared_by';
805+
}
806+
796807
// User performing the share
797-
$this->shareNotificationForSharer('unshared_user_self', $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
808+
$this->shareNotificationForSharer($actionSharer, $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
798809

799810
// Owner
800811
if ($this->currentUser->getUID() !== null) {
801-
$this->shareNotificationForOriginalOwners($this->currentUser->getUID(), 'unshared_user_by', $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
812+
$this->shareNotificationForOriginalOwners($this->currentUser->getUID(), $actionOwner, $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
802813
}
803814

804815
// Recipient
805816
$this->addNotificationsForUser(
806-
$share->getSharedWith(), 'unshared_by', [[$share->getNodeId() => $share->getTarget()], $this->currentUser->getUserIdentifier()],
817+
$share->getSharedWith(), $actionUser, [[$share->getNodeId() => $share->getTarget()], $this->currentUser->getUserIdentifier()],
807818
$share->getNodeId(), $share->getTarget(), $share->getNodeType() === 'file',
808819
$this->userSettings->getUserSetting($share->getSharedWith(), 'stream', Files_Sharing::TYPE_SHARED),
809820
$this->userSettings->getUserSetting($share->getSharedWith(), 'email', Files_Sharing::TYPE_SHARED) ? $this->userSettings->getUserSetting($share->getSharedWith(), 'setting', 'batchtime') : false
@@ -839,16 +850,27 @@ protected function unshareFromGroup(IShare $share) {
839850
return;
840851
}
841852

853+
if ($share->isExpired()) {
854+
// Link expired
855+
$actionSharer = 'expired_group_by';
856+
$actionOwner = 'expired_group_by';
857+
$actionUser = 'expired_by';
858+
} else {
859+
$actionSharer = 'unshared_group_self';
860+
$actionOwner = 'unshared_group_by';
861+
$actionUser = 'unshared_by';
862+
}
863+
842864
// User performing the share
843-
$this->shareNotificationForSharer('unshared_group_self', $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
865+
$this->shareNotificationForSharer($actionSharer, $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
844866
if ($this->currentUser->getUID() !== null) {
845-
$this->shareNotificationForOriginalOwners($this->currentUser->getUID(), 'unshared_group_by', $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
867+
$this->shareNotificationForOriginalOwners($this->currentUser->getUID(), $actionOwner, $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
846868
}
847869

848870
$offset = 0;
849871
$users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
850872
while (!empty($users)) {
851-
$this->addNotificationsForGroupUsers($users, 'unshared_by', $share->getNodeId(), $share->getNodeType(), $share->getTarget(), $share->getId());
873+
$this->addNotificationsForGroupUsers($users, $actionUser, $share->getNodeId(), $share->getNodeType(), $share->getTarget(), $share->getId());
852874
$offset += self::USER_BATCH_SIZE;
853875
$users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
854876
}
@@ -862,7 +884,8 @@ protected function unshareFromGroup(IShare $share) {
862884
*/
863885
protected function unshareLink(IShare $share) {
864886
$owner = $share->getSharedBy();
865-
if ($this->currentUser->getUID() === null) {
887+
888+
if ($share->isExpired()) {
866889
// Link expired
867890
$actionSharer = 'link_expired';
868891
$actionOwner = 'link_by_expired';

0 commit comments

Comments
 (0)