|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Phpsa\Datastore\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
|
|
6
|
|
|
use Phpsa\Datastore\Datastore; |
|
7
|
|
|
use Phpsa\Datastore\Asset; |
|
8
|
|
|
use Phpsa\Datastore\Helpers; |
|
9
|
|
|
use Phpsa\Datastore\DatastoreException; |
|
10
|
|
|
use Phpsa\Datastore\Repositories\DatastoreRepository; |
|
11
|
|
|
|
|
12
|
|
|
use Phpsa\Datastore\Models\Datastore as DatastoreModel; |
|
13
|
|
|
use Phpsa\Datastore\Models\DatastorePages; |
|
14
|
|
|
|
|
15
|
|
|
Class DatastoreController extends Controller { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var DatastoreRepository |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $datastoreRepository; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* UserController constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param DatastoreRepository $datastoreRepository |
|
26
|
|
|
* @todo get rid of these datastoreRepository and make use of the mode only |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(DatastoreRepository $datastoreRepository) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->datastoreRepository = $datastoreRepository; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Checks if the current user can manage else set status column |
|
35
|
|
|
* this allows us to filter out unpublished items to public but allow admins to |
|
36
|
|
|
* view unpublished items |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $permission |
|
39
|
|
|
* |
|
40
|
|
|
* @return string|null |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function canViewAll($status = 'published') :string |
|
43
|
|
|
{ |
|
44
|
|
|
$user = auth()->user(); |
|
45
|
|
|
return $user && $user->can('manage datastore') ? null : $status; |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* gets page based on the slug |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $slug |
|
52
|
|
|
* |
|
53
|
|
|
* @return DatastorePages |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function getPageBySlug($slug){ |
|
56
|
|
|
$page = DatastorePages::where('slug', $slug)->first(); |
|
57
|
|
|
if(!$page){ |
|
58
|
|
|
abort(404); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$datastore = $page->datastore; |
|
62
|
|
|
$user = auth()->user(); |
|
63
|
|
|
|
|
64
|
|
|
if(!$datastore->statusIsActive() && (!$user || !$user->can('manage datastore'))) { |
|
|
|
|
|
|
65
|
|
|
abort(404); |
|
66
|
|
|
} |
|
67
|
|
|
return $page; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Gets the page view based off of the slug passed in |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $slug |
|
74
|
|
|
* |
|
75
|
|
|
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
|
76
|
|
|
*/ |
|
77
|
|
|
public function page($slug){ |
|
78
|
|
|
|
|
79
|
|
|
$page = $this->getPageBySlug($slug); |
|
80
|
|
|
|
|
81
|
|
|
$acceptedAssets = $page->datastore->accept ? $this->datastoreRepository->paginateAccepted($page->asset, $this->canViewAll(Helpers::getStatusEquals($page->datastore->accept))) : false; |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
return view($page->datastore->getViewName()) |
|
|
|
|
|
|
84
|
|
|
->withDatastore($page->datastore) |
|
85
|
|
|
->withChildren($page->datastore->children()) |
|
86
|
|
|
->withAccepted($acceptedAssets) |
|
87
|
|
|
->withPage($page); |
|
88
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function childPage($parent_slug, $slug){ |
|
92
|
|
|
return $this->page($slug); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function articleByAuthor($author_id, $slug){ |
|
96
|
|
|
$this->datastoreRepository->paginateSearchProp('author', $author_id, Phpsa\Datastore\Ams\Article\ItemAsset::class, $this->canViewAll('published')); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths