Skip to content

Commit

Permalink
Merge pull request #3 from startialab-inc/M1CK431/add_basic_multiple_…
Browse files Browse the repository at this point in the history
…admin_users

add basic multiple admin users
  • Loading branch information
kyurin-shu authored Aug 31, 2023
2 parents 031121c + 5f06084 commit b6f0389
Show file tree
Hide file tree
Showing 27 changed files with 831 additions and 190 deletions.
10 changes: 3 additions & 7 deletions server/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ async function sendNotificationList(socket) {
const timeLogger = new TimeLogger();

let result = [];
let list = await R.find("notification", " user_id = ? ", [
socket.userID,
]);
let list = await R.findAll("notification");

for (let bean of list) {
let notificationObject = bean.export();
Expand Down Expand Up @@ -105,7 +103,7 @@ async function sendImportantHeartbeatList(socket, monitorID, toUser = false, ove
async function sendProxyList(socket) {
const timeLogger = new TimeLogger();

const list = await R.find("proxy", " user_id = ? ", [ socket.userID ]);
const list = await R.findAll("proxy");
io.to(socket.userID).emit("proxyList", list.map(bean => bean.export()));

timeLogger.print("Send Proxy List");
Expand Down Expand Up @@ -174,9 +172,7 @@ async function sendDockerHostList(socket) {
const timeLogger = new TimeLogger();

let result = [];
let list = await R.find("docker_host", " user_id = ? ", [
socket.userID,
]);
let list = await R.findAll("docker_host");

for (let bean of list) {
result.push(bean.toJSON());
Expand Down
7 changes: 3 additions & 4 deletions server/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DockerHost {
let bean;

if (dockerHostID) {
bean = await R.findOne("docker_host", " id = ? AND user_id = ? ", [ dockerHostID, userID ]);
bean = await R.findOne("docker_host", " id = ? ", [ dockerHostID ]);

if (!bean) {
throw new Error("docker host not found");
Expand All @@ -46,11 +46,10 @@ class DockerHost {
/**
* Delete a Docker host
* @param {number} dockerHostID ID of the Docker host to delete
* @param {number} userID ID of the user who created the Docker host
* @returns {Promise<void>}
*/
static async delete(dockerHostID, userID) {
let bean = await R.findOne("docker_host", " id = ? AND user_id = ? ", [ dockerHostID, userID ]);
static async delete(dockerHostID) {
let bean = await R.findOne("docker_host", " id = ? ", [ dockerHostID ]);

if (!bean) {
throw new Error("docker host not found");
Expand Down
20 changes: 5 additions & 15 deletions server/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ class Notification {
let bean;

if (notificationID) {
bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
notificationID,
userID,
]);
bean = await R.findOne("notification", " id = ? ", [ notificationID ]);

if (! bean) {
throw new Error("notification not found");
Expand All @@ -188,14 +185,10 @@ class Notification {
/**
* Delete a notification
* @param {number} notificationID ID of notification to delete
* @param {number} userID ID of user who created notification
* @returns {Promise<void>}
*/
static async delete(notificationID, userID) {
let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [
notificationID,
userID,
]);
static async delete(notificationID) {
let bean = await R.findOne("notification", " id = ? ", [ notificationID ]);

if (! bean) {
throw new Error("notification not found");
Expand All @@ -219,13 +212,10 @@ class Notification {
/**
* Apply the notification to every monitor
* @param {number} notificationID ID of notification to apply
* @param {number} userID ID of user who created notification
* @returns {Promise<void>}
*/
async function applyNotificationEveryMonitor(notificationID, userID) {
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
userID
]);
async function applyNotificationEveryMonitor(notificationID) {
let monitors = await R.getAll("SELECT id FROM monitor");

for (let i = 0; i < monitors.length; i++) {
let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [
Expand Down
12 changes: 5 additions & 7 deletions server/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Proxy {
let bean;

if (proxyID) {
bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [ proxyID, userID ]);
bean = await R.findOne("proxy", " id = ? ", [ proxyID ]);

if (!bean) {
throw new Error("proxy not found");
Expand Down Expand Up @@ -67,11 +67,10 @@ class Proxy {
* Deletes proxy with given id and removes it from monitors
*
* @param proxyID
* @param userID
* @return {Promise<void>}
*/
static async delete(proxyID, userID) {
const bean = await R.findOne("proxy", " id = ? AND user_id = ? ", [ proxyID, userID ]);
static async delete(proxyID) {
const bean = await R.findOne("proxy", " id = ? ", [ proxyID ]);

if (!bean) {
throw new Error("proxy not found");
Expand Down Expand Up @@ -173,12 +172,11 @@ class Proxy {
* Applies given proxy id to monitors
*
* @param proxyID
* @param userID
* @return {Promise<void>}
*/
async function applyProxyEveryMonitor(proxyID, userID) {
async function applyProxyEveryMonitor(proxyID) {
// Find all monitors with id and proxy id
const monitors = await R.getAll("SELECT id, proxy_id FROM monitor WHERE user_id = ?", [ userID ]);
const monitors = await R.getAll("SELECT id, proxy_id FROM monitor");

// Update proxy id not match with given proxy id
for (const monitor of monitors) {
Expand Down
Loading

0 comments on commit b6f0389

Please sign in to comment.