mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-21 03:30:38 +00:00
Fixed issue where default user was over-fetched
This commit is contained in:
parent
241278226f
commit
bab27462ab
2 changed files with 7 additions and 10 deletions
app
|
@ -4,8 +4,6 @@ namespace BookStack\Http\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Contracts\Auth\Guard;
|
use Illuminate\Contracts\Auth\Guard;
|
||||||
use BookStack\Exceptions\UserRegistrationException;
|
|
||||||
use Setting;
|
|
||||||
|
|
||||||
class Authenticate
|
class Authenticate
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,9 +5,7 @@ use BookStack\View;
|
||||||
|
|
||||||
class ViewService
|
class ViewService
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $view;
|
protected $view;
|
||||||
protected $user;
|
|
||||||
protected $permissionService;
|
protected $permissionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +16,6 @@ class ViewService
|
||||||
public function __construct(View $view, PermissionService $permissionService)
|
public function __construct(View $view, PermissionService $permissionService)
|
||||||
{
|
{
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
$this->user = user();
|
|
||||||
$this->permissionService = $permissionService;
|
$this->permissionService = $permissionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +26,9 @@ class ViewService
|
||||||
*/
|
*/
|
||||||
public function add(Entity $entity)
|
public function add(Entity $entity)
|
||||||
{
|
{
|
||||||
if ($this->user === null) return 0;
|
$user = user();
|
||||||
$view = $entity->views()->where('user_id', '=', $this->user->id)->first();
|
if ($user === null || $user->isDefault()) return 0;
|
||||||
|
$view = $entity->views()->where('user_id', '=', $user->id)->first();
|
||||||
// Add view if model exists
|
// Add view if model exists
|
||||||
if ($view) {
|
if ($view) {
|
||||||
$view->increment('views');
|
$view->increment('views');
|
||||||
|
@ -39,7 +37,7 @@ class ViewService
|
||||||
|
|
||||||
// Otherwise create new view count
|
// Otherwise create new view count
|
||||||
$entity->views()->save($this->view->create([
|
$entity->views()->save($this->view->create([
|
||||||
'user_id' => $this->user->id,
|
'user_id' => user()->id,
|
||||||
'views' => 1
|
'views' => 1
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
@ -78,13 +76,14 @@ class ViewService
|
||||||
*/
|
*/
|
||||||
public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false)
|
public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false)
|
||||||
{
|
{
|
||||||
if ($this->user === null) return collect();
|
$user = user();
|
||||||
|
if ($user === null || $user->isDefault()) return collect();
|
||||||
|
|
||||||
$query = $this->permissionService
|
$query = $this->permissionService
|
||||||
->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type');
|
->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type');
|
||||||
|
|
||||||
if ($filterModel) $query = $query->where('viewable_type', '=', get_class($filterModel));
|
if ($filterModel) $query = $query->where('viewable_type', '=', get_class($filterModel));
|
||||||
$query = $query->where('user_id', '=', user()->id);
|
$query = $query->where('user_id', '=', $user->id);
|
||||||
|
|
||||||
$viewables = $query->with('viewable')->orderBy('updated_at', 'desc')
|
$viewables = $query->with('viewable')->orderBy('updated_at', 'desc')
|
||||||
->skip($count * $page)->take($count)->get()->pluck('viewable');
|
->skip($count * $page)->take($count)->get()->pluck('viewable');
|
||||||
|
|
Loading…
Add table
Reference in a new issue