From c8d50538b8488b56f252fbbb23893adf1b807471 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?=
 <skjnldsv@protonmail.com>
Date: Thu, 1 Aug 2019 13:56:35 +0200
Subject: [PATCH] Use same settings for mail share as link shares
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
---
 .../lib/Controller/ShareAPIController.php     | 33 ++++++++-----------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 86573bcfd79..5072db60fc4 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -453,8 +453,10 @@ class ShareAPIController extends OCSController {
 			}
 			$share->setSharedWith($shareWith);
 			$share->setPermissions($permissions);
-		} else if ($shareType === Share::SHARE_TYPE_LINK) {
-			//Can we even share links?
+		} else if ($shareType === Share::SHARE_TYPE_LINK
+			|| $shareType === Share::SHARE_TYPE_EMAIL) {
+
+			// Can we even share links?
 			if (!$this->shareManager->shareApiAllowLinks()) {
 				throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator'));
 			}
@@ -485,11 +487,17 @@ class ShareAPIController extends OCSController {
 				$share->setPassword($password);
 			}
 
-
-			if (!empty($label)) {
-				$share->setLabel($label);
+			// Only share by mail have a recipient
+			if ($shareType === Share::SHARE_TYPE_EMAIL) {
+				$share->setSharedWith($shareWith);
+			} else {
+				// Only link share have a label
+				if (!empty($label)) {
+					$share->setLabel($label);
+				}
 			}
 
+
 			if ($sendPasswordByTalk === 'true') {
 				if (!$this->appManager->isEnabledForUser('spreed')) {
 					throw new OCSForbiddenException($this->l->t('Sharing %s sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled', [$path->getPath()]));
@@ -522,21 +530,6 @@ class ShareAPIController extends OCSController {
 
 			$share->setSharedWith($shareWith);
 			$share->setPermissions($permissions);
-		} else if ($shareType === Share::SHARE_TYPE_EMAIL) {
-			if ($share->getNodeType() === 'file') {
-				$share->setPermissions(Constants::PERMISSION_READ);
-			} else {
-				$share->setPermissions($permissions);
-			}
-			$share->setSharedWith($shareWith);
-
-			if ($sendPasswordByTalk === 'true') {
-				if (!$this->appManager->isEnabledForUser('spreed')) {
-					throw new OCSForbiddenException($this->l->t('Sharing %s sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled', [$path->getPath()]));
-				}
-
-				$share->setSendPasswordByTalk(true);
-			}
 		} else if ($shareType === Share::SHARE_TYPE_CIRCLE) {
 			if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) {
 				throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled'));
-- 
GitLab