Skip to content

Commit 04dd924

Browse files
committed
feat(file_sharing): Provide template creator list in public shares
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent c0595e9 commit 04dd924

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

apps/files/src/newMenu/newFromTemplate.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { TemplateFile } from '../types.ts'
99

1010
import { Folder, Node, Permission, addNewFileMenuEntry } from '@nextcloud/files'
1111
import { loadState } from '@nextcloud/initial-state'
12+
import { isPublicShare } from '@nextcloud/sharing/public'
1213
import { newNodeName } from '../utils/newNodeDialog'
1314
import { translate as t } from '@nextcloud/l10n'
1415
import Vue, { defineAsyncComponent } from 'vue'
@@ -46,7 +47,12 @@ const getTemplatePicker = async (context: Folder) => {
4647
* Register all new-file-menu entries for all template providers
4748
*/
4849
export function registerTemplateEntries() {
49-
const templates = loadState<TemplateFile[]>('files', 'templates', [])
50+
let templates: TemplateFile[]
51+
if (isPublicShare()) {
52+
templates = loadState<TemplateFile[]>('files_sharing', 'templates', [])
53+
} else {
54+
templates = loadState<TemplateFile[]>('files', 'templates', [])
55+
}
5056

5157
// Init template files menu
5258
templates.forEach((provider, index) => {

apps/files_sharing/lib/DefaultPublicShareTemplateProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use OCP\Defaults;
2525
use OCP\EventDispatcher\IEventDispatcher;
2626
use OCP\Files\File;
27+
use OCP\Files\Template\ITemplateManager;
2728
use OCP\IAppConfig;
2829
use OCP\IConfig;
2930
use OCP\IL10N;
@@ -49,6 +50,7 @@ public function __construct(
4950
private Defaults $defaults,
5051
private IConfig $config,
5152
private IRequest $request,
53+
private ITemplateManager $templateManager,
5254
private IInitialState $initialState,
5355
private IAppConfig $appConfig,
5456
) {
@@ -119,6 +121,8 @@ public function renderPage(IShare $share, string $token, string $path): Template
119121
$this->eventDispatcher->dispatchTyped(new LoadViewer());
120122
}
121123

124+
$this->initialState->provideInitialState('templates', $this->templateManager->listCreators());
125+
122126
// Allow external apps to register their scripts
123127
$this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($share));
124128

apps/files_sharing/tests/Controller/ShareControllerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\Files\File;
3232
use OCP\Files\IRootFolder;
3333
use OCP\Files\NotFoundException;
34+
use OCP\Files\Template\ITemplateManager;
3435
use OCP\IAppConfig;
3536
use OCP\IConfig;
3637
use OCP\IL10N;
@@ -68,6 +69,7 @@ class ShareControllerTest extends \Test\TestCase {
6869
private Manager&MockObject $shareManager;
6970
private IPreview&MockObject $previewManager;
7071
private IUserManager&MockObject $userManager;
72+
private ITemplateManager&MockObject $templateManager;
7173
private IInitialState&MockObject $initialState;
7274
private IURLGenerator&MockObject $urlGenerator;
7375
private ISecureRandom&MockObject $secureRandom;
@@ -87,6 +89,7 @@ protected function setUp(): void {
8789
$this->config = $this->createMock(IConfig::class);
8890
$this->appConfig = $this->createMock(IAppConfig::class);
8991
$this->userManager = $this->createMock(IUserManager::class);
92+
$this->templateManager = $this->createMock(ITemplateManager::class);
9093
$this->initialState = $this->createMock(IInitialState::class);
9194
$this->federatedShareProvider = $this->createMock(FederatedShareProvider::class);
9295
$this->federatedShareProvider->expects($this->any())
@@ -114,6 +117,7 @@ protected function setUp(): void {
114117
$this->defaults,
115118
$this->config,
116119
$this->createMock(IRequest::class),
120+
$this->templateManager,
117121
$this->initialState,
118122
$this->appConfig,
119123
)
@@ -338,6 +342,7 @@ public function testShowShare(): void {
338342
'owner' => 'ownerUID',
339343
'ownerDisplayName' => 'ownerDisplay',
340344
'isFileRequest' => false,
345+
'templates' => [],
341346
];
342347

343348
$response = $this->shareController->showShare();
@@ -485,6 +490,7 @@ public function testShowFileDropShare(): void {
485490
'isFileRequest' => false,
486491
'note' => 'The note',
487492
'label' => 'A label',
493+
'templates' => [],
488494
];
489495

490496
$response = $this->shareController->showShare();

0 commit comments

Comments
 (0)