Skip to content

Commit e033e8e

Browse files
committed
fix(recording): create the recording folder as the owning user
The recording and transcript files are created with the owner as the active user, but the folder that holds them is created in getRecordingFolder() outside of that context. For the first recording of a conversation the folder therefore appears in the activity stream as created by "remote account", next to the file that is attributed correctly. Move the user switch into a small runAsUser() helper and use it for the folder lookup as well, so both the folder and the file are attributed to the owner. Signed-off-by: Baki Burak Öğün <burak@burakogun.com>
1 parent bdcf8bd commit e033e8e

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

‎lib/Service/RecordingService.php‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,16 +632,26 @@ private function validateMimeTypeAndExtension(string $fileName, string $mimeType
632632
* @throws NoUserException
633633
*/
634634
private function newFileAsUser(string $owner, Folder $folder, string $fileName, $content): File {
635+
return $this->runAsUser($owner, function () use ($folder, $fileName, $content): File {
636+
return $folder->newFile($fileName, $content);
637+
});
638+
}
639+
640+
/**
641+
* Run the callback with the owner as active user, so that file events and
642+
* activities are attributed to them instead of to nobody.
643+
*/
644+
private function runAsUser(string $owner, callable $callback) {
635645
$user = $this->userManager->get($owner);
636646
if (!$user instanceof IUser) {
637-
return $folder->newFile($fileName, $content);
647+
return $callback();
638648
}
639649

640650
$previousUser = $this->userSession->getUser();
641651
$this->userSession->setUser($user);
642652

643653
try {
644-
return $folder->newFile($fileName, $content);
654+
return $callback();
645655
} finally {
646656
$this->userSession->setUser($previousUser);
647657
}
@@ -652,6 +662,16 @@ private function newFileAsUser(string $owner, Folder $folder, string $fileName,
652662
* @throws NoUserException
653663
*/
654664
private function getRecordingFolder(string $owner, string $token): Folder {
665+
return $this->runAsUser($owner, function () use ($owner, $token): Folder {
666+
return $this->getRecordingFolderInternal($owner, $token);
667+
});
668+
}
669+
670+
/**
671+
* @throws NotPermittedException
672+
* @throws NoUserException
673+
*/
674+
private function getRecordingFolderInternal(string $owner, string $token): Folder {
655675
$userFolder = $this->rootFolder->getUserFolder($owner);
656676
$recordingRootFolderName = $this->config->getRecordingFolder($owner);
657677
try {

0 commit comments

Comments
 (0)