v0.9.31 rules changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jama-backend",
|
||||
"version": "0.9.30",
|
||||
"version": "0.9.31",
|
||||
"description": "TeamChat backend server",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -69,6 +69,15 @@ router.post('/multigroup', authMiddleware, adminMiddleware, (req, res) => {
|
||||
if (db.prepare('SELECT id FROM multi_group_dms WHERE LOWER(name) = LOWER(?)').get(name.trim())) {
|
||||
return res.status(400).json({ error: 'Name already in use' });
|
||||
}
|
||||
// Check for duplicate user group set
|
||||
const newGroupIds = [...new Set(userGroupIds.map(Number).filter(Boolean))].sort();
|
||||
const allDms = db.prepare('SELECT id, name FROM multi_group_dms').all();
|
||||
for (const existing of allDms) {
|
||||
const existingIds = db.prepare('SELECT user_group_id FROM multi_group_dm_members WHERE multi_group_dm_id = ?').all(existing.id).map(r => r.user_group_id).sort();
|
||||
if (existingIds.length === newGroupIds.length && existingIds.every((id, i) => id === newGroupIds[i])) {
|
||||
return res.status(400).json({ error: `DM not created — "${existing.name}" already exists with the same member groups.` });
|
||||
}
|
||||
}
|
||||
const admin = db.prepare('SELECT id FROM users WHERE is_default_admin = 1').get();
|
||||
const dmResult = db.prepare(`INSERT INTO groups (name, type, owner_id, is_managed) VALUES (?, 'private', ?, 1)`).run(name.trim(), admin?.id || req.user.id);
|
||||
const dmGroupId = dmResult.lastInsertRowid;
|
||||
@@ -179,6 +188,17 @@ router.post('/', authMiddleware, adminMiddleware, (req, res) => {
|
||||
if (db.prepare('SELECT id FROM user_groups WHERE LOWER(name) = LOWER(?)').get(name.trim())) {
|
||||
return res.status(400).json({ error: 'A group with that name already exists' });
|
||||
}
|
||||
// Check for duplicate member set
|
||||
const newIds = [...new Set((Array.isArray(memberIds) ? memberIds : []).map(Number).filter(Boolean))].sort();
|
||||
if (newIds.length > 0) {
|
||||
const allGroups = db.prepare('SELECT id, name FROM user_groups').all();
|
||||
for (const existing of allGroups) {
|
||||
const existingIds = db.prepare('SELECT user_id FROM user_group_members WHERE user_group_id = ?').all(existing.id).map(r => r.user_id).sort();
|
||||
if (existingIds.length === newIds.length && existingIds.every((id, i) => id === newIds[i])) {
|
||||
return res.status(400).json({ error: `Group not created — "${existing.name}" already exists with the same members.` });
|
||||
}
|
||||
}
|
||||
}
|
||||
const admin = db.prepare('SELECT id FROM users WHERE is_default_admin = 1').get();
|
||||
const dmResult = db.prepare(`INSERT INTO groups (name, type, owner_id, is_readonly, is_direct, is_managed) VALUES (?, 'private', ?, 0, 0, 1)`).run(name.trim(), admin?.id || req.user.id);
|
||||
const dmGroupId = dmResult.lastInsertRowid;
|
||||
|
||||
Reference in New Issue
Block a user