- $activity = $entity->hasMany('BookStack\Activity')->orderBy('created_at', 'desc')
- ->skip($count * $page)->take($count)->get();
+ if ($entity->isA('book')) {
+ $query = $this->activity->where('book_id', '=', $entity->id);
+ } else {
+ $query = $this->activity->where('entity_type', '=', get_class($entity))
+ ->where('entity_id', '=', $entity->id);
+ }
+
+ $activity = $this->permissionService
+ ->filterRestrictedEntityRelations($query, 'activities', 'entity_id', 'entity_type')
+ ->orderBy('created_at', 'desc')->with(['entity', 'user.avatar'])->skip($count * $page)->take($count)->get();