summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-09-04 16:50:52 +0200
committerJoas Schilling <coding@schilljs.com>2019-11-12 17:36:58 +0100
commit520042bbd0512e19717d18705c3b045b2d8400a7 (patch)
tree286e21a2dd06feca025a7dabe2dcbb63d65c5498 /apps/files_sharing/lib
parentc79a56481bc4bd9fb94b0dfbf483537400c76569 (diff)
downloadnextcloud-server-520042bbd0512e19717d18705c3b045b2d8400a7.tar.gz
nextcloud-server-520042bbd0512e19717d18705c3b045b2d8400a7.zip
Allow to accept group shares
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php16
-rw-r--r--apps/files_sharing/lib/Notification/Listener.php5
-rw-r--r--apps/files_sharing/lib/Notification/Notifier.php94
3 files changed, 85 insertions, 30 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index acb95a0a3d3..9c5f6abee68 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -962,19 +962,17 @@ class ShareAPIController extends OCSController {
throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
}
- if (!$this->canAccessShare($share, false)) {
+ if (!$this->canAccessShare($share)) {
throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
}
- if ($share->getShareType() !== Share::SHARE_TYPE_USER ||
- $share->getSharedWith() !== $this->currentUser) {
- throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist'));
+ if ($share->getShareType() !== IShare::TYPE_USER &&
+ $share->getShareType() !== IShare::TYPE_GROUP) {
+ throw new OCSNotFoundException($this->l->t('Share type does not support accepting'));
}
- $share->setStatus(IShare::STATUS_ACCEPTED);
-
try {
- $this->shareManager->updateShare($share);
+ $this->shareManager->acceptShare($share, $this->currentUser);
} catch (GenericShareException $e) {
$code = $e->getCode() === 0 ? 403 : $e->getCode();
throw new OCSException($e->getHint(), $code);
@@ -1117,8 +1115,8 @@ class ShareAPIController extends OCSController {
* @suppress PhanUndeclaredClassMethod
*/
protected function canDeleteShareFromSelf(\OCP\Share\IShare $share): bool {
- if ($share->getShareType() !== Share::SHARE_TYPE_GROUP &&
- $share->getShareType() !== Share::SHARE_TYPE_ROOM
+ if ($share->getShareType() !== IShare::TYPE_GROUP &&
+ $share->getShareType() !== IShare::TYPE_ROOM
) {
return false;
}
diff --git a/apps/files_sharing/lib/Notification/Listener.php b/apps/files_sharing/lib/Notification/Listener.php
index b2e00613e70..fd4daca28e7 100644
--- a/apps/files_sharing/lib/Notification/Listener.php
+++ b/apps/files_sharing/lib/Notification/Listener.php
@@ -63,6 +63,11 @@ class Listener {
$group = $this->groupManager->get($share->getSharedWith());
foreach ($group->getUsers() as $user) {
+ if ($user->getUID() === $share->getShareOwner() ||
+ $user->getUID() === $share->getSharedBy()) {
+ continue;
+ }
+
$notification->setUser($user->getUID());
$this->notificationManager->notify($notification);
}
diff --git a/apps/files_sharing/lib/Notification/Notifier.php b/apps/files_sharing/lib/Notification/Notifier.php
index 6ae009895d3..03d7038e6fe 100644
--- a/apps/files_sharing/lib/Notification/Notifier.php
+++ b/apps/files_sharing/lib/Notification/Notifier.php
@@ -28,7 +28,10 @@ namespace OCA\Files_Sharing\Notification;
use OCP\Files\IRootFolder;
use OCP\IL10N;
+use OCP\IGroupManager;
use OCP\IURLGenerator;
+use OCP\IUser;
+use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\INotification;
@@ -45,6 +48,10 @@ class Notifier implements INotifier {
private $shareManager;
/** @var IRootFolder */
private $rootFolder;
+ /** @var IGroupManager */
+ protected $groupManager;
+ /** @var IUserManager */
+ protected $userManager;
/** @var IURLGenerator */
protected $url;
@@ -52,10 +59,14 @@ class Notifier implements INotifier {
public function __construct(IFactory $l10nFactory,
IManager $shareManager,
IRootFolder $rootFolder,
+ IGroupManager $groupManager,
+ IUserManager $userManager,
IURLGenerator $url) {
$this->l10nFactory = $l10nFactory;
$this->shareManager = $shareManager;
$this->rootFolder = $rootFolder;
+ $this->groupManager = $groupManager;
+ $this->userManager = $userManager;
$this->url = $url;
}
@@ -135,11 +146,12 @@ class Notifier implements INotifier {
}
protected function parseShareInvitation(IShare $share, INotification $notification, IL10N $l): INotification {
+
if ($share->getShareType() === IShare::TYPE_USER) {
- if ($share->getSharedWith() !== $notification->getUser()) {
+ if ($share->getStatus() !== IShare::STATUS_PENDING) {
throw new AlreadyProcessedException();
}
-
+ } else if ($share->getShareType() === IShare::TYPE_GROUP) {
if ($share->getStatus() !== IShare::STATUS_PENDING) {
throw new AlreadyProcessedException();
}
@@ -147,6 +159,10 @@ class Notifier implements INotifier {
switch ($notification->getSubject()) {
case 'incoming_user_share':
+ if ($share->getSharedWith() !== $notification->getUser()) {
+ throw new AlreadyProcessedException();
+ }
+
$subject = $l->t('You received {share} as a share from {user}');
$subjectParameters = [
'share' => [
@@ -160,34 +176,70 @@ class Notifier implements INotifier {
'name' => $share->getShareOwner(),
],
];
+ break;
- $placeholders = $replacements = [];
- foreach ($subjectParameters as $placeholder => $parameter) {
- $placeholders[] = '{' . $placeholder . '}';
- $replacements[] = $parameter['name'];
+ case 'incoming_group_share':
+ $user = $this->userManager->get($notification->getUser());
+ if (!$user instanceof IUser) {
+ throw new AlreadyProcessedException();
}
- $notification->setParsedSubject(str_replace($placeholders, $replacements, $subject))
- ->setRichSubject($subject, $subjectParameters)
- ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
-
- $acceptAction = $notification->createAction();
- $acceptAction->setParsedLabel($l->t('Accept'))
- ->setLink($this->url->linkToOCSRouteAbsolute('files_sharing.ShareAPI.acceptShare', ['id' => $share->getId()]), 'POST')
- ->setPrimary(true);
- $notification->addParsedAction($acceptAction);
+ $group = $this->groupManager->get($share->getSharedWith());
+ if (!$group->inGroup($user)) {
+ throw new AlreadyProcessedException();
+ }
- $rejectAction = $notification->createAction();
- $rejectAction->setParsedLabel($l->t('Reject'))
- ->setLink($this->url->linkToOCSRouteAbsolute('files_sharing.ShareAPI.deleteShare', ['id' => $share->getId()]), 'DELETE')
- ->setPrimary(false);
- $notification->addParsedAction($rejectAction);
+ if ($share->getPermissions() === 0) {
+ // Already rejected
+ throw new AlreadyProcessedException();
+ }
- return $notification;
+ $subject = $l->t('You received {share} to group {group} as a share from {user}');
+ $subjectParameters = [
+ 'share' => [
+ 'type' => 'highlight',
+ 'id' => $notification->getObjectId(),
+ 'name' => $share->getNode()->getName(),
+ ],
+ 'group' => [
+ 'type' => 'user-group',
+ 'id' => $group->getGID(),
+ 'name' => $group->getDisplayName(),
+ ],
+ 'user' => [
+ 'type' => 'user',
+ 'id' => $share->getShareOwner(),
+ 'name' => $share->getShareOwner(),
+ ],
+ ];
break;
default:
throw new \InvalidArgumentException('Invalid subject');
}
+
+ $placeholders = $replacements = [];
+ foreach ($subjectParameters as $placeholder => $parameter) {
+ $placeholders[] = '{' . $placeholder . '}';
+ $replacements[] = $parameter['name'];
+ }
+
+ $notification->setParsedSubject(str_replace($placeholders, $replacements, $subject))
+ ->setRichSubject($subject, $subjectParameters)
+ ->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
+
+ $acceptAction = $notification->createAction();
+ $acceptAction->setParsedLabel($l->t('Accept'))
+ ->setLink($this->url->linkToOCSRouteAbsolute('files_sharing.ShareAPI.acceptShare', ['id' => $share->getId()]), 'POST')
+ ->setPrimary(true);
+ $notification->addParsedAction($acceptAction);
+
+ $rejectAction = $notification->createAction();
+ $rejectAction->setParsedLabel($l->t('Reject'))
+ ->setLink($this->url->linkToOCSRouteAbsolute('files_sharing.ShareAPI.deleteShare', ['id' => $share->getId()]), 'DELETE')
+ ->setPrimary(false);
+ $notification->addParsedAction($rejectAction);
+
+ return $notification;
}
}