fix: Changed group assignment.
This commit is contained in:
@@ -25,7 +25,7 @@ declare global {
|
||||
uname: string;
|
||||
admin?: number;
|
||||
locked?: boolean;
|
||||
room?: number
|
||||
room?: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export class NotifcationHelper {
|
||||
return await this.send(message, await Notification.aggregate(roomNotif(room)))
|
||||
},
|
||||
group: async (group: string) => {
|
||||
return await this.send(message, await Notification.aggregate(groupNotif(group)))
|
||||
return await this.send(message, [])
|
||||
},
|
||||
withRoom: async () => {
|
||||
return await this.send(message, await Notification.aggregate(allNotif()))
|
||||
|
||||
@@ -82,70 +82,7 @@ function allNotif() {
|
||||
}
|
||||
|
||||
function groupNotif(group: string) {
|
||||
var pipeline: PipelineStage[] = [
|
||||
{
|
||||
$match:
|
||||
{
|
||||
_id: new Types.ObjectId(group)
|
||||
}
|
||||
},
|
||||
{
|
||||
$graphLookup:
|
||||
{
|
||||
from: "logins",
|
||||
startWith: "$rooms",
|
||||
connectFromField: "rooms",
|
||||
connectToField: "room",
|
||||
as: "logins",
|
||||
},
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
unames: {
|
||||
$function: {
|
||||
body: "function (arg, arg2) { if (!arg2) arg2 = []; return [...arg2,...arg.map((s) => s.uname)];}",
|
||||
args: ["$logins", "$unames"],
|
||||
lang: "js",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind:
|
||||
{
|
||||
path: "$unames",
|
||||
},
|
||||
},
|
||||
{
|
||||
$graphLookup:
|
||||
{
|
||||
from: "notifications",
|
||||
startWith: "$unames",
|
||||
connectFromField: "unames",
|
||||
connectToField: "uname",
|
||||
as: "notif",
|
||||
},
|
||||
},
|
||||
{
|
||||
$project:
|
||||
{
|
||||
notif: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind:
|
||||
{
|
||||
path: "$notif",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot:
|
||||
{
|
||||
newRoot: "$notif",
|
||||
},
|
||||
},
|
||||
]
|
||||
return pipeline
|
||||
return
|
||||
}
|
||||
|
||||
export { userNotif, roomNotif, allNotif, groupNotif }
|
||||
@@ -1,17 +1,19 @@
|
||||
import User from "@schemas/User";
|
||||
import { Router } from "express"
|
||||
import { Perms, adminCond, adminPerm } from "@/utility";
|
||||
import capability from "@/capability";
|
||||
import Group from "@/schemas/Group";
|
||||
|
||||
const accsRouter = Router()
|
||||
|
||||
accsRouter.use(adminPerm(Perms.Accs))
|
||||
|
||||
accsRouter.get('/', async (req, res)=> {
|
||||
if (req.user.admin) {
|
||||
res.send(await User.find({"uname": {"$ne": req.user.uname}}, {pass: 0}))
|
||||
return
|
||||
var data = {
|
||||
users: await User.find({"uname": {"$ne": req.user.uname}}, {pass: 0}),
|
||||
groups: capability.settings.groups ? await Group.find() : undefined
|
||||
}
|
||||
res.send(await User.find({"uname": {"$ne": req.user.uname}}, {pass: 0, admin: 0}))
|
||||
res.send(data)
|
||||
})
|
||||
|
||||
accsRouter.post('/', async (req, res)=> {
|
||||
@@ -45,7 +47,7 @@ accsRouter.put('/:id', async (req, res)=> {
|
||||
if (adminCond(req.body.flags, Perms.Superadmin)) {
|
||||
res.status(400).send("Cannot set superadmin")
|
||||
} else {
|
||||
await user.set({uname: req.body.uname, room: req.body.room, admin: req.body.flags, fname: req.body.fname, surname: req.body.surname}).save()
|
||||
await user.set({uname: req.body.uname, room: req.body.room, admin: req.body.flags, fname: req.body.fname, surname: req.body.surname, groups: req.body.groups}).save()
|
||||
res.send({status: 200})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,10 @@ import { ObjectId, Schema, model } from "mongoose"
|
||||
|
||||
interface IGroup {
|
||||
name: string;
|
||||
rooms?: number[];
|
||||
unames?: string[];
|
||||
}
|
||||
|
||||
const groupSchema = new Schema<IGroup>({
|
||||
name: {type: String, required: true},
|
||||
rooms: [Schema.Types.Number],
|
||||
unames: [Schema.Types.String]
|
||||
name: {type: String, required: true}
|
||||
})
|
||||
|
||||
export default model("group", groupSchema)
|
||||
@@ -1,25 +1,27 @@
|
||||
import mongoose, { Schema } from "mongoose"
|
||||
import mongoose, { ObjectId, Schema } from "mongoose"
|
||||
|
||||
// TODO: Unify `fname` and `surename` into single field
|
||||
|
||||
interface IUser {
|
||||
uname: string;
|
||||
pass: string;
|
||||
room?: number;
|
||||
room?: string;
|
||||
admin?: number;
|
||||
locked?: boolean;
|
||||
fname?: string;
|
||||
surname?: string;
|
||||
groups: ObjectId[];
|
||||
}
|
||||
|
||||
const userSchema = new Schema<IUser>({
|
||||
uname: {type: String, required: true},
|
||||
pass: {type: String, required: true, default: "$2y$10$wxDhf.XiXkmdKrFqYUEa0.F4Bf.pDykZaMmgjvyLyeRP3E/Xy0hbC"},
|
||||
room: Number,
|
||||
room: String,
|
||||
admin: Number,
|
||||
locked: {type: Boolean, default: false},
|
||||
fname: String,
|
||||
surname: String
|
||||
surname: String,
|
||||
groups: [{type: mongoose.Types.ObjectId, ref: "Group"}]
|
||||
})
|
||||
|
||||
export default mongoose.model("logins", userSchema)
|
||||
Reference in New Issue
Block a user