-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathEntityShareLinkController.php
More file actions
124 lines (105 loc) · 3.58 KB
/
EntityShareLinkController.php
File metadata and controls
124 lines (105 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace BookStack\Entities\Controllers;
use BookStack\Entities\EntityShareLinkService;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Models\EntityShareLink;
use BookStack\Entities\Queries\EntityQueries;
use BookStack\Exceptions\PermissionsException;
use BookStack\Http\Controller;
use BookStack\Permissions\Permission;
use Illuminate\Http\Request;
class EntityShareLinkController extends Controller
{
public function __construct(
protected EntityShareLinkService $shareLinkService,
protected EntityQueries $queries
) {
}
/**
* Display the share links for a specific book.
*/
public function indexForBook(string $bookSlug)
{
$book = $this->queries->books->findVisibleBySlugOrFail($bookSlug);
return $this->index($book);
}
/**
* Display the share links for a specific chapter.
*/
public function indexForChapter(string $bookSlug, string $chapterSlug)
{
$chapter = $this->queries->chapters->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
return $this->index($chapter);
}
/**
* Display the share links for a specific page.
*/
public function indexForPage(string $bookSlug, string $pageSlug)
{
$page = $this->queries->pages->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
return $this->index($page);
}
/**
* Display the share links for the given entity.
*/
protected function index(Entity $entity)
{
$this->checkPermission(Permission::ContentShareManage);
$shareLinks = $this->shareLinkService->getShareLinksForEntity($entity);
return view('entities.share-links.index', [
'entity' => $entity,
'shareLinks' => $shareLinks,
]);
}
/**
* Store a new share link for a book.
*/
public function storeForBook(Request $request, string $bookSlug)
{
$book = $this->queries->books->findVisibleBySlugOrFail($bookSlug);
return $this->store($request, $book);
}
/**
* Store a new share link for a chapter.
*/
public function storeForChapter(Request $request, string $bookSlug, string $chapterSlug)
{
$chapter = $this->queries->chapters->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
return $this->store($request, $chapter);
}
/**
* Store a new share link for a page.
*/
public function storeForPage(Request $request, string $bookSlug, string $pageSlug)
{
$page = $this->queries->pages->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
return $this->store($request, $page);
}
/**
* Store a new share link for the given entity.
*/
protected function store(Request $request, Entity $entity)
{
$this->checkPermission(Permission::ContentShareManage);
$this->validate($request, [
'name' => ['nullable', 'string', 'max:255'],
]);
$this->shareLinkService->createShareLink($entity, $request->get('name'));
$this->showSuccessNotification(trans('entities.share_link_created'));
return redirect($entity->getUrl('/share-links'));
}
/**
* Delete a share link.
*/
public function destroy(int $id)
{
$shareLink = EntityShareLink::query()->findOrFail($id);
try {
$this->shareLinkService->deleteShareLink($shareLink);
$this->showSuccessNotification(trans('entities.share_link_deleted'));
} catch (PermissionsException $e) {
$this->showErrorNotification($e->getMessage());
}
return redirect()->back();
}
}