1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-22 17:12:30 +01:00

Start ripping out old search functionality for models

This commit is contained in:
Dane Everitt 2020-09-13 11:29:47 -07:00
parent 3c7ffaaadb
commit 4dddcaebb0
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
16 changed files with 15 additions and 182 deletions

View File

@ -1,38 +0,0 @@
<?php
namespace Pterodactyl\Contracts\Repository\Attributes;
interface SearchableInterface
{
/**
* Set the search term.
*
* @param string|null $term
* @return $this
* @deprecated
*/
public function search($term);
/**
* Set the search term to use when requesting all records from
* the model.
*
* @param string|null $term
* @return $this
*/
public function setSearchTerm(string $term = null);
/**
* Determine if a valid search term is set on this repository.
*
* @return bool
*/
public function hasSearchTerm(): bool;
/**
* Return the search term.
*
* @return string|null
*/
public function getSearchTerm();
}

View File

@ -4,9 +4,8 @@ namespace Pterodactyl\Contracts\Repository;
use Pterodactyl\Models\Location;
use Illuminate\Support\Collection;
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
interface LocationRepositoryInterface extends RepositoryInterface, SearchableInterface
interface LocationRepositoryInterface extends RepositoryInterface
{
/**
* Return locations with a count of nodes and servers attached to it.

View File

@ -8,7 +8,7 @@ use Illuminate\Support\LazyCollection;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
interface NodeRepositoryInterface extends RepositoryInterface, SearchableInterface
interface NodeRepositoryInterface extends RepositoryInterface
{
const THRESHOLD_PERCENTAGE_LOW = 75;
const THRESHOLD_PERCENTAGE_MEDIUM = 90;

View File

@ -5,9 +5,8 @@ namespace Pterodactyl\Contracts\Repository;
use Pterodactyl\Models\Server;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
interface ServerRepositoryInterface extends RepositoryInterface, SearchableInterface
interface ServerRepositoryInterface extends RepositoryInterface
{
/**
* Returns a listing of all servers that exist including relationships.

View File

@ -6,7 +6,7 @@ use Illuminate\Support\Collection;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
interface UserRepositoryInterface extends RepositoryInterface, SearchableInterface
interface UserRepositoryInterface extends RepositoryInterface
{
/**
* Return all users with counts of servers and subusers of servers.

View File

@ -5,7 +5,6 @@ namespace Pterodactyl\Models;
use Symfony\Component\Yaml\Yaml;
use Illuminate\Container\Container;
use Illuminate\Notifications\Notifiable;
use Pterodactyl\Models\Traits\Searchable;
use Illuminate\Contracts\Encryption\Encrypter;
/**
@ -40,7 +39,6 @@ use Illuminate\Contracts\Encryption\Encrypter;
class Node extends Model
{
use Notifiable;
use Searchable;
/**
* The resource name for this model when it is transformed into an
@ -95,18 +93,6 @@ class Node extends Model
'description', 'maintenance_mode',
];
/**
* Fields that are searchable.
*
* @var array
*/
protected $searchableColumns = [
'name' => 10,
'fqdn' => 8,
'location.short' => 4,
'location.long' => 4,
];
/**
* @var array
*/
@ -216,7 +202,7 @@ class Node extends Model
*/
public function getDecryptedKey(): string
{
return (string) Container::getInstance()->make(Encrypter::class)->decrypt(
return (string)Container::getInstance()->make(Encrypter::class)->decrypt(
$this->daemon_token
);
}

View File

@ -3,7 +3,6 @@
namespace Pterodactyl\Models;
use Illuminate\Notifications\Notifiable;
use Pterodactyl\Models\Traits\Searchable;
use Illuminate\Database\Query\JoinClause;
use Znck\Eloquent\Traits\BelongsToThrough;
@ -58,7 +57,6 @@ class Server extends Model
{
use BelongsToThrough;
use Notifiable;
use Searchable;
/**
* The resource name for this model when it is transformed into an
@ -154,21 +152,6 @@ class Server extends Model
'backup_limit' => 'integer',
];
/**
* Parameters for search querying.
*
* @var array
*/
protected $searchableColumns = [
'name' => 100,
'uuid' => 80,
'uuidShort' => 80,
'external_id' => 50,
'user.email' => 40,
'user.username' => 30,
'node.name' => 10,
];
/**
* Returns the format for server allocations when communicating with the Daemon.
*

View File

@ -1,13 +0,0 @@
<?php
namespace Pterodactyl\Models\Traits;
use Pterodactyl\Extensions\Illuminate\Database\Eloquent\Builder;
trait Searchable
{
public function newEloquentBuilder($query)
{
return new Builder($query);
}
}

View File

@ -8,7 +8,6 @@ use Illuminate\Validation\Rules\In;
use Illuminate\Auth\Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Builder;
use Pterodactyl\Models\Traits\Searchable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Pterodactyl\Traits\Helpers\AvailableLanguages;
use Illuminate\Foundation\Auth\Access\Authorizable;
@ -52,7 +51,6 @@ class User extends Model implements
use AvailableLanguages;
use CanResetPassword;
use Notifiable;
use Searchable;
const USER_LEVEL_USER = 0;
const USER_LEVEL_ADMIN = 1;
@ -120,20 +118,6 @@ class User extends Model implements
*/
protected $hidden = ['password', 'remember_token', 'totp_secret', 'totp_authenticated_at'];
/**
* Parameters for search querying.
*
* @var array
*/
protected $searchableColumns = [
'username' => 100,
'email' => 100,
'external_id' => 80,
'uuid' => 80,
'name_first' => 40,
'name_last' => 40,
];
/**
* Default values for specific fields in the database.
*

View File

@ -11,18 +11,6 @@ trait Searchable
*/
protected $searchTerm;
/**
* Set the search term.
*
* @param string|null $term
* @return $this
* @deprecated
*/
public function search($term)
{
return $this->setSearchTerm($term);
}
/**
* Set the search term to use when requesting all records from
* the model.
@ -41,24 +29,4 @@ trait Searchable
return $clone;
}
/**
* Determine if a valid search term is set on this repository.
*
* @return bool
*/
public function hasSearchTerm(): bool
{
return ! empty($this->searchTerm);
}
/**
* Return the search term.
*
* @return string|null
*/
public function getSearchTerm()
{
return $this->searchTerm;
}
}

View File

@ -289,12 +289,7 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
*/
public function all(): Collection
{
$instance = $this->getBuilder();
if (is_subclass_of(get_called_class(), SearchableInterface::class) && $this->hasSearchTerm()) {
$instance = $instance->search($this->getSearchTerm());
}
return $instance->get($this->getColumns());
return $this->getBuilder()->get($this->getColumns());
}
/**
@ -305,12 +300,7 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
*/
public function paginated(int $perPage): LengthAwarePaginator
{
$instance = $this->getBuilder();
if (is_subclass_of(get_called_class(), SearchableInterface::class) && $this->hasSearchTerm()) {
$instance = $instance->search($this->getSearchTerm());
}
return $instance->paginate($perPage, $this->getColumns());
return $this->getBuilder()->paginate($perPage, $this->getColumns());
}
/**

View File

@ -4,15 +4,12 @@ namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Location;
use Illuminate\Support\Collection;
use Pterodactyl\Repositories\Concerns\Searchable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
class LocationRepository extends EloquentRepository implements LocationRepositoryInterface
{
use Searchable;
/**
* Return the model backing this repository.
*

View File

@ -5,14 +5,11 @@ namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Mount;
use Pterodactyl\Models\Server;
use Illuminate\Support\Collection;
use Pterodactyl\Repositories\Concerns\Searchable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
class MountRepository extends EloquentRepository
{
use Searchable;
/**
* Return the model backing this repository.
*

View File

@ -5,14 +5,11 @@ namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Node;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Pterodactyl\Repositories\Concerns\Searchable;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
class NodeRepository extends EloquentRepository implements NodeRepositoryInterface
{
use Searchable;
/**
* Return the model backing this repository.
*
@ -92,13 +89,7 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
*/
public function getNodeListingData(): LengthAwarePaginator
{
$instance = $this->getBuilder()->with('location')->withCount('servers');
if ($this->hasSearchTerm()) {
$instance->search($this->getSearchTerm());
}
return $instance->paginate(25, $this->getColumns());
return $this->getBuilder()->with('location')->withCount('servers')->paginate(25, $this->getColumns());
}
/**

View File

@ -5,7 +5,6 @@ namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Server;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Builder;
use Pterodactyl\Repositories\Concerns\Searchable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
@ -13,8 +12,6 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class ServerRepository extends EloquentRepository implements ServerRepositoryInterface
{
use Searchable;
/**
* Return the model backing this repository.
*
@ -33,9 +30,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
*/
public function getAllServers(int $paginate): LengthAwarePaginator
{
$instance = $this->getBuilder()->with('node', 'user', 'allocation')->search($this->getSearchTerm());
return $instance->paginate($paginate, $this->getColumns());
return $this->getBuilder()->with('node', 'user', 'allocation')->paginate($paginate, $this->getColumns());
}
/**
@ -67,7 +62,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
if (! is_null($server) && is_null($node)) {
$instance = $instance->where('id', '=', $server);
} elseif (is_null($server) && ! is_null($node)) {
} else if (is_null($server) && ! is_null($node)) {
$instance = $instance->where('node_id', '=', $node);
}
@ -87,7 +82,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
if (! is_null($server) && is_null($node)) {
$instance = $instance->where('id', '=', $server);
} elseif (is_null($server) && ! is_null($node)) {
} else if (is_null($server) && ! is_null($node)) {
$instance = $instance->where('node_id', '=', $node);
}
@ -224,9 +219,9 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
if (! empty($nodes) && ! empty($servers)) {
$instance->whereIn('id', $servers)->orWhereIn('node_id', $nodes);
} elseif (empty($nodes) && ! empty($servers)) {
} else if (empty($nodes) && ! empty($servers)) {
$instance->whereIn('id', $servers);
} elseif (! empty($nodes) && empty($servers)) {
} else if (! empty($nodes) && empty($servers)) {
$instance->whereIn('node_id', $nodes);
}

View File

@ -4,14 +4,11 @@ namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\User;
use Illuminate\Support\Collection;
use Pterodactyl\Repositories\Concerns\Searchable;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
class UserRepository extends EloquentRepository implements UserRepositoryInterface
{
use Searchable;
/**
* Return the model backing this repository.
*
@ -29,9 +26,7 @@ class UserRepository extends EloquentRepository implements UserRepositoryInterfa
*/
public function getAllUsersWithCounts(): LengthAwarePaginator
{
return $this->getBuilder()->withCount('servers')
->search($this->getSearchTerm())
->paginate(50, $this->getColumns());
return $this->getBuilder()->withCount('servers')->paginate(50, $this->getColumns());
}
/**
@ -46,7 +41,7 @@ class UserRepository extends EloquentRepository implements UserRepositoryInterfa
'id', 'email', 'username', 'name_first', 'name_last',
]);
$instance = $this->getBuilder()->search($query)->get($this->getColumns());
$instance = $this->getBuilder()->get($this->getColumns());
return $instance->transform(function ($item) {
$item->md5 = md5(strtolower($item->email));