Skip to content

Commit

Permalink
allow using OR operator in ListUsers endpoint (NamelessMC#2460)
Browse files Browse the repository at this point in the history
  • Loading branch information
tadhgboyle committed Oct 24, 2021
1 parent cce8d26 commit 3175009
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions modules/Core/includes/endpoints/ListUsersEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ public function execute(Nameless2API $api) {
$query = 'SELECT u.id, u.username, u.uuid, u.isbanned AS banned, u.active FROM nl2_users u';
}

$operator = isset($_GET['operator']) && $_GET['operator'] == 'OR'
? ' OR'
: ' AND';

if (isset($_GET['group_id'])) {
$query .= ' INNER JOIN nl2_users_groups ug ON u.id = ug.user_id WHERE ug.group_id = ' . $_GET['group_id'];
$filterGroup = true;
}

if (isset($_GET['banned'])) {
if (isset($filterGroup)) {
$query .= ' AND';
$query .= $operator;
} else {
$query .= ' WHERE';
}
Expand All @@ -39,7 +43,7 @@ public function execute(Nameless2API $api) {

if (isset($_GET['active'])) {
if (isset($filterBanned) || isset($filterGroup)) {
$query .= ' AND';
$query .= $operator;
} else {
$query .= ' WHERE';
}
Expand All @@ -49,7 +53,7 @@ public function execute(Nameless2API $api) {

if ($discord_enabled && isset($_GET['discord_linked'])) {
if (isset($filterBanned) || isset($filterActive) || isset($filterGroup)) {
$query .= ' AND';
$query .= $operator;
} else {
$query .= ' WHERE';
}
Expand Down

0 comments on commit 3175009

Please sign in to comment.