Browse Source

Add basic group info APIs

tags/v2.0
Skylar Ittner 1 year ago
parent
commit
4ac39bd0d3
4 changed files with 54 additions and 1 deletions
  1. 49
    0
      api.php
  2. BIN
      database.mwb
  3. 2
    1
      database.sql
  4. 3
    0
      database_upgrade/1.0.1_1.1.sql

+ 49
- 0
api.php View File

@@ -305,6 +305,55 @@ switch ($VARS['action']) {
}
}
exit(json_encode(["status" => "OK", "apps" => $apps]));
case "getusersbygroup":
if ($VARS['gid']) {
if ($database->has("groups", ['groupid' => $VARS['gid']])) {
$groupid = $VARS['gid'];
} else {
exit(json_encode(["status" => "ERROR", "msg" => lang("group does not exist", false)]));
}
} else {
http_response_code(400);
die("\"400 Bad Request\"");
}
if ($VARS['get'] == "username") {
$users = $database->select('assigned_groups', ['[>]accounts' => ['uid' => 'uid']], 'username', ['groupid' => $groupid]);
} else {
$users = $database->select('assigned_groups', 'uid', ['groupid' => $groupid]);
}
exit(json_encode(["status" => "OK", "users" => $users]));
break;
case "getgroupsbyuser":
if ($VARS['uid']) {
if ($database->has("accounts", ['uid' => $VARS['uid']])) {
$empid = $VARS['uid'];
} else {
exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false)]));
}
} else if ($VARS['username']) {
if ($database->has("accounts", ['username' => strtolower($VARS['username'])])) {
$empid = $database->select('accounts', 'uid', ['username' => strtolower($VARS['username'])]);
} else {
exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false)]));
}
} else {
http_response_code(400);
die("\"400 Bad Request\"");
}
$groups = $database->select('assigned_groups', ["[>]groups" => ["groupid" => "groupid"]], ['groups.groupid (id)', 'groups.groupname (name)'], ['uid' => $empid]);
exit(json_encode(["status" => "OK", "groups" => $groups]));
break;
case "getgroups":
$groups = $database->select('groups', ['groupid (id)', 'groupname (name)']);
exit(json_encode(["status" => "OK", "groups" => $groups]));
break;
case "groupsearch":
if (is_empty($VARS['search']) || strlen($VARS['search']) < 2) {
exit(json_encode(["status" => "OK", "result" => []]));
}
$data = $database->select('groups', ['groupid (id)', 'groupname (name)'], ['groupname[~]' => $VARS['search'], "LIMIT" => 10]);
exit(json_encode(["status" => "OK", "result" => $data]));
break;
default:
http_response_code(404);
die(json_encode("404 Not Found: the requested action is not available."));

BIN
database.mwb View File


+ 2
- 1
database.sql View File

@@ -1,5 +1,5 @@
-- MySQL Script generated by MySQL Workbench
-- Thu 21 Dec 2017 01:19:57 AM MST
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering

@@ -123,7 +123,7 @@ ENGINE = InnoDB;
-- Table `accounthub`.`groups`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `accounthub`.`groups` (
`groupid` INT NOT NULL,
`groupid` INT NOT NULL AUTO_INCREMENT,
`groupname` VARCHAR(45) NOT NULL,
PRIMARY KEY (`groupid`),
UNIQUE INDEX `groupid_UNIQUE` (`groupid` ASC),

+ 3
- 0
database_upgrade/1.0.1_1.1.sql View File

@@ -12,3 +12,6 @@ CREATE TABLE IF NOT EXISTS `onetimekeys` (
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8

ALTER TABLE `groups`
CHANGE COLUMN `groupid` `groupid` INT(11) NOT NULL AUTO_INCREMENT

Loading…
Cancel
Save