diff --git a/core/Api/GroupsAPI.class.php b/core/Api/GroupsAPI.class.php index 611705b..803eb44 100644 --- a/core/Api/GroupsAPI.class.php +++ b/core/Api/GroupsAPI.class.php @@ -177,8 +177,11 @@ namespace Api\Groups { } $id = $this->getParam("uid"); - $sql = $this->user->getSQL(); + if (in_array($id, DEFAULT_GROUPS)) { + return $this->createError("You cannot delete a default group."); + } + $sql = $this->user->getSQL(); $res = $sql->select($sql->count()) ->from("Group") ->where(new Compare("uid", $id)) diff --git a/core/Api/RoutesAPI.class.php b/core/Api/RoutesAPI.class.php index 9adda89..8be140f 100644 --- a/core/Api/RoutesAPI.class.php +++ b/core/Api/RoutesAPI.class.php @@ -26,7 +26,7 @@ namespace Api\Routes { use Api\RoutesAPI; use Driver\SQL\Column\Column; use Driver\SQL\Condition\CondBool; - use Driver\SQL\Condition\Regex; + use Driver\SQL\Condition\CondRegex; class Fetch extends RoutesAPI { @@ -99,7 +99,7 @@ namespace Api\Routes { ->select("uid", "request", "action", "target", "extra") ->from("Route") ->where(new CondBool("active")) - ->where(new Regex($request, new Column("request"))) + ->where(new CondRegex($request, new Column("request"))) ->limit(1) ->execute(); diff --git a/core/Driver/SQL/Condition/CondIn.class.php b/core/Driver/SQL/Condition/CondIn.class.php index f46f350..f0598fe 100644 --- a/core/Driver/SQL/Condition/CondIn.class.php +++ b/core/Driver/SQL/Condition/CondIn.class.php @@ -2,8 +2,6 @@ namespace Driver\SQL\Condition; -use Driver\SQL\Column\Column; - class CondIn extends Condition { private string $column; diff --git a/core/Driver/SQL/Condition/Regex.class.php b/core/Driver/SQL/Condition/CondKeyword.class.php similarity index 57% rename from core/Driver/SQL/Condition/Regex.class.php rename to core/Driver/SQL/Condition/CondKeyword.class.php index f0ba2bf..a153da6 100644 --- a/core/Driver/SQL/Condition/Regex.class.php +++ b/core/Driver/SQL/Condition/CondKeyword.class.php @@ -2,16 +2,19 @@ namespace Driver\SQL\Condition; -class Regex extends Condition { +abstract class CondKeyword extends Condition { private $leftExpression; private $rightExpression; + private string $keyword; - public function __construct($leftExpression, $rightExpression) { + public function __construct($keyword, $leftExpression, $rightExpression) { $this->leftExpression = $leftExpression; $this->rightExpression = $rightExpression; + $this->keyword = $keyword; } public function getLeftExp() { return $this->leftExpression; } public function getRightExp() { return $this->rightExpression; } + public function getKeyword() { return $this->keyword; } } \ No newline at end of file diff --git a/core/Driver/SQL/Condition/CondLike.class.php b/core/Driver/SQL/Condition/CondLike.class.php new file mode 100644 index 0000000..1e7b949 --- /dev/null +++ b/core/Driver/SQL/Condition/CondLike.class.php @@ -0,0 +1,10 @@ +connection); } - - protected function buildCondition($condition, &$params) { - if($condition instanceof Regex) { - $left = $condition->getLeftExp(); - $right = $condition->getRightExp(); - $left = ($left instanceof Column) ? $this->columnName($left->getName()) : $this->addValue($left, $params); - $right = ($right instanceof Column) ? $this->columnName($right->getName()) : $this->addValue($right, $params); - return $left . " REGEXP " . $right; - } else { - return parent::buildCondition($condition, $params); - } - } } diff --git a/core/Driver/SQL/PostgreSQL.class.php b/core/Driver/SQL/PostgreSQL.class.php index 9b5e988..0f5895d 100644 --- a/core/Driver/SQL/PostgreSQL.class.php +++ b/core/Driver/SQL/PostgreSQL.class.php @@ -13,7 +13,7 @@ use \Driver\SQL\Column\DateTimeColumn; use Driver\SQL\Column\BoolColumn; use Driver\SQL\Column\JsonColumn; -use Driver\SQL\Condition\Regex; +use Driver\SQL\Condition\CondRegex; use Driver\SQL\Expression\Add; use Driver\SQL\Strategy\Strategy; use Driver\SQL\Strategy\UpdateStrategy; @@ -304,7 +304,7 @@ class PostgreSQL extends SQL { } protected function buildCondition($condition, &$params) { - if($condition instanceof Regex) { + if($condition instanceof CondRegex) { $left = $condition->getLeftExp(); $right = $condition->getRightExp(); $left = ($left instanceof Column) ? $this->columnName($left->getName()) : $this->addValue($left, $params); diff --git a/core/Driver/SQL/SQL.class.php b/core/Driver/SQL/SQL.class.php index 2404ed2..ac86739 100644 --- a/core/Driver/SQL/SQL.class.php +++ b/core/Driver/SQL/SQL.class.php @@ -6,8 +6,9 @@ use Driver\SQL\Column\Column; use Driver\SQL\Condition\Compare; use Driver\SQL\Condition\CondBool; use Driver\SQL\Condition\CondIn; +use Driver\SQL\Condition\CondKeyword; use Driver\SQL\Condition\CondOr; -use Driver\SQL\Condition\Regex; +use Driver\SQL\Condition\CondRegex; use Driver\SQL\Constraint\Constraint; use \Driver\SQL\Constraint\Unique; use \Driver\SQL\Constraint\PrimaryKey; @@ -343,6 +344,13 @@ abstract class SQL { $values = implode(",", $values); return $this->columnName($condition->getColumn()) . " IN ($values)"; + } else if($condition instanceof CondKeyword) { + $left = $condition->getLeftExp(); + $right = $condition->getRightExp(); + $keyword = $condition->getKeyword(); + $left = ($left instanceof Column) ? $this->columnName($left->getName()) : $this->addValue($left, $params); + $right = ($right instanceof Column) ? $this->columnName($right->getName()) : $this->addValue($right, $params); + return "$left $keyword $right "; } else { $this->lastError = "Unsupported condition type: " . get_class($condition); return false; diff --git a/core/constants.php b/core/constants.php index b752eb6..6989e62 100644 --- a/core/constants.php +++ b/core/constants.php @@ -7,6 +7,10 @@ const USER_GROUP_SUPPORT_NAME = "Support"; const USER_GROUP_ADMIN = 3; const USER_GROUP_ADMIN_NAME = "Administrator"; +const DEFAULT_GROUPS = array( + USER_GROUP_MODERATOR, USER_GROUP_SUPPORT, USER_GROUP_ADMIN +); + function GroupName($index) { $groupNames = array( USER_GROUP_MODERATOR => USER_GROUP_MODERATOR_NAME, diff --git a/core/datetime.php b/core/datetime.php index c09cefc..377c1bc 100644 --- a/core/datetime.php +++ b/core/datetime.php @@ -1,26 +1,5 @@