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

github.com/nextcloud/documentserver_community.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-10-06 15:53:36 +0300
committerRobin Appelman <robin@icewind.nl>2020-10-06 15:53:36 +0300
commitb42f87fe08b721474d1cd008f60f61586a12bdee (patch)
tree9eb111f9d8116a5911d0b6b36c58195152c5821a
parentaf19fccb3481ff3f896eb3175bffa3406c3a964b (diff)
set current user during file hooks
-rw-r--r--lib/Document/DocumentStore.php15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Document/DocumentStore.php b/lib/Document/DocumentStore.php
index 20034b8..2bf8457 100644
--- a/lib/Document/DocumentStore.php
+++ b/lib/Document/DocumentStore.php
@@ -34,6 +34,7 @@ use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\IUserSession;
class DocumentStore {
private $appData;
@@ -42,6 +43,7 @@ class DocumentStore {
private $rootFolder;
private $userManager;
private $localAppData;
+ private $userSession;
public function __construct(
IAppData $appData,
@@ -49,7 +51,8 @@ class DocumentStore {
IConfig $config,
IRootFolder $rootFolder,
IUserManager $userManager,
- LocalAppData $localAppData
+ LocalAppData $localAppData,
+ IUserSession $userSession
) {
$this->appData = $appData;
$this->documentConverter = $documentConverter;
@@ -57,6 +60,7 @@ class DocumentStore {
$this->rootFolder = $rootFolder;
$this->userManager = $userManager;
$this->localAppData = $localAppData;
+ $this->userSession = $userSession;
}
private function getDocumentFolder(int $documentId): ISimpleFolder {
@@ -146,7 +150,7 @@ class DocumentStore {
$targetExtension = $sourceFile->getExtension();
- $this->localAppData->getReadWriteLocalPath($docFolder, function (string $localPath) use ($changes, $targetExtension, $sourceFile) {
+ $this->localAppData->getReadWriteLocalPath($docFolder, function (string $localPath) use ($owner, $changes, $targetExtension, $sourceFile) {
$target = $localPath . '/saved.' . $targetExtension;
$this->documentConverter->saveChanges($localPath, $changes, $target, $targetExtension);
@@ -160,7 +164,14 @@ class DocumentStore {
Filesystem::init($user, $userDir);
}
+ // set owner in user session for file hooks
+ $ownerObject = $this->userManager->get($owner);
+ $oldUser = $this->userSession->getUser();
+ $this->userSession->setUser($ownerObject);
+
$sourceFile->putContent(stream_get_contents($savedContent));
+
+ $this->userSession->setUser($oldUser);
});
}