Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic multiple admin users support #3571

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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 @@ -171,9 +169,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