Skip to content

Commit

Permalink
Merge pull request #383 from nextcloud/fix/sharing/unshare-message
Browse files Browse the repository at this point in the history
Add expiration event for shares
  • Loading branch information
skjnldsv authored Aug 26, 2019
2 parents 5ab2987 + 5828af5 commit dd899ae
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -808,17 +808,27 @@ protected function unshareFromUser(IShare $share) {
return;
}

if ($share->isExpired()) {
$actionSharer = 'expired_user';
$actionOwner = 'expired_user';
$actionUser = 'expired';
} else {
$actionSharer = 'unshared_user_self';
$actionOwner = 'unshared_user_by';
$actionUser = 'unshared_by';
}

// User performing the share
$this->shareNotificationForSharer('unshared_user_self', $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
$this->shareNotificationForSharer($actionSharer, $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());

// Owner
if ($this->currentUser->getUID() !== null) {
$this->shareNotificationForOriginalOwners($this->currentUser->getUID(), 'unshared_user_by', $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
$this->shareNotificationForOriginalOwners($this->currentUser->getUID(), $actionOwner, $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
}

// Recipient
$this->addNotificationsForUser(
$share->getSharedWith(), 'unshared_by', [[$share->getNodeId() => $share->getTarget()], $this->currentUser->getUserIdentifier()],
$share->getSharedWith(), $actionUser, [[$share->getNodeId() => $share->getTarget()], $this->currentUser->getUserIdentifier()],
$share->getNodeId(), $share->getTarget(), $share->getNodeType() === 'file',
$this->userSettings->getUserSetting($share->getSharedWith(), 'stream', Files_Sharing::TYPE_SHARED),
$this->userSettings->getUserSetting($share->getSharedWith(), 'email', Files_Sharing::TYPE_SHARED) ? $this->userSettings->getUserSetting($share->getSharedWith(), 'setting', 'batchtime') : false
Expand Down Expand Up @@ -854,16 +864,26 @@ protected function unshareFromGroup(IShare $share) {
return;
}

if ($share->isExpired()) {
$actionSharer = 'expired_group';
$actionOwner = 'expired_group';
$actionUser = 'expired';
} else {
$actionSharer = 'unshared_group_self';
$actionOwner = 'unshared_group_by';
$actionUser = 'unshared_by';
}

// User performing the share
$this->shareNotificationForSharer('unshared_group_self', $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
$this->shareNotificationForSharer($actionSharer, $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
if ($this->currentUser->getUID() !== null) {
$this->shareNotificationForOriginalOwners($this->currentUser->getUID(), 'unshared_group_by', $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
$this->shareNotificationForOriginalOwners($this->currentUser->getUID(), $actionOwner, $share->getSharedWith(), $share->getNodeId(), $share->getNodeType());
}

$offset = 0;
$users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
while (!empty($users)) {
$this->addNotificationsForGroupUsers($users, 'unshared_by', $share->getNodeId(), $share->getNodeType(), $share->getTarget(), $share->getId());
$this->addNotificationsForGroupUsers($users, $actionUser, $share->getNodeId(), $share->getNodeType(), $share->getTarget(), $share->getId());
$offset += self::USER_BATCH_SIZE;
$users = $group->searchUsers('', self::USER_BATCH_SIZE, $offset);
}
Expand Down Expand Up @@ -893,7 +913,8 @@ protected function unshareFromSelfGroup(IShare $share) {
*/
protected function unshareLink(IShare $share) {
$owner = $share->getSharedBy();
if ($this->currentUser->getUID() === null) {

if ($share->isExpired()) {
// Link expired
$actionSharer = 'link_expired';
$actionOwner = 'link_by_expired';
Expand Down

0 comments on commit dd899ae

Please sign in to comment.