mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
1d875ccfb7
Cleaned up PermissionApplicator to remove old cache system which was hardly ever actuall caching anything since it was reset after each public method run. Changed the scope of 'userCanOnAny' to just check entity permissions, and added protections of action scope creep, in case a role permission action was passed by mistake.
36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Queries;
|
|
|
|
use BookStack\Actions\Favourite;
|
|
use Illuminate\Database\Query\JoinClause;
|
|
|
|
class TopFavourites extends EntityQuery
|
|
{
|
|
public function run(int $count, int $skip = 0)
|
|
{
|
|
$user = user();
|
|
if (is_null($user) || $user->isDefault()) {
|
|
return collect();
|
|
}
|
|
|
|
$query = $this->permissionService()
|
|
->filterRestrictedEntityRelations(Favourite::query(), 'favourites', 'favouritable_id', 'favouritable_type')
|
|
->select('favourites.*')
|
|
->leftJoin('views', function (JoinClause $join) {
|
|
$join->on('favourites.favouritable_id', '=', 'views.viewable_id');
|
|
$join->on('favourites.favouritable_type', '=', 'views.viewable_type');
|
|
$join->where('views.user_id', '=', user()->id);
|
|
})
|
|
->orderBy('views.views', 'desc')
|
|
->where('favourites.user_id', '=', user()->id);
|
|
|
|
return $query->with('favouritable')
|
|
->skip($skip)
|
|
->take($count)
|
|
->get()
|
|
->pluck('favouritable')
|
|
->filter();
|
|
}
|
|
}
|