|
24 | 24 | use OCP\Files\InvalidPathException; |
25 | 25 | use OCP\Files\IRootFolder; |
26 | 26 | use OCP\Files\NotPermittedException; |
| 27 | +use OCP\IAppConfig; |
27 | 28 | use OCP\IConfig; |
28 | 29 | use OCP\IL10N; |
29 | 30 | use OCP\ITempManager; |
@@ -91,6 +92,7 @@ public function __construct( |
91 | 92 | private IL10N $l10n, |
92 | 93 | private ITempManager $tempManager, |
93 | 94 | private IConfig $config, |
| 95 | + private IAppConfig $appConfig, |
94 | 96 | private IShareManager $shareManager, |
95 | 97 | private SystemTagService $systemTagService, |
96 | 98 | ) { |
@@ -522,41 +524,54 @@ public function storeInputFile(string $userId, string $tempFileLocation, ?string |
522 | 524 | public function getAssistantDataFolder(string $userId): Folder { |
523 | 525 | $userFolder = $this->rootFolder->getUserFolder($userId); |
524 | 526 |
|
525 | | - $dataFolderName = $this->config->getUserValue($userId, Application::APP_ID, 'data_folder', Application::ASSISTANT_DATA_FOLDER_NAME) ?: Application::ASSISTANT_DATA_FOLDER_NAME; |
| 527 | + $defaultFolderName = $this->appConfig->getValueString(Application::APP_ID, 'default_data_folder', Application::ASSISTANT_DATA_FOLDER_NAME, lazy: true); |
| 528 | + if ($defaultFolderName === '') { |
| 529 | + $defaultFolderName = Application::ASSISTANT_DATA_FOLDER_NAME; |
| 530 | + } |
| 531 | + $dataFolderName = $this->config->getUserValue($userId, Application::APP_ID, 'data_folder', ''); |
| 532 | + if ($dataFolderName === '') { |
| 533 | + // No folder stored for this user. If they already have one under the built-in |
| 534 | + // name, from before an administrator set a default, keep using it: applying the |
| 535 | + // default here would start a second folder and leave their existing output behind. |
| 536 | + $dataFolderName = $userFolder->nodeExists(Application::ASSISTANT_DATA_FOLDER_NAME) |
| 537 | + ? Application::ASSISTANT_DATA_FOLDER_NAME |
| 538 | + : $defaultFolderName; |
| 539 | + } |
526 | 540 | if ($userFolder->nodeExists($dataFolderName)) { |
527 | 541 | $dataFolderNode = $userFolder->get($dataFolderName); |
528 | 542 | if ($dataFolderNode instanceof Folder && $dataFolderNode->isCreatable()) { |
529 | 543 | return $dataFolderNode; |
530 | 544 | } |
531 | 545 | } |
532 | 546 | // it does not exist or is not a folder or does not have write permissions: we create one |
533 | | - $dataFolder = $this->createAssistantDataFolder($userId); |
| 547 | + $dataFolder = $this->createAssistantDataFolder($userId, $dataFolderName); |
534 | 548 | $dataFolderName = $dataFolder->getName(); |
535 | 549 | $this->config->setUserValue($userId, Application::APP_ID, 'data_folder', $dataFolderName); |
536 | 550 | return $dataFolder; |
537 | 551 | } |
538 | 552 |
|
539 | 553 | /** |
540 | 554 | * @param string $userId |
| 555 | + * @param string $baseName |
541 | 556 | * @param int $try |
542 | 557 | * @return Folder |
543 | 558 | * @throws NoUserException |
544 | 559 | * @throws NotPermittedException |
545 | 560 | */ |
546 | | - private function createAssistantDataFolder(string $userId, int $try = 0): Folder { |
| 561 | + private function createAssistantDataFolder(string $userId, string $baseName, int $try = 0): Folder { |
547 | 562 | $userFolder = $this->rootFolder->getUserFolder($userId); |
548 | 563 | if ($try === 0) { |
549 | | - $folderPath = Application::ASSISTANT_DATA_FOLDER_NAME; |
| 564 | + $folderPath = $baseName; |
550 | 565 | } else { |
551 | | - $folderPath = Application::ASSISTANT_DATA_FOLDER_NAME . ' ' . $try; |
| 566 | + $folderPath = $baseName . ' ' . $try; |
552 | 567 | } |
553 | 568 |
|
554 | 569 | if ($userFolder->nodeExists($folderPath)) { |
555 | 570 | if ($try > 3) { |
556 | 571 | // give up |
557 | 572 | throw new RuntimeException('Could not create the assistant data folder'); |
558 | 573 | } |
559 | | - return $this->createAssistantDataFolder($userId, $try + 1); |
| 574 | + return $this->createAssistantDataFolder($userId, $baseName, $try + 1); |
560 | 575 | } |
561 | 576 |
|
562 | 577 | return $userFolder->newFolder($folderPath); |
|
0 commit comments