From a717f40a23abc4d4189940ffe10e4766544d0a72 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Wed, 22 Mar 2023 17:25:28 +0100 Subject: [PATCH] room rights restructur --- src/api/acts/rooms.ts | 36 +++++++++++++++++++++++++++++------- src/server/permissions.ts | 4 ++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/api/acts/rooms.ts b/src/api/acts/rooms.ts index 391ecd8..0d22a6e 100644 --- a/src/api/acts/rooms.ts +++ b/src/api/acts/rooms.ts @@ -110,7 +110,7 @@ export const getRoomInfo: Act = { title: req[0][rooms.title], description: req[0][rooms.description], icon: req[0][rooms.icon], - + isAdmin: req[0][roomMembers.admin] ? true : false, isOwner: client.state == STATE.client && req[0][ownerAlias] == client.name, }) @@ -435,7 +435,7 @@ export const setAdminStatus: Act = { aws(resp.state, resp.data); return; } - let roomID = await client.isRoomAdmin(data.room, ROOM_RIGHTS.MANAGE_MEMBERS); + let roomID = await client.isRoomAdmin(data.room, ROOM_RIGHTS.CHANGE_ADMIN); if (roomID == -1) return void aws("error", "roomAdmin"); let req = await update(roomMembers) .set(roomMembers.admin, data.admin) @@ -499,13 +499,12 @@ export const leaveRoom: Act = { } }; -export const roomSettings: Act = { +export const setVisibility: Act = { state: STATE.client | STATE.remote, right: 0, data: { room: "string", server: "string", - rights: "number", //see permissions.ts visibility: "number" //0 is not, 1 only to clients, 2 or bigger everywhere }, func: async (client, data, aws) => { @@ -515,18 +514,41 @@ export const roomSettings: Act = { aws(resp.state, resp.data); return; } - let roomID = await client.isRoomAdmin(data.room, ROOM_RIGHTS.CHANGE_SETTINGS); + let roomID = await client.isRoomAdmin(data.room, ROOM_RIGHTS.OTA); if (roomID == -1) return void aws("error", "roomAdmin"); let req = await update(rooms) - .set(rooms.rights, data.rights) .set(rooms.visibility, data.visibility) .where(eq(rooms.roomID, roomID)) .query(db); aws("ok", ""); } }; +export const setRoomRight: Act = { + state: STATE.client | STATE.remote, + right: 0, + data: { + room: "string", + server: "string", + rights: "number", //see permissions.ts + }, + func: async (client, data, aws) => { + if (!checkSelfTag(data.server)) { + if (client.state != STATE.client) return void aws("error", "right"); + let resp = await client.pass(data.server, "roomSettings", data); + aws(resp.state, resp.data); + return; + } + let roomID = await client.isRoomAdmin(data.room, ROOM_RIGHTS.CHANGE_ADMIN); + if (roomID == -1) return void aws("error", "roomAdmin"); + let req = await update(rooms) + .set(rooms.rights, data.rights) + .where(eq(rooms.roomID, roomID)) + .query(db); + aws("ok", ""); + } +}; -export const roomMeta: Act = { +export const changeRoomMeta: Act = { state: STATE.client | STATE.remote, right: 0, data: { diff --git a/src/server/permissions.ts b/src/server/permissions.ts index 4d232ce..60a3a9c 100644 --- a/src/server/permissions.ts +++ b/src/server/permissions.ts @@ -21,6 +21,6 @@ export const ROOM_RIGHTS = { //when changing, look in main (db defaults) LIST_GROUPS_ITEMS: 0b0000100, //edit room intern listGroups and listItems CHANGE_META: 0b0001000, OTA: 0b0010000, //edit otas - CHANGE_SETTINGS: 0b0100000, - MANAGE_MEMBERS: 0b1000000, + MANAGE_MEMBERS: 0b0100000, + CHANGE_ADMIN: 0b1000000, };