From 17caf16f484d7199783234e0f99b5b1c80832196 Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 14 Nov 2023 19:21:53 +0200 Subject: [PATCH 1/8] Update mongoose to v8 #LIGHTQUARK-63 State Done --- package.json | 2 +- src/routes/v2/channel.ts | 1 - yarn.lock | 44 +++++++++++++++++++--------------------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 2b5dae1..26a5060 100755 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "file-type": "^18.0.0", "form-data": "^4.0.0", "jose": "^4.10.4", - "mongoose": "^7.6.4", + "mongoose": "^8.0.0", "sharp": "^0.32.1", "tail": "^2.2.4", "typescript": "^4.8.4", diff --git a/src/routes/v2/channel.ts b/src/routes/v2/channel.ts index 3572ddc..24769ad 100755 --- a/src/routes/v2/channel.ts +++ b/src/routes/v2/channel.ts @@ -80,7 +80,6 @@ router.delete("/:id", Auth, P("DELETE_CHANNEL", "channel"), async (req, res) => /** * Edit a channel by id */ -// TODO: Allow roles to edit channels router.patch("/:id", Auth, async (req, res) => { if (!req.params.id) return res.status(400).json(new InvalidReplyMessage("Provide a channel id")); if (!mongoose.isValidObjectId(req.params.id)) return res.status(400).json(new InvalidReplyMessage("Invalid channel id")); diff --git a/yarn.lock b/yarn.lock index 4639c2d..729ccd5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -275,10 +275,10 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== -axios@^1.1.3: - version "1.5.0" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.5.0.tgz#f02e4af823e2e46a9768cfc74691fdd0517ea267" - integrity sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ== +axios@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.1.tgz#76550d644bf0a2d469a01f9244db6753208397d7" + integrity sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g== dependencies: follow-redirects "^1.15.0" form-data "^4.0.0" @@ -353,10 +353,10 @@ braces@~3.0.2: dependencies: fill-range "^7.0.1" -bson@^5.5.0: - version "5.5.1" - resolved "https://registry.yarnpkg.com/bson/-/bson-5.5.1.tgz#f5849d405711a7f23acdda9a442375df858e6833" - integrity sha512-ix0EwukN2EpC0SRWIj/7B5+A6uQMQy6KMREI9qQqvgpkV2frH63T0UDVd1SYedL6dNCmDBYB3QtXi4ISk9YT+g== +bson@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/bson/-/bson-6.2.0.tgz#4b6acafc266ba18eeee111373c2699304a9ba0a3" + integrity sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q== buffer@^5.5.0: version "5.7.1" @@ -1188,25 +1188,23 @@ mongodb-connection-string-url@^2.6.0: "@types/whatwg-url" "^8.2.1" whatwg-url "^11.0.0" -mongodb@5.9.0: - version "5.9.0" - resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-5.9.0.tgz#5a22065fa8cfaf1d58bf2e3c451cd2c4bfa983a2" - integrity sha512-g+GCMHN1CoRUA+wb1Agv0TI4YTSiWr42B5ulkiAfLLHitGK1R+PkSAf3Lr5rPZwi/3F04LiaZEW0Kxro9Fi2TA== +mongodb@6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-6.2.0.tgz#2c9dcb3eeaf528ed850e94b3df392de6c6b0d7ab" + integrity sha512-d7OSuGjGWDZ5usZPqfvb36laQ9CPhnWkAGHT61x5P95p/8nMVeH8asloMwW6GcYFeB0Vj4CB/1wOTDG2RA9BFA== dependencies: - bson "^5.5.0" - mongodb-connection-string-url "^2.6.0" - socks "^2.7.1" - optionalDependencies: "@mongodb-js/saslprep" "^1.1.0" + bson "^6.2.0" + mongodb-connection-string-url "^2.6.0" -mongoose@^7.6.4: - version "7.6.4" - resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-7.6.4.tgz#2f6b796789d0d24636cd7607d7d9c7a302bb550b" - integrity sha512-kadPkS/f5iZJrrMxxOvSoOAErXmdnb28lMvHmuYgmV1ZQTpRqpp132PIPHkJMbG4OC2H0eSXYw/fNzYTH+LUcw== +mongoose@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-8.0.0.tgz#f14175eebfaf5256855d7cbd58bf862819b3fd12" + integrity sha512-PzwkLgm1Jhj0NQdgGfnFsu0QP9V1sBFgbavEgh/IPAUzKAagzvEhuaBuAQOQGjczVWnpIU9tBqyd02cOTgsPlA== dependencies: - bson "^5.5.0" + bson "^6.2.0" kareem "2.5.1" - mongodb "5.9.0" + mongodb "6.2.0" mpath "0.9.0" mquery "5.0.0" ms "2.1.3" @@ -1644,7 +1642,7 @@ socks-proxy-agent@^7.0.0: debug "^4.3.3" socks "^2.6.2" -socks@^2.6.2, socks@^2.7.1: +socks@^2.6.2: version "2.7.1" resolved "https://registry.yarnpkg.com/socks/-/socks-2.7.1.tgz#d8e651247178fde79c0663043e07240196857d55" integrity sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ== From 3af3d7728372b3b3be6ef52de2dfe084414734d2 Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 14 Nov 2023 19:22:00 +0200 Subject: [PATCH 2/8] 0.0.50 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26a5060..ad40e7f 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "lightquark", - "version": "0.0.49", + "version": "0.0.50", "description": "Proof of Concept", "exports": "./src/index.ts", "repository": "https://github.com/LITdevs/Lightquark.git", From 4ee4a26a2ea38e163f3a16bb9fd0ecde1ea3111e Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 14 Nov 2023 19:26:34 +0200 Subject: [PATCH 3/8] Fix missing bot flag #LIGHTQUARK-61 State Done --- src/routes/v2/channel.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes/v2/channel.ts b/src/routes/v2/channel.ts index 24769ad..f53ad4a 100755 --- a/src/routes/v2/channel.ts +++ b/src/routes/v2/channel.ts @@ -311,7 +311,8 @@ router.post("/:id/messages", Auth, P("WRITE_MESSAGE", "channel"), RequiredProper _id: res.locals.user._id, username: await getNick(res.locals.user._id, quark._id), avatarUri: res.locals.user.avatar, - admin: !!res.locals.user.admin + admin: !!res.locals.user.admin, + isBot: !!res.locals.user.isBot } let data = { eventId: "messageCreate", From 4070cea3c1d1c962d0fcdfdc381cca962ae4dc8e Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 14 Nov 2023 19:26:39 +0200 Subject: [PATCH 4/8] 0.0.51 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad40e7f..ca5ca73 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "lightquark", - "version": "0.0.50", + "version": "0.0.51", "description": "Proof of Concept", "exports": "./src/index.ts", "repository": "https://github.com/LITdevs/Lightquark.git", From 63da84e9b708591227308d7a039a4d0c50eacc6a Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 14 Nov 2023 19:41:10 +0200 Subject: [PATCH 5/8] Show failed event in gateway permission error, cleanup, fix network endpoint --- src/index.ts | 65 +--------------------------------------- src/routes/home.ts | 11 ++++++- src/routes/v1/gateway.ts | 4 +-- 3 files changed, 13 insertions(+), 67 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5caab4d..cad4e13 100755 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import fs from "fs"; import { initialize } from 'unleash-client'; import {kitty} from "./util/kitty.js"; export const networkInformation = JSON.parse(fs.readFileSync("network.json").toString()); -const pjson = JSON.parse(fs.readFileSync("package.json").toString()); +export const pjson = JSON.parse(fs.readFileSync("package.json").toString()); const app = express(); Sentry.init({ @@ -73,70 +73,7 @@ app.use("/v2/channel", channelv2); import home from './routes/home.js'; app.use("/", home) -app.get("/v*/network", (req, res) => { - networkInformation.version = pjson.version; - networkInformation.capabilities = { - base: true, // Everything before capabilities was added - userStatus: unleash.isEnabled("LQ_Status", res.locals.unleashContext) // User statuses - } - res.json(networkInformation); -}) -/* -app.post("/roleCreateTest", async (req, res) => { - let Role = db.getRoles(); - let role = new Role({ - name: "Test Role", - color: "#000000", - quark: "643aa2e550c913775aec2058", - description: "This is a test role", - createdBy: "646893a40ca841fd8e8f953e", - priority: 0 - }) - await role.save(); - res.json(role); -}) -app.get("/roleGetTest", async (req, res) => { - let Role = db.getRoles(); - console.time("roleGetTest") - // Find role 646894100df66a3fc81e0919 and populate permissionAssignments - let role = await Role.findById("646897a40644cbd91f00d400").populate("permissionAssignments").populate("roleAssignments"); - console.timeEnd("roleGetTest") - res.json(role); -}) - -app.get("/paGetTest", async (req, res) => { - let PA = db.getPermissionAssignments(); - console.time("paGetTest") - // Find role 646894100df66a3fc81e0919 and populate permissionAssignments - let pa = await PA.findById("646898dbefcff8c704e31f19").populate("role"); - console.timeEnd("paGetTest"); - res.json(pa); -}) - - -app.post("/permissionCreateTest", async (req, res) => { - let PermissionAssignment = db.getPermissionAssignments(); - let pa = new PermissionAssignment({ - role: "646897a40644cbd91f00d400", - permission: "ADMIN", - type: "allow", - scopeType: "quark", - scopeId: "643aa2e550c913775aec2058" - }) - await pa.save(); - res.json(pa); -}) -app.post("/raCreateTest", async (req, res) => { - let RoleAssignment = db.getRoleAssignments(); - let ra = new RoleAssignment({ - role: "646897a40644cbd91f00d400", - user: "646893a40ca841fd8e8f953e" - }) - await ra.save(); - res.json(ra); -}) -*/ app.all("*", (req, res) => { res.reply(new NotFoundReply("Endpoint not found")); diff --git a/src/routes/home.ts b/src/routes/home.ts index 2900589..df3934d 100755 --- a/src/routes/home.ts +++ b/src/routes/home.ts @@ -86,7 +86,7 @@ const knownClients = JSON.parse(fs.readFileSync("src/util/knownClients.json").to import CapabilityParser from "../util/CapabilityParser.js"; import ServerErrorReply from "../classes/reply/ServerErrorReply.js"; import db from "../db.js"; -import {networkInformation} from "../index.js"; +import {networkInformation, pjson, unleash} from "../index.js"; router.get("/features/:clientName", async (req, res) => { try { @@ -146,4 +146,13 @@ router.get("/v*/stats", (req, res ) => { }) }) +router.get("/v*/network", (req, res) => { + networkInformation.version = pjson.version; + networkInformation.capabilities = { + base: true, // Everything before capabilities was added + userStatus: unleash.isEnabled("LQ_Status", res.locals.unleashContext) // User statuses + } + res.json(networkInformation); +}) + export default router; \ No newline at end of file diff --git a/src/routes/v1/gateway.ts b/src/routes/v1/gateway.ts index 73d5fc3..25d43d1 100755 --- a/src/routes/v1/gateway.ts +++ b/src/routes/v1/gateway.ts @@ -111,13 +111,13 @@ async function handleMessage(message, ws, user, socketId) { await sm.subscribe(event, sub, user, socketId); ws.send(JSON.stringify({eventId: "subscribe", message: "Successfully subscribed to event", code: 200})); } else { - ws.send(JSON.stringify({eventId: "error", message: "You are not permitted to subscribe to this event", code: 403})); + ws.send(JSON.stringify({eventId: "error", message: "You are not permitted to subscribe to this event", code: 403, event})); } } else if (event.split("_")[0] === "quark") { let Quarks = db.getQuarks(); try { let quark = await Quarks.findOne({_id: event.split("_")[1], members: user._id}); - if (!quark) return ws.send(JSON.stringify({eventId: "error", message: "You are not permitted to subscribe to this event", code: 403})); + if (!quark) return ws.send(JSON.stringify({eventId: "error", message: "You are not permitted to subscribe to this event", code: 403, event})); const sub = (data) => { ws.send(JSON.stringify(data)); } From bc3a7707b1c78e1a73be3e918f72c1cfcb1c2ede Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 14 Nov 2023 19:41:16 +0200 Subject: [PATCH 6/8] 0.0.52 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ca5ca73..295b1fb 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "lightquark", - "version": "0.0.51", + "version": "0.0.52", "description": "Proof of Concept", "exports": "./src/index.ts", "repository": "https://github.com/LITdevs/Lightquark.git", From 99254955714830d61db2d032c73dbaab273bc37e Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 14 Nov 2023 19:44:45 +0200 Subject: [PATCH 7/8] Change invalid event format to match not permitted event --- src/routes/v1/gateway.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/v1/gateway.ts b/src/routes/v1/gateway.ts index 25d43d1..cac10d1 100755 --- a/src/routes/v1/gateway.ts +++ b/src/routes/v1/gateway.ts @@ -85,7 +85,7 @@ async function handleMessage(message, ws, user, socketId) { if (validEvent !== 1) return ws.send(JSON.stringify({ eventId: "error", message: "Invalid event", - attemptedEvent: event, + event, code: validEvent })); From 7fb4239eac7567385861530bb433ad227e4fff12 Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 14 Nov 2023 19:44:51 +0200 Subject: [PATCH 8/8] 0.0.53 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 295b1fb..54e875e 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "lightquark", - "version": "0.0.52", + "version": "0.0.53", "description": "Proof of Concept", "exports": "./src/index.ts", "repository": "https://github.com/LITdevs/Lightquark.git",