|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\FileLinks; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use App\Domains\FileLinks\GetFileLinks; |
|
8
|
|
|
use App\Domains\FileLinks\KillFileLink; |
|
9
|
|
|
use App\Domains\FileLinks\GetFileLinkDetails; |
|
10
|
|
|
use App\Domains\FileLinks\SetFileLinkDetails; |
|
11
|
|
|
|
|
12
|
|
|
use App\Http\Requests\FileLinkCreateRequest; |
|
13
|
|
|
use App\Http\Requests\FileLinkUpdateRequest; |
|
14
|
|
|
use App\Http\Requests\FileLinkInstructionsRequest; |
|
15
|
|
|
|
|
16
|
|
|
class FileLinksController extends Controller |
|
17
|
|
|
{ |
|
18
|
|
|
// Only authorized users have access |
|
19
|
88 |
|
public function __construct() |
|
20
|
|
|
{ |
|
21
|
|
|
// Verify the user is logged in and has permissions for this page |
|
22
|
88 |
|
$this->middleware('auth'); |
|
23
|
|
|
$this->middleware(function($request, $next) { |
|
24
|
66 |
|
$this->authorize('hasAccess', 'Use File Links'); |
|
25
|
44 |
|
return $next($request); |
|
26
|
88 |
|
}); |
|
27
|
88 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
// Landing page shows all links that the user owns |
|
30
|
2 |
|
public function index() |
|
31
|
|
|
{ |
|
32
|
2 |
|
return view('links.index'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// Ajax call to show the links for a specific user |
|
36
|
8 |
|
public function find($id) |
|
37
|
|
|
{ |
|
38
|
|
|
// If the user is trying to access the links of another user, they must have the proper permissions permissions |
|
39
|
8 |
|
if($id != 0) |
|
40
|
|
|
{ |
|
41
|
6 |
|
$this->authorize('hasAccess', 'manage_users'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
4 |
|
return (new GetFileLinks($id, true))->execute(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// Create a new file link form |
|
48
|
2 |
|
public function create() |
|
49
|
|
|
{ |
|
50
|
2 |
|
return view('links.newLink'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// Submit the new file link form |
|
54
|
8 |
|
public function store(FileLinkCreateRequest $request) |
|
55
|
|
|
{ |
|
56
|
8 |
|
$linkData = (new SetFileLinkDetails)->processNewLink($request); |
|
57
|
|
|
|
|
58
|
|
|
// return response()->json($linkData); |
|
59
|
8 |
|
return response()->json([ |
|
60
|
8 |
|
'success' => $linkData ? true : false, |
|
61
|
8 |
|
'link_id' => $linkData ? $linkData : false, |
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// Show details about a file link |
|
66
|
4 |
|
public function details($id, /** @scrutinizer ignore-unused */ $name) |
|
67
|
|
|
{ |
|
68
|
4 |
|
$linkDataObj = new GetFileLinkDetails($id); |
|
69
|
|
|
|
|
70
|
|
|
// If the link is invalid, return an error page |
|
71
|
4 |
|
if(!$linkDataObj->isLinkValid()) |
|
72
|
|
|
{ |
|
73
|
2 |
|
return view('links.badLink'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
2 |
|
return view('links.details', [ |
|
77
|
2 |
|
'details' => $linkDataObj->execute(true), |
|
78
|
|
|
]); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
// Ajax call te get JSON details of the link |
|
82
|
2 |
|
public function show($id) |
|
83
|
|
|
{ |
|
84
|
2 |
|
$linkDataObj = new GetFileLinkDetails($id); |
|
85
|
2 |
|
$linkData = $linkDataObj->execute(true); |
|
86
|
2 |
|
return $linkData; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
// Update the link's details |
|
90
|
2 |
|
public function update(FileLinkUpdateRequest $request, $id) |
|
91
|
|
|
{ |
|
92
|
2 |
|
(new SetFileLinkDetails)->updateLink($request, $id); |
|
93
|
2 |
|
return response()->json(['success' => true]); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
// Retrieve the instructions attached to a link |
|
97
|
2 |
|
public function getInstructions($linkID) |
|
98
|
|
|
{ |
|
99
|
2 |
|
return response()->json(['note' => (new GetFileLinkDetails($linkID))->getLinkInstructions()]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
// Update the instructions attached to the link |
|
103
|
2 |
|
public function submitInstructions(FileLinkInstructionsRequest $request, $linkID) |
|
104
|
|
|
{ |
|
105
|
2 |
|
(new SetFileLinkDetails)->setLinkInstructions($request, $linkID); |
|
106
|
2 |
|
return response()->json(['success' => true]); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
// Disable a file linke, but do not remove it (set the expire date to a previous date) |
|
110
|
2 |
|
public function disableLink($id) |
|
111
|
|
|
{ |
|
112
|
2 |
|
(new KillFileLink)->disableLink($id); |
|
113
|
2 |
|
return response()->json(['success' => true]); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
// Delete a file link |
|
117
|
2 |
|
public function destroy($id) |
|
118
|
|
|
{ |
|
119
|
2 |
|
(new KillFileLink)->deleteFileLink($id); |
|
120
|
2 |
|
return response()->json(['success' => true]); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|