Skip to content

Commit 149053f

Browse files
authored
Merge pull request #4846 from nextcloud/backport/4807/stable30
[stable30] fix: allow document creation only for users that can edit
2 parents 25a7dd6 + 8e32c4f commit 149053f

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

lib/Listener/RegisterTemplateFileCreatorListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function handle(Event $event): void {
3434
return;
3535
}
3636

37-
if (!$this->permissionManager->isEnabledForUser() || empty($this->capabilitiesService->getCapabilities())) {
37+
if (!$this->permissionManager->isEnabledForUser() || !$this->permissionManager->userCanEdit() || empty($this->capabilitiesService->getCapabilities())) {
3838
return;
3939
}
4040

tests/lib/Listener/RegisterTemplateFileCreatorListenerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function testHandleDoesNotRegisterIfPermissionOrCapabilitiesMissing() {
5353
$event = $this->createMock(RegisterTemplateCreatorEvent::class);
5454
$event->method('getTemplateManager')->willReturn($this->templateManager);
5555
$this->permissionManager->method('isEnabledForUser')->willReturn(false);
56+
$this->permissionManager->method('userCanEdit')->willReturn(true);
5657
$this->capabilitiesService->method('getCapabilities')->willReturn([]);
5758

5859
$listener = new RegisterTemplateFileCreatorListener(
@@ -70,6 +71,7 @@ public function testHandleRegistersTemplateFileCreators() {
7071
$event = $this->createMock(RegisterTemplateCreatorEvent::class);
7172
$event->method('getTemplateManager')->willReturn($this->templateManager);
7273
$this->permissionManager->method('isEnabledForUser')->willReturn(true);
74+
$this->permissionManager->method('userCanEdit')->willReturn(true);
7375
$this->capabilitiesService->method('getCapabilities')->willReturn(['something']);
7476
$this->capabilitiesService->method('hasDrawSupport')->willReturn(true);
7577
$this->config->method('getAppValue')->willReturn('ooxml');
@@ -91,6 +93,7 @@ public function testHandleRegistersWithoutDrawSupport() {
9193
$event = $this->createMock(RegisterTemplateCreatorEvent::class);
9294
$event->method('getTemplateManager')->willReturn($this->templateManager);
9395
$this->permissionManager->method('isEnabledForUser')->willReturn(true);
96+
$this->permissionManager->method('userCanEdit')->willReturn(true);
9497
$this->capabilitiesService->method('getCapabilities')->willReturn(['something']);
9598
$this->capabilitiesService->method('hasDrawSupport')->willReturn(false);
9699
$this->config->method('getAppValue')->willReturn('ooxml');
@@ -107,4 +110,22 @@ public function testHandleRegistersWithoutDrawSupport() {
107110
);
108111
$listener->handle($event);
109112
}
113+
114+
public function testHandleDoesNotRegisterIfUserCannotEdit() {
115+
$event = $this->createMock(RegisterTemplateCreatorEvent::class);
116+
$event->method('getTemplateManager')->willReturn($this->templateManager);
117+
$this->permissionManager->method('isEnabledForUser')->willReturn(true);
118+
$this->permissionManager->method('userCanEdit')->willReturn(false);
119+
$this->capabilitiesService->method('getCapabilities')->willReturn(['something']);
120+
121+
$listener = new RegisterTemplateFileCreatorListener(
122+
$this->l10n,
123+
$this->config,
124+
$this->appManager,
125+
$this->capabilitiesService,
126+
$this->permissionManager
127+
);
128+
$this->templateManager->expects($this->never())->method('registerTemplateFileCreator');
129+
$listener->handle($event);
130+
}
110131
}

0 commit comments

Comments
 (0)