mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-01-31 20:21:36 +01:00
Added restrictions to user profile lists
This commit is contained in:
parent
66c56e9d02
commit
1d6137f7e2
@ -42,13 +42,19 @@ class EntityRepo
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the latest books added to the system.
|
* Get the latest books added to the system.
|
||||||
* @param $count
|
* @param int $count
|
||||||
* @param $page
|
* @param int $page
|
||||||
|
* @param bool $additionalQuery
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public function getRecentlyCreatedBooks($count = 20, $page = 0)
|
public function getRecentlyCreatedBooks($count = 20, $page = 0, $additionalQuery = false)
|
||||||
{
|
{
|
||||||
return $this->restrictionService->enforceBookRestrictions($this->book)
|
$query = $this->restrictionService->enforceBookRestrictions($this->book)
|
||||||
->orderBy('created_at', 'desc')->skip($page * $count)->take($count)->get();
|
->orderBy('created_at', 'desc');
|
||||||
|
if ($additionalQuery !== false && is_callable($additionalQuery)) {
|
||||||
|
$additionalQuery($query);
|
||||||
|
}
|
||||||
|
return $query->skip($page * $count)->take($count)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,13 +71,36 @@ class EntityRepo
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the latest pages added to the system.
|
* Get the latest pages added to the system.
|
||||||
* @param $count
|
* @param int $count
|
||||||
* @param $page
|
* @param int $page
|
||||||
|
* @param bool $additionalQuery
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public function getRecentlyCreatedPages($count = 20, $page = 0)
|
public function getRecentlyCreatedPages($count = 20, $page = 0, $additionalQuery = false)
|
||||||
{
|
{
|
||||||
return $this->restrictionService->enforcePageRestrictions($this->page)
|
$query = $this->restrictionService->enforcePageRestrictions($this->page)
|
||||||
->orderBy('created_at', 'desc')->skip($page * $count)->take($count)->get();
|
->orderBy('created_at', 'desc');
|
||||||
|
if ($additionalQuery !== false && is_callable($additionalQuery)) {
|
||||||
|
$additionalQuery($query);
|
||||||
|
}
|
||||||
|
return $query->skip($page * $count)->take($count)->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the latest chapters added to the system.
|
||||||
|
* @param int $count
|
||||||
|
* @param int $page
|
||||||
|
* @param bool $additionalQuery
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function getRecentlyCreatedChapters($count = 20, $page = 0, $additionalQuery = false)
|
||||||
|
{
|
||||||
|
$query = $this->restrictionService->enforceChapterRestrictions($this->chapter)
|
||||||
|
->orderBy('created_at', 'desc');
|
||||||
|
if ($additionalQuery !== false && is_callable($additionalQuery)) {
|
||||||
|
$additionalQuery($query);
|
||||||
|
}
|
||||||
|
return $query->skip($page * $count)->take($count)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,12 +141,15 @@ class UserRepo
|
|||||||
public function getRecentlyCreated(User $user, $count = 20)
|
public function getRecentlyCreated(User $user, $count = 20)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
|
'pages' => $this->entityRepo->getRecentlyCreatedPages($count, 0, function ($query) use ($user) {
|
||||||
->take($count)->get(),
|
$query->where('created_by', '=', $user->id);
|
||||||
'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
|
}),
|
||||||
->take($count)->get(),
|
'chapters' => $this->entityRepo->getRecentlyCreatedChapters($count, 0, function ($query) use ($user) {
|
||||||
'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
|
$query->where('created_by', '=', $user->id);
|
||||||
->take($count)->get()
|
}),
|
||||||
|
'books' => $this->entityRepo->getRecentlyCreatedBooks($count, 0, function ($query) use ($user) {
|
||||||
|
$query->where('created_by', '=', $user->id);
|
||||||
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,9 +121,10 @@ class ActivityService
|
|||||||
*/
|
*/
|
||||||
public function userActivity($user, $count = 20, $page = 0)
|
public function userActivity($user, $count = 20, $page = 0)
|
||||||
{
|
{
|
||||||
$activity = $this->activity->where('user_id', '=', $user->id)
|
$activityList = $this->restrictionService
|
||||||
->orderBy('created_at', 'desc')->skip($count * $page)->take($count)->get();
|
->filterRestrictedEntityRelations($this->activity, 'activities', 'entity_id', 'entity_type')
|
||||||
return $this->filterSimilar($activity);
|
->orderBy('created_at', 'desc')->where('user_id', '=', $user->id)->skip($count * $page)->take($count)->get();
|
||||||
|
return $this->filterSimilar($activityList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user