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