User Groups fix + frontend

This commit is contained in:
2024-05-04 11:18:28 +02:00
parent 91520dd26c
commit e7283310f0
7 changed files with 150 additions and 37 deletions

View File

@@ -54,11 +54,16 @@ namespace Core\API {
namespace Core\API\Groups {
use Core\API\GroupsAPI;
use Core\API\Parameter\ArrayType;
use Core\API\Parameter\Parameter;
use Core\API\Parameter\RegexType;
use Core\API\Parameter\StringType;
use Core\API\Traits\Pagination;
use Core\Driver\SQL\Column\Column;
use Core\Driver\SQL\Condition\Compare;
use Core\Driver\SQL\Condition\CondIn;
use Core\Driver\SQL\Condition\CondLike;
use Core\Driver\SQL\Condition\CondNot;
use Core\Driver\SQL\Expression\Alias;
use Core\Driver\SQL\Expression\Count;
use Core\Driver\SQL\Join\InnerJoin;
@@ -118,6 +123,48 @@ namespace Core\API\Groups {
}
}
class Search extends GroupsAPI {
public function __construct(Context $context, bool $externalCall = false) {
parent::__construct($context, $externalCall, [
"query" => new StringType("query", -1, true, NULL),
"exclude" => new ArrayType("exclude", Parameter::TYPE_INT, true, true, [])
]);
}
protected function _execute(): bool {
$sql = $this->context->getSQL();
$query = $this->getParam("query");
$exclude = array_unique($this->getParam("exclude"));
$groupsQuery = Group::createBuilder($sql, false)
->limit(5);
if (!empty($query)) {
$groupsQuery->where(new CondLike(new Column("name"), "%$query%"));
}
if (!empty($exclude)) {
$groupsQuery->where(new CondNot(new CondIn(new Column("id"), $exclude)));
}
$groups = Group::findBy($groupsQuery);
if ($groups === false) {
return $this->createError($sql->getLastError());
}
$this->result["groups"] = $groups;
return true;
}
public static function getDescription(): string {
return "Returns a list of groups matching the search criteria";
}
public static function getDefaultPermittedGroups(): array {
return [Group::ADMIN, Group::SUPPORT];
}
}
class Get extends GroupsAPI {
public function __construct(Context $context, bool $externalCall = false) {
parent::__construct($context, $externalCall, [