mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-09 10:22:51 +03:00
Revised webhooks list to new format
Also aligned query naming to start with model in use. Also added created/updated sort options to roles.
This commit is contained in:
34
app/Actions/Queries/WebhooksAllPaginatedAndSorted.php
Normal file
34
app/Actions/Queries/WebhooksAllPaginatedAndSorted.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace BookStack\Actions\Queries;
|
||||
|
||||
use BookStack\Actions\Webhook;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* Get all the webhooks in the system in a paginated format.
|
||||
*/
|
||||
class WebhooksAllPaginatedAndSorted
|
||||
{
|
||||
/**
|
||||
* @param array{sort: string, order: string, search: string} $sortData
|
||||
*/
|
||||
public function run(int $count, array $sortData): LengthAwarePaginator
|
||||
{
|
||||
$sort = $sortData['sort'];
|
||||
|
||||
$query = Webhook::query()->select(['*'])
|
||||
->withCount(['trackedEvents'])
|
||||
->orderBy($sort, $sortData['order']);
|
||||
|
||||
if ($sortData['search']) {
|
||||
$term = '%' . $sortData['search'] . '%';
|
||||
$query->where(function ($query) use ($term) {
|
||||
$query->where('name', 'like', $term)
|
||||
->orWhere('endpoint', 'like', $term);
|
||||
});
|
||||
}
|
||||
|
||||
return $query->paginate($count);
|
||||
}
|
||||
}
|
@@ -8,7 +8,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
/**
|
||||
* Get all the roles in the system in a paginated format.
|
||||
*/
|
||||
class AllRolesPaginatedAndSorted
|
||||
class RolesAllPaginatedAndSorted
|
||||
{
|
||||
/**
|
||||
* @param array{sort: string, order: string, search: string} $sortData
|
@@ -11,7 +11,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
* user is assumed to be trusted. (Admin users).
|
||||
* Email search can be abused to extract email addresses.
|
||||
*/
|
||||
class AllUsersPaginatedAndSorted
|
||||
class UsersAllPaginatedAndSorted
|
||||
{
|
||||
/**
|
||||
* @param array{sort: string, order: string, search: string} $sortData
|
@@ -3,7 +3,7 @@
|
||||
namespace BookStack\Http\Controllers;
|
||||
|
||||
use BookStack\Auth\Permissions\PermissionsRepo;
|
||||
use BookStack\Auth\Queries\AllRolesPaginatedAndSorted;
|
||||
use BookStack\Auth\Queries\RolesAllPaginatedAndSorted;
|
||||
use BookStack\Auth\Role;
|
||||
use BookStack\Exceptions\PermissionsException;
|
||||
use Exception;
|
||||
@@ -32,7 +32,7 @@ class RoleController extends Controller
|
||||
'order' => setting()->getForCurrentUser('roles_sort_order', 'asc'),
|
||||
];
|
||||
|
||||
$roles = (new AllRolesPaginatedAndSorted())->run(20, $listDetails);
|
||||
$roles = (new RolesAllPaginatedAndSorted())->run(20, $listDetails);
|
||||
$roles->appends(['search' => $listDetails['search']]);
|
||||
|
||||
$this->setPageTitle(trans('settings.roles'));
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace BookStack\Http\Controllers;
|
||||
|
||||
use BookStack\Auth\Access\SocialAuthService;
|
||||
use BookStack\Auth\Queries\AllUsersPaginatedAndSorted;
|
||||
use BookStack\Auth\Queries\UsersAllPaginatedAndSorted;
|
||||
use BookStack\Auth\Role;
|
||||
use BookStack\Auth\User;
|
||||
use BookStack\Auth\UserRepo;
|
||||
@@ -42,7 +42,7 @@ class UserController extends Controller
|
||||
'order' => setting()->getForCurrentUser('users_sort_order', 'asc'),
|
||||
];
|
||||
|
||||
$users = (new AllUsersPaginatedAndSorted())->run(20, $listDetails);
|
||||
$users = (new UsersAllPaginatedAndSorted())->run(20, $listDetails);
|
||||
|
||||
$this->setPageTitle(trans('settings.users'));
|
||||
$users->appends(['search' => $listDetails['search']]);
|
||||
@@ -251,7 +251,7 @@ class UserController extends Controller
|
||||
*/
|
||||
public function changeSort(Request $request, string $id, string $type)
|
||||
{
|
||||
$validSortTypes = ['books', 'bookshelves', 'shelf_books', 'users', 'roles'];
|
||||
$validSortTypes = ['books', 'bookshelves', 'shelf_books', 'users', 'roles', 'webhooks'];
|
||||
if (!in_array($type, $validSortTypes)) {
|
||||
return redirect()->back(500);
|
||||
}
|
||||
@@ -322,7 +322,7 @@ class UserController extends Controller
|
||||
// Probably better to do a simple validation here then validate at usage.
|
||||
$validSorts = [
|
||||
'name', 'created_at', 'updated_at', 'default', 'email', 'last_activity_at', 'display_name',
|
||||
'users_count', 'permissions_count',
|
||||
'users_count', 'permissions_count', 'endpoint', 'active',
|
||||
];
|
||||
if (!in_array($sort, $validSorts)) {
|
||||
$sort = 'name';
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace BookStack\Http\Controllers;
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Actions\Queries\WebhooksAllPaginatedAndSorted;
|
||||
use BookStack\Actions\Webhook;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -18,16 +19,23 @@ class WebhookController extends Controller
|
||||
/**
|
||||
* Show all webhooks configured in the system.
|
||||
*/
|
||||
public function index()
|
||||
public function index(Request $request)
|
||||
{
|
||||
$webhooks = Webhook::query()
|
||||
->orderBy('name', 'desc')
|
||||
->with('trackedEvents')
|
||||
->get();
|
||||
$listDetails = [
|
||||
'search' => $request->get('search', ''),
|
||||
'sort' => setting()->getForCurrentUser('webhooks_sort', 'name'),
|
||||
'order' => setting()->getForCurrentUser('webhooks_sort_order', 'asc'),
|
||||
];
|
||||
|
||||
$webhooks = (new WebhooksAllPaginatedAndSorted())->run(20, $listDetails);
|
||||
$webhooks->appends(['search' => $listDetails['search']]);
|
||||
|
||||
$this->setPageTitle(trans('settings.webhooks'));
|
||||
|
||||
return view('settings.webhooks.index', ['webhooks' => $webhooks]);
|
||||
return view('settings.webhooks.index', [
|
||||
'webhooks' => $webhooks,
|
||||
'listDetails' => $listDetails,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user