authorizeStaff($composition); $guide = $this->guide($composition); $images = EmbeddedImages::staff(); foreach ($guide['chapters'] as $index => $chapter) { $guide['chapters'][$index]['html'] = DocumentGuide::shiftHeadings(FormattedText::html($chapter['version']->body, $images)); } return view('document.preview', ['guide' => $guide, 'composition' => $composition, 'pdfUrl' => route('editorial.document-preview.pdf', $composition)]); } public function pdf(Composition $composition): Response { $this->authorizeStaff($composition); $content = app(DocumentPdf::class)->render($this->guide($composition), 'Vorschau der Redaktion', 'vorschau', EmbeddedImages::forStaffPdf()); return response($content, 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename="vorschau.pdf"', 'Cache-Control' => 'private, no-store', ]); } /** * @return array */ private function guide(Composition $composition): array { $chapters = app(DocumentReader::class)->forStaff($composition); abort_if($chapters === null, 404); foreach ($chapters as $index => $chapter) { $chapters[$index] += [ 'allowed' => true, 'grant' => null, 'may_download' => true, 'download_grant' => null, 'state' => 'ok', 'html' => null, 'blocks' => FormattedText::blocks($chapter['version']->body), ]; } return [ 'title' => app(EditorialCatalog::class)->compositionTitle($composition), 'summary_html' => FormattedText::html($composition->summary), 'chapters' => $chapters, ]; } private function authorizeStaff(Composition $composition): void { $user = auth('staff')->user(); abort_unless( $user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)), 403, ); abort_unless($composition->kind === CompositionKind::Document, 404); } }