Compare commits

..

4 Commits

Author SHA1 Message Date
Julius Härtl
3ef5f8edd0 Implement basic card entity for flow integration
Signed-off-by: Julius Härtl <jus@bitgrid.net>
2021-03-08 10:48:09 +01:00
Nextcloud bot
327d579521 [tx-robot] updated from transifex 2021-03-05 02:33:47 +00:00
Julius Härtl
225a22c93e Merge pull request #2847 from nextcloud/bugfix/noid/content-disposition
Switch to Content-Disposition attachment and check for sane mimetypes
2021-03-04 08:25:46 +01:00
Julius Härtl
9f7901519b Switch to Content-Disposition attachment and check for sane mimetypes
Signed-off-by: Julius Härtl <jus@bitgrid.net>
2021-03-04 08:17:28 +01:00
17 changed files with 381 additions and 143 deletions

View File

@@ -107,9 +107,16 @@ OC.L10N.register(
"Select the board to link to a project" : "Izberite zbirko za povezavo s projektom",
"Search by board title" : "Išči po imenu zbirke",
"Select board" : "Izbor zbirke",
"Create a new card" : "Ustvari novo nalogo",
"Select a board" : "Izbor zbirke",
"Select a list" : "Izbor seznama",
"Card title" : "Naslov naloge",
"Cancel" : "Prekliči",
"Creating the new card…" : "Poteka ustvarjanje nove naloge ...",
"\"{card}\" was added to \"{board}\"" : "Naloga »{card}« je dodana v zbirko »{board}«.",
"Open card" : "Odpri nalogo",
"Close" : "Zapri",
"Create card" : "Ustvari nalogo",
"Select a card" : "Izbor naloge",
"Select the card to link to a project" : "Izbor naloge za povezavo do projekta",
"Link to card" : "Poveži nalogo",
@@ -258,6 +265,7 @@ OC.L10N.register(
"upcoming cards" : "prihajajoče naloge",
"Link to a board" : "Povezava do zbirke",
"Link to a card" : "Povezava do naloge",
"Create a card" : "Ustvari nalogo",
"Something went wrong" : "Prišlo je do napake ...",
"Failed to upload {name}" : "Pošiljanje {name} je spodletelo",
"Maximum file size of {size} exceeded" : "Omejitev velikosti datoteke {size} je prekoračena.",

View File

@@ -105,9 +105,16 @@
"Select the board to link to a project" : "Izberite zbirko za povezavo s projektom",
"Search by board title" : "Išči po imenu zbirke",
"Select board" : "Izbor zbirke",
"Create a new card" : "Ustvari novo nalogo",
"Select a board" : "Izbor zbirke",
"Select a list" : "Izbor seznama",
"Card title" : "Naslov naloge",
"Cancel" : "Prekliči",
"Creating the new card…" : "Poteka ustvarjanje nove naloge ...",
"\"{card}\" was added to \"{board}\"" : "Naloga »{card}« je dodana v zbirko »{board}«.",
"Open card" : "Odpri nalogo",
"Close" : "Zapri",
"Create card" : "Ustvari nalogo",
"Select a card" : "Izbor naloge",
"Select the card to link to a project" : "Izbor naloge za povezavo do projekta",
"Link to card" : "Poveži nalogo",
@@ -256,6 +263,7 @@
"upcoming cards" : "prihajajoče naloge",
"Link to a board" : "Povezava do zbirke",
"Link to a card" : "Povezava do naloge",
"Create a card" : "Ustvari nalogo",
"Something went wrong" : "Prišlo je do napake ...",
"Failed to upload {name}" : "Pošiljanje {name} je spodletelo",
"Maximum file size of {size} exceeded" : "Omejitev velikosti datoteke {size} je prekoračena.",

View File

@@ -45,6 +45,8 @@ use OCA\Deck\Service\FullTextSearchService;
use OCA\Deck\Service\PermissionService;
use OCA\Deck\Sharing\DeckShareProvider;
use OCA\Deck\Sharing\Listener;
use OCA\Deck\Listeners\RegisterChecksListener;
use OCA\Deck\Listeners\RegisterEntityListener;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
@@ -66,6 +68,8 @@ use OCP\IUserManager;
use OCP\Notification\IManager as NotificationManager;
use OCP\Share\IManager;
use OCP\Util;
use OCP\WorkflowEngine\Events\RegisterChecksEvent;
use OCP\WorkflowEngine\Events\RegisterEntitiesEvent;
use Psr\Container\ContainerInterface;
class Application20 extends App implements IBootstrap {
@@ -127,6 +131,9 @@ class Application20 extends App implements IBootstrap {
$context->registerDashboardWidget(DeckWidget::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
$context->registerEventListener(RegisterEntitiesEvent::class, RegisterEntityListener::class);
//$context->registerEventListener(RegisterChecksEvent::class, RegisterChecksListener::class);
}
public function registerNotifications(NotificationManager $notificationManager): void {

View File

@@ -0,0 +1,43 @@
<?php
/*
* @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
declare(strict_types=1);
namespace OCA\Deck\Event;
use OCA\Deck\Db\Card;
class CardCreatedEvent extends \OCP\EventDispatcher\Event {
/** @var Card */
private $card;
public function __construct(Card $card) {
$this->card = $card;
}
public function getCard(): Card {
return $this->card;
}
}

107
lib/Flow/CardEntity.php Normal file
View File

@@ -0,0 +1,107 @@
<?php
/*
* @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
declare(strict_types=1);
namespace OCA\Deck\Flow;
use OCA\Deck\Event\CardCreatedEvent;
use OCP\EventDispatcher\Event;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\WorkflowEngine\EntityContext\IDisplayName;
use OCP\WorkflowEngine\EntityContext\IDisplayText;
use OCP\WorkflowEngine\EntityContext\IUrl;
use OCP\WorkflowEngine\IEntity;
use OCP\WorkflowEngine\IRuleMatcher;
class CardEntity implements IEntity, IDisplayText, IDisplayName, IUrl {
/**
* @var IL10N
*/
private $l10n;
/**
* @var IURLGenerator
*/
private $urlGenerator;
private $card;
public function __construct(IL10N $l, IURLGenerator $urlGenerator) {
$this->l10n = $l;
$this->urlGenerator = $urlGenerator;
}
/**
* @inheritDoc
*/
public function getName(): string {
return $this->l10n->t('Deck card');
}
/**
* @inheritDoc
*/
public function getIcon(): string {
return $this->urlGenerator->imagePath('deck', 'deck-dark.svg');
}
/**
* @inheritDoc
*/
public function getEvents(): array {
return [new CardEntityCreatedEvent($this->l10n)];
}
/**
* @inheritDoc
*/
public function prepareRuleMatcher(IRuleMatcher $ruleMatcher, string $eventName, Event $event): void {
if(!$event instanceof CardCreatedEvent) {
return;
}
/** @var CardCreatedEvent $event */
$ruleMatcher->setEntitySubject($this, $event->getCard());
$this->card = $event->getCard();
}
/**
* @inheritDoc
*/
public function isLegitimatedForUserId(string $userId): bool {
return true;
}
public function getDisplayName(): string {
return $this->card->getTitle();
}
public function getDisplayText(int $verbosity = 0): string {
return $this->card->getTitle() . PHP_EOL . $this->card->getDescription();
}
public function getUrl(): string {
return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#' . '/board/1/card/' . $this->card->getId();
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
declare(strict_types=1);
namespace OCA\Deck\Flow;
use OCA\Deck\Event\CardCreatedEvent;
use OCP\IL10N;
use OCP\WorkflowEngine\IEntityEvent;
class CardEntityCreatedEvent implements IEntityEvent {
/** @var IL10N */
private $l10n;
public function __construct(IL10N $l10n) {
$this->l10n = $l10n;
}
public function getDisplayName(): string {
return $this->l10n->t('Card created');
}
public function getEventName(): string {
return CardCreatedEvent::class;
}
}

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Listeners;
use OCA\FlowWebhooks\AppInfo\Application;
use OCA\FlowWebhooks\Flow\ParameterCheck;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;
use OCP\WorkflowEngine\Events\RegisterChecksEvent;
class RegisterChecksListener implements IEventListener {
/** @var ParameterCheck */
private $parameterCheck;
public function __construct(ParameterCheck $parameterCheck) {
$this->parameterCheck = $parameterCheck;
}
public function handle(Event $event): void {
if (!($event instanceof RegisterChecksEvent)) {
return;
}
$event->registerCheck($this->parameterCheck);
Util::addScript(Application::APP_ID, Application::APP_ID);
}
}

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Listeners;
use OCA\Deck\Flow\CardEntity;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\WorkflowEngine\Events\RegisterEntitiesEvent;
class RegisterEntityListener implements IEventListener {
/** @var CardEntity */
private $cardEntity;
public function __construct(CardEntity $cardEntity) {
$this->cardEntity = $cardEntity;
}
public function handle(Event $event): void {
if(!$event instanceof RegisterEntitiesEvent) {
return;
}
$event->registerEntity($this->cardEntity);
}
}

View File

@@ -35,6 +35,7 @@ use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Event\CardCreatedEvent;
use OCA\Deck\Event\FTSEvent;
use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\Db\BoardMapper;
@@ -224,7 +225,8 @@ class CardService {
$card = $this->cardMapper->insert($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_CREATE);
$this->changeHelper->cardChanged($card->getId(), false);
$this->eventDispatcher->dispatchTyped(new CardCreatedEvent($card));
$this->eventDispatcher->dispatch(
'\OCA\Deck\Card::onCreate',
new FTSEvent(

View File

@@ -27,10 +27,9 @@ use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\StatusException;
use OCA\Deck\Exceptions\ConflictException;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\StreamResponse;
use OCP\Files\IAppData;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
@@ -49,6 +48,7 @@ class FileService implements IAttachmentService {
private $rootFolder;
private $config;
private $attachmentMapper;
private $mimeTypeDetector;
public function __construct(
IL10N $l10n,
@@ -57,7 +57,8 @@ class FileService implements IAttachmentService {
ILogger $logger,
IRootFolder $rootFolder,
IConfig $config,
AttachmentMapper $attachmentMapper
AttachmentMapper $attachmentMapper,
IMimeTypeDetector $mimeTypeDetector
) {
$this->l10n = $l10n;
$this->appData = $appData;
@@ -66,6 +67,7 @@ class FileService implements IAttachmentService {
$this->rootFolder = $rootFolder;
$this->config = $config;
$this->attachmentMapper = $attachmentMapper;
$this->mimeTypeDetector = $mimeTypeDetector;
}
/**
@@ -225,27 +227,14 @@ class FileService implements IAttachmentService {
/**
* @param Attachment $attachment
* @return FileDisplayResponse|\OCP\AppFramework\Http\Response|StreamResponse
* @return StreamResponse
* @throws \Exception
*/
public function display(Attachment $attachment) {
$file = $this->getFileFromRootFolder($attachment);
if (method_exists($file, 'fopen')) {
$response = new StreamResponse($file->fopen('r'));
$response->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"');
} else {
$response = new FileDisplayResponse($file);
}
// We need those since otherwise chrome won't show the PDF file with CSP rule object-src 'none'
// https://bugs.chromium.org/p/chromium/issues/detail?id=271452
$policy = new ContentSecurityPolicy();
$policy->addAllowedObjectDomain('\'self\'');
$policy->addAllowedObjectDomain('blob:');
$policy->addAllowedMediaDomain('\'self\'');
$policy->addAllowedMediaDomain('blob:');
$response->setContentSecurityPolicy($policy);
$response->addHeader('Content-Type', $file->getMimeType());
$response = new StreamResponse($file->fopen('rb'));
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($file->getName()) . '"');
$response->addHeader('Content-Type', $this->mimeTypeDetector->getSecureMimeType($file->getMimeType()));
return $response;
}

View File

@@ -26,10 +26,9 @@ namespace OCA\Deck\Service;
use OCA\Deck\Db\Attachment;
use OCA\Deck\Sharing\DeckShareProvider;
use OCA\Deck\StatusException;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\StreamResponse;
use OCP\Constants;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IDBConnection;
@@ -50,6 +49,7 @@ class FilesAppService implements IAttachmentService, ICustomAttachmentService {
private $l10n;
private $preview;
private $permissionService;
private $mimeTypeDetector;
public function __construct(
IRequest $request,
@@ -60,6 +60,7 @@ class FilesAppService implements IAttachmentService, ICustomAttachmentService {
DeckShareProvider $shareProvider,
IPreview $preview,
PermissionService $permissionService,
IMimeTypeDetector $mimeTypeDetector,
string $userId = null
) {
$this->request = $request;
@@ -70,6 +71,7 @@ class FilesAppService implements IAttachmentService, ICustomAttachmentService {
$this->shareManager = $shareManager;
$this->userId = $userId;
$this->preview = $preview;
$this->mimeTypeDetector = $mimeTypeDetector;
}
public function listAttachments(int $cardId): array {
@@ -147,22 +149,10 @@ class FilesAppService implements IAttachmentService, ICustomAttachmentService {
if ($file === null || $share->getSharedWith() !== (string)$attachment->getCardId()) {
throw new NotFoundException('File not found');
}
if (method_exists($file, 'fopen')) {
$response = new StreamResponse($file->fopen('r'));
$response->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"');
} else {
$response = new FileDisplayResponse($file);
}
// We need those since otherwise chrome won't show the PDF file with CSP rule object-src 'none'
// https://bugs.chromium.org/p/chromium/issues/detail?id=271452
$policy = new ContentSecurityPolicy();
$policy->addAllowedObjectDomain('\'self\'');
$policy->addAllowedObjectDomain('blob:');
$policy->addAllowedMediaDomain('\'self\'');
$policy->addAllowedMediaDomain('blob:');
$response->setContentSecurityPolicy($policy);
$response->addHeader('Content-Type', $file->getMimeType());
$response = new StreamResponse($file->fopen('rb'));
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($file->getName()) . '"');
$response->addHeader('Content-Type', $this->mimeTypeDetector->getSecureMimeType($file->getMimeType()));
return $response;
}

View File

@@ -168,7 +168,6 @@ export default {
},
close() {
this.$emit('close')
this.$root.$emit('close')
},
async select() {

View File

@@ -28,11 +28,11 @@
:members="members"
name-key="uid"
:tab-select="true">
<template #item="s">
<template v-slot:item="s">
<Avatar class="atwho-li--avatar" :user="s.item.uid" :size="24" />
<span class="atwho-li--name" v-text="s.item.displayname" />
</template>
<template #embeddedItem="scope">
<template v-slot:embeddedItem="scope">
<span>
<UserBubble v-if="scope.current.uid"
:data-mention-id="scope.current.uid"

View File

@@ -149,9 +149,6 @@ export default {
directives: {
ClickOutside,
},
inject: [
'boardApi',
],
props: {
board: {
type: Object,
@@ -315,6 +312,9 @@ export default {
this.updateDueSetting = null
},
},
inject: [
'boardApi',
],
}
</script>

View File

@@ -21,40 +21,32 @@
-->
<template>
<div>
<DashboardWidget :items="cards"
empty-content-icon="icon-deck"
:empty-content-message="t('deck', 'No upcoming cards')"
:show-more-text="t('deck', 'upcoming cards')"
:show-more-url="showMoreUrl"
:loading="loading"
@hide="() => {}"
@markDone="() => {}">
<template #default="{ item }">
<a :key="item.id"
:href="cardLink(item)"
target="_blank"
class="card">
<div class="card--header">
<DueDate class="right" :card="item" />
<span class="title">{{ item.title }}</span>
</div>
<ul v-if="item.labels && item.labels.length"
class="labels">
<li v-for="label in item.labels" :key="label.id" :style="labelStyle(label)">
<span>{{ label.title }}</span>
</li>
</ul>
</a>
</template>
</DashboardWidget>
<div class="center-button">
<button @click="toggleAddCardModel">
{{ t('deck', 'Add card') }}
</button>
<CardCreateDialog v-if="showAddCardModal" @close="toggleAddCardModel" />
</div>
</div>
<DashboardWidget :items="cards"
empty-content-icon="icon-deck"
:empty-content-message="t('deck', 'No upcoming cards')"
:show-more-text="t('deck', 'upcoming cards')"
:show-more-url="showMoreUrl"
:loading="loading"
@hide="() => {}"
@markDone="() => {}">
<template v-slot:default="{ item }">
<a :key="item.id"
:href="cardLink(item)"
target="_blank"
class="card">
<div class="card--header">
<DueDate class="right" :card="item" />
<span class="title">{{ item.title }}</span>
</div>
<ul v-if="item.labels && item.labels.length"
class="labels">
<li v-for="label in item.labels" :key="label.id" :style="labelStyle(label)">
<span>{{ label.title }}</span>
</li>
</ul>
</a>
</template>
</DashboardWidget>
</template>
<script>
@@ -63,20 +55,17 @@ import { mapGetters } from 'vuex'
import labelStyle from './../mixins/labelStyle'
import DueDate from '../components/cards/badges/DueDate'
import { generateUrl } from '@nextcloud/router'
import CardCreateDialog from '../CardCreateDialog'
export default {
name: 'Dashboard',
components: {
DueDate,
DashboardWidget,
CardCreateDialog,
},
mixins: [labelStyle],
data() {
return {
loading: false,
showAddCardModal: false,
}
},
computed: {
@@ -84,17 +73,11 @@ export default {
'assignedCardsDashboard',
]),
cards() {
/* const list = [
const list = [
...this.assignedCardsDashboard,
].filter((card) => {
return card.duedate !== null
}) */
const list = this.assignedCardsDashboard.slice(0, 6)
.filter((card) => {
return card.duedate !== null
})
})
list.sort((a, b) => {
return (new Date(a.duedate)).getTime() - (new Date(b.duedate)).getTime()
})
@@ -115,11 +98,6 @@ export default {
this.loading = false
})
},
methods: {
toggleAddCardModel() {
this.showAddCardModal = !this.showAddCardModal
},
},
}
</script>
@@ -167,8 +145,4 @@ export default {
.right {
float: right;
}
.center-button {
text-align: center;
}
</style>

View File

@@ -25,10 +25,10 @@ namespace OCA\Deck\Service;
use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\StreamResponse;
use OCP\Files\Folder;
use OCP\Files\IAppData;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\IRootFolder;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
@@ -57,6 +57,8 @@ class FileServiceTest extends TestCase {
private $config;
/** @var AttachmentMapper|MockObject */
private $attachmentMapper;
/** @var IMimeTypeDetector|MockObject */
private $mimeTypeDetector;
public function setUp(): void {
parent::setUp();
@@ -67,7 +69,8 @@ class FileServiceTest extends TestCase {
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->config = $this->createMock(IConfig::class);
$this->attachmentMapper = $this->createMock(AttachmentMapper::class);
$this->fileService = new FileService($this->l10n, $this->appData, $this->request, $this->logger, $this->rootFolder, $this->config, $this->attachmentMapper);
$this->mimeTypeDetector = $this->createMock(IMimeTypeDetector::class);
$this->fileService = new FileService($this->l10n, $this->appData, $this->request, $this->logger, $this->rootFolder, $this->config, $this->attachmentMapper, $this->mimeTypeDetector);
}
public function mockGetFolder($cardId) {
@@ -268,51 +271,13 @@ class FileServiceTest extends TestCase {
$file->expects($this->any())
->method('fopen')
->willReturn('fileresource');
$this->mimeTypeDetector->expects($this->once())
->method('getSecureMimeType')
->willReturn('image/jpeg');
$actual = $this->fileService->display($attachment);
$expected = new StreamResponse('fileresource');
$expected->addHeader('Content-Type', 'image/jpeg');
$expected->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"');
$policy = new ContentSecurityPolicy();
$policy->addAllowedObjectDomain('\'self\'');
$policy->addAllowedObjectDomain('blob:');
$policy->addAllowedMediaDomain('\'self\'');
$policy->addAllowedMediaDomain('blob:');
$expected->setContentSecurityPolicy($policy);
$this->assertEquals($expected, $actual);
}
public function testDisplayPdf() {
$this->config->expects($this->once())
->method('getSystemValue')
->willReturn('123');
$appDataFolder = $this->createMock(Folder::class);
$deckAppDataFolder = $this->createMock(Folder::class);
$cardFolder = $this->createMock(Folder::class);
$this->rootFolder->expects($this->once())->method('get')->willReturn($appDataFolder);
$appDataFolder->expects($this->once())->method('get')->willReturn($deckAppDataFolder);
$deckAppDataFolder->expects($this->once())->method('get')->willReturn($cardFolder);
$attachment = $this->getAttachment();
$file = $this->createMock(\OCP\Files\File::class);
$cardFolder->expects($this->once())->method('get')->willReturn($file);
$file->expects($this->any())
->method('getMimeType')
->willReturn('application/pdf');
$file->expects($this->any())
->method('getName')
->willReturn('file1');
$file->expects($this->any())
->method('fopen')
->willReturn('fileresource');
$actual = $this->fileService->display($attachment);
$expected = new StreamResponse('fileresource');
$expected->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"');
$expected->addHeader('Content-Type', 'application/pdf');
$policy = new ContentSecurityPolicy();
$policy->addAllowedObjectDomain('\'self\'');
$policy->addAllowedObjectDomain('blob:');
$policy->addAllowedMediaDomain('\'self\'');
$policy->addAllowedMediaDomain('blob:');
$expected->setContentSecurityPolicy($policy);
$expected->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($file->getName()) . '"');
$this->assertEquals($expected, $actual);
}

View File

@@ -11,7 +11,7 @@ const config = {
},
output: {
filename: '[name].js',
// jsonpFunction: 'webpackJsonpOCADeck',
jsonpFunction: 'webpackJsonpOCADeck',
chunkFilename: '[name].js?v=[contenthash]',
},
resolve: {