Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Listener/RegisterTemplateFileCreatorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function handle(Event $event): void {
return;
}

if (!$this->permissionManager->isEnabledForUser() || empty($this->capabilitiesService->getCapabilities())) {
if (!$this->permissionManager->isEnabledForUser() || !$this->permissionManager->userCanEdit() || empty($this->capabilitiesService->getCapabilities())) {
return;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/lib/Listener/RegisterTemplateFileCreatorListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function testHandleDoesNotRegisterIfPermissionOrCapabilitiesMissing() {
$event = $this->createMock(RegisterTemplateCreatorEvent::class);
$event->method('getTemplateManager')->willReturn($this->templateManager);
$this->permissionManager->method('isEnabledForUser')->willReturn(false);
$this->permissionManager->method('userCanEdit')->willReturn(true);
$this->capabilitiesService->method('getCapabilities')->willReturn([]);

$listener = new RegisterTemplateFileCreatorListener(
Expand All @@ -70,6 +71,7 @@ public function testHandleRegistersTemplateFileCreators() {
$event = $this->createMock(RegisterTemplateCreatorEvent::class);
$event->method('getTemplateManager')->willReturn($this->templateManager);
$this->permissionManager->method('isEnabledForUser')->willReturn(true);
$this->permissionManager->method('userCanEdit')->willReturn(true);
$this->capabilitiesService->method('getCapabilities')->willReturn(['something']);
$this->capabilitiesService->method('hasDrawSupport')->willReturn(true);
$this->config->method('getAppValue')->willReturn('ooxml');
Expand All @@ -91,6 +93,7 @@ public function testHandleRegistersWithoutDrawSupport() {
$event = $this->createMock(RegisterTemplateCreatorEvent::class);
$event->method('getTemplateManager')->willReturn($this->templateManager);
$this->permissionManager->method('isEnabledForUser')->willReturn(true);
$this->permissionManager->method('userCanEdit')->willReturn(true);
$this->capabilitiesService->method('getCapabilities')->willReturn(['something']);
$this->capabilitiesService->method('hasDrawSupport')->willReturn(false);
$this->config->method('getAppValue')->willReturn('ooxml');
Expand All @@ -107,4 +110,22 @@ public function testHandleRegistersWithoutDrawSupport() {
);
$listener->handle($event);
}

public function testHandleDoesNotRegisterIfUserCannotEdit() {
$event = $this->createMock(RegisterTemplateCreatorEvent::class);
$event->method('getTemplateManager')->willReturn($this->templateManager);
$this->permissionManager->method('isEnabledForUser')->willReturn(true);
$this->permissionManager->method('userCanEdit')->willReturn(false);
$this->capabilitiesService->method('getCapabilities')->willReturn(['something']);

$listener = new RegisterTemplateFileCreatorListener(
$this->l10n,
$this->config,
$this->appManager,
$this->capabilitiesService,
$this->permissionManager
);
$this->templateManager->expects($this->never())->method('registerTemplateFileCreator');
$listener->handle($event);
}
}
Loading