Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com>2021-07-25 18:57:11 +0300
committerJohn Molakvoæ <skjnldsv@users.noreply.github.com>2021-09-06 17:39:11 +0300
commit961f8958c0df8e60ca9fda88d5f46526534eecd9 (patch)
tree6bd65beefbd7012fd211fc3f491b8b567b8a822f /apps/files_sharing/lib
parent33a0b75c83a1c56fa84b98d3a07a26b5c4932b65 (diff)
Let users choose a share_folder
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/Controller/SettingsController.php22
-rw-r--r--apps/files_sharing/lib/External/Manager.php2
-rw-r--r--apps/files_sharing/lib/Helper.php20
-rw-r--r--apps/files_sharing/lib/Settings/Personal.php7
-rw-r--r--apps/files_sharing/lib/SharedMount.php2
5 files changed, 47 insertions, 6 deletions
diff --git a/apps/files_sharing/lib/Controller/SettingsController.php b/apps/files_sharing/lib/Controller/SettingsController.php
index 8f542ecb071..00d627095b8 100644
--- a/apps/files_sharing/lib/Controller/SettingsController.php
+++ b/apps/files_sharing/lib/Controller/SettingsController.php
@@ -6,6 +6,7 @@ declare(strict_types=1);
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Hinrich Mahler <nextcloud@mahlerhome.de>
*
* @license GNU AGPL version 3 or any later version
*
@@ -35,10 +36,13 @@ class SettingsController extends Controller {
/** @var IConfig */
private $config;
+
/** @var string */
private $userId;
- public function __construct(IRequest $request, IConfig $config, string $userId) {
+ public function __construct(IRequest $request,
+ IConfig $config,
+ string $userId) {
parent::__construct(Application::APP_ID, $request);
$this->config = $config;
@@ -52,4 +56,20 @@ class SettingsController extends Controller {
$this->config->setUserValue($this->userId, Application::APP_ID, 'default_accept', $accept ? 'yes' : 'no');
return new JSONResponse();
}
+
+ /**
+ * @NoAdminRequired
+ */
+ public function setUserShareFolder(string $shareFolder): JSONResponse {
+ $this->config->setUserValue($this->userId, Application::APP_ID, 'share_folder', $shareFolder);
+ return new JSONResponse();
+ }
+
+ /**
+ * @NoAdminRequired
+ */
+ public function resetUserShareFolder(): JSONResponse {
+ $this->config->deleteUserValue($this->userId, Application::APP_ID, 'share_folder');
+ return new JSONResponse();
+ }
}
diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php
index f9ef35b558c..d967f40cc32 100644
--- a/apps/files_sharing/lib/External/Manager.php
+++ b/apps/files_sharing/lib/External/Manager.php
@@ -309,7 +309,7 @@ class Manager {
if ($share) {
\OC_Util::setupFS($this->uid);
- $shareFolder = Helper::getShareFolder();
+ $shareFolder = Helper::getShareFolder(null, $this->uid);
$mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']);
$mountPoint = Filesystem::normalizePath($mountPoint);
$hash = md5($mountPoint);
diff --git a/apps/files_sharing/lib/Helper.php b/apps/files_sharing/lib/Helper.php
index d8e58e84b7d..931301a04c4 100644
--- a/apps/files_sharing/lib/Helper.php
+++ b/apps/files_sharing/lib/Helper.php
@@ -29,6 +29,7 @@ namespace OCA\Files_Sharing;
use OC\Files\Filesystem;
use OC\Files\View;
+use OCA\Files_Sharing\AppInfo\Application;
class Helper {
public static function registerHooks() {
@@ -63,16 +64,29 @@ class Helper {
/**
* get default share folder
*
- * @param \OC\Files\View $view
+ * @param \OC\Files\View|null $view
+ * @param string|null $userId
* @return string
*/
- public static function getShareFolder($view = null) {
+ public static function getShareFolder(View $view = null, string $userId = null): string {
if ($view === null) {
$view = Filesystem::getView();
}
- $shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/');
+
+ $config = \OC::$server->getConfig();
+ $systemDefault = $config->getSystemValue('share_folder', '/');
+ $allowCustomShareFolder = $config->getSystemValueBool('sharing.allow_custom_share_folder', true);
+
+ // Init custom shareFolder
+ $shareFolder = $systemDefault;
+ if ($userId !== null && $allowCustomShareFolder) {
+ $shareFolder = $config->getUserValue($userId, Application::APP_ID, 'share_folder', $systemDefault);
+ }
+
+ // Verify and sanitize path
$shareFolder = Filesystem::normalizePath($shareFolder);
+ // Init path if folder doesn't exists
if (!$view->file_exists($shareFolder)) {
$dir = '';
$subdirs = explode('/', $shareFolder);
diff --git a/apps/files_sharing/lib/Settings/Personal.php b/apps/files_sharing/lib/Settings/Personal.php
index 3917001e882..d3886321f97 100644
--- a/apps/files_sharing/lib/Settings/Personal.php
+++ b/apps/files_sharing/lib/Settings/Personal.php
@@ -7,6 +7,7 @@ declare(strict_types=1);
*
* @author Julius Härtl <jus@bitgrid.net>
* @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Hinrich Mahler <nextcloud@mahlerhome.de>
*
* @license GNU AGPL version 3 or any later version
*
@@ -49,10 +50,16 @@ class Personal implements ISettings {
public function getForm(): TemplateResponse {
$defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes';
+ $shareFolderSystemConfig = $this->config->getSystemValue('share_folder', '/');
$acceptDefault = $this->config->getUserValue($this->userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes';
$enforceAccept = $this->config->getSystemValueBool('sharing.force_share_accept', false);
+ $allowCustomDirectory = $this->config->getSystemValueBool('sharing.allow_custom_share_folder', true);
+ $shareFolderDefault = $this->config->getUserValue($this->userId, Application::APP_ID, 'share_folder', $shareFolderSystemConfig);
$this->initialState->provideInitialState('accept_default', $acceptDefault);
$this->initialState->provideInitialState('enforce_accept', $enforceAccept);
+ $this->initialState->provideInitialState('allow_custom_share_folder', $allowCustomDirectory);
+ $this->initialState->provideInitialState('share_folder', $shareFolderDefault);
+ $this->initialState->provideInitialState('default_share_folder', $shareFolderSystemConfig);
return new TemplateResponse('files_sharing', 'Settings/personal');
}
diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php
index 8443ccb8439..7fd477d07e4 100644
--- a/apps/files_sharing/lib/SharedMount.php
+++ b/apps/files_sharing/lib/SharedMount.php
@@ -105,7 +105,7 @@ class SharedMount extends MountPoint implements MoveableMount {
$folderExistCache->set($parent, $parentExists);
}
if (!$parentExists) {
- $parent = Helper::getShareFolder($this->recipientView);
+ $parent = Helper::getShareFolder($this->recipientView, $this->user);
}
$newMountPoint = $this->generateUniqueTarget(