X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/66c56e9d02efe5ee6c77fcb41ba82176c65f5475..refs/pull/139/head:/app/Repos/UserRepo.php diff --git a/app/Repos/UserRepo.php b/app/Repos/UserRepo.php index ec6f3d0d1..0926f6304 100644 --- a/app/Repos/UserRepo.php +++ b/app/Repos/UserRepo.php @@ -51,6 +51,27 @@ class UserRepo return $this->user->with('roles', 'avatar')->orderBy('name', 'asc')->get(); } + /** + * Get all the users with their permissions in a paginated format. + * @param int $count + * @param $sortData + * @return \Illuminate\Database\Eloquent\Builder|static + */ + public function getAllUsersPaginatedAndSorted($count = 20, $sortData) + { + $query = $this->user->with('roles', 'avatar')->orderBy($sortData['sort'], $sortData['order']); + + if ($sortData['search']) { + $term = '%' . $sortData['search'] . '%'; + $query->where(function($query) use ($term) { + $query->where('name', 'like', $term) + ->orWhere('email', 'like', $term); + }); + } + + return $query->paginate($count); + } + /** * Creates a new user and attaches a role to them. * @param array $data @@ -106,7 +127,8 @@ class UserRepo return $this->user->forceCreate([ 'name' => $data['name'], 'email' => $data['email'], - 'password' => bcrypt($data['password']) + 'password' => bcrypt($data['password']), + 'email_confirmed' => false ]); } @@ -141,12 +163,15 @@ class UserRepo public function getRecentlyCreated(User $user, $count = 20) { return [ - 'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc') - ->take($count)->get(), - 'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->orderBy('created_at', 'desc') - ->take($count)->get(), - 'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->orderBy('created_at', 'desc') - ->take($count)->get() + 'pages' => $this->entityRepo->getRecentlyCreatedPages($count, 0, function ($query) use ($user) { + $query->where('created_by', '=', $user->id); + }), + 'chapters' => $this->entityRepo->getRecentlyCreatedChapters($count, 0, function ($query) use ($user) { + $query->where('created_by', '=', $user->id); + }), + 'books' => $this->entityRepo->getRecentlyCreatedBooks($count, 0, function ($query) use ($user) { + $query->where('created_by', '=', $user->id); + }) ]; } @@ -158,12 +183,21 @@ class UserRepo public function getAssetCounts(User $user) { return [ - 'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->count(), + 'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->count(), 'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->count(), - 'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->count(), + 'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->count(), ]; } + /** + * Get the roles in the system that are assignable to a user. + * @return mixed + */ + public function getAssignableRoles() + { + return $this->role->visible(); + } + /** * Get all the roles which can be given restricted access to * other entities in the system. @@ -171,7 +205,7 @@ class UserRepo */ public function getRestrictableRoles() { - return $this->role->where('name', '!=', 'admin')->get(); + return $this->role->where('hidden', '=', false)->where('system_name', '=', '')->get(); } } \ No newline at end of file