diff --git a/whiteboard/WhiteboardApp.ts b/whiteboard/WhiteboardApp.ts index f63094b2a6..3a4cfa9d0e 100644 --- a/whiteboard/WhiteboardApp.ts +++ b/whiteboard/WhiteboardApp.ts @@ -116,6 +116,7 @@ export class WhiteboardApp extends App implements IUIKitInteractionHandler { \`/whiteboard delete \` - Delete a whiteboard \`/whiteboard help\` - Display helper message \`/whiteboard list\` - List all the board names in the room + \`/whiteboard deny of \` - Deny a user to edit the board You can use \`Create Whiteboard\` Action Button to create a new whiteboard as well \n Refer https://github.com/RocketChat/Apps.Whiteboard documentation for more details 🚀`, persistence diff --git a/whiteboard/blocks/UtilityBlock.ts b/whiteboard/blocks/UtilityBlock.ts index 6db1a31267..f4eae1c502 100644 --- a/whiteboard/blocks/UtilityBlock.ts +++ b/whiteboard/blocks/UtilityBlock.ts @@ -25,24 +25,6 @@ export async function buildHeaderBlock( ButtonStyle.PRIMARY ); - // const settingButton = getButton( - // "Settings", - // UtilityEnum.PREVIEW_BLOCK_ID, - // UtilityEnum.SETTINGS_BUTTON_ACTION_ID, - // appId, - // "Settings", - // undefined - // ); - - // const deleteButton = getDeleteButton( - // "Delete board", - // UtilityEnum.PREVIEW_BLOCK_ID, - // UtilityEnum.DELETE_BUTTON_ACTION_ID, - // appId, - // "Delete", - // ButtonStyle.DANGER - // ); - let markdownBlock: SectionBlock; if (boardname == undefined) { markdownBlock = getMarkdownBlock( @@ -53,9 +35,7 @@ export async function buildHeaderBlock( } const actionBlock = getActionsBlock(UtilityEnum.PREVIEW_BLOCK_ID, [ - // settingButton, - openbutton, - // deleteButton, + openbutton ]); block.push(markdownBlock); block.push(actionBlock); @@ -176,7 +156,7 @@ export async function permissionHeaderBlock( let markdownBlock: SectionBlock; markdownBlock = getMarkdownBlock( - `${userForBoardPermission} wants to edit *${boardname}*` + `*${userForBoardPermission}* wants to edit *${boardname}*` ); const actionBlock = getActionsBlock(UtilityEnum.PERMISSION_BLOCK_ID, [ diff --git a/whiteboard/handlers/ExecuteViewSubmitHandler.ts b/whiteboard/handlers/ExecuteViewSubmitHandler.ts index 47481bdfa5..903b06d956 100644 --- a/whiteboard/handlers/ExecuteViewSubmitHandler.ts +++ b/whiteboard/handlers/ExecuteViewSubmitHandler.ts @@ -47,7 +47,6 @@ export class ExecuteViewSubmitHandler { .getAppUser()) as IUser; const appId = AppSender.appId; try { - console.log("View Id: ", view); switch (view.id) { // This case is used to handle the submit interaction from the settings modal case UtilityEnum.SETTINGS_MODAL_ID: @@ -400,7 +399,6 @@ export class ExecuteViewSubmitHandler { const messageId = this.context.getInteractionData().view.submit ?.value; - // console.log("MessageId inside Delete Modal ID", messageId) if (messageId) { // Board data is deleted from database const boardName = await deleteBoardByMessageId( @@ -445,46 +443,32 @@ export class ExecuteViewSubmitHandler { .getInteractionResponder() .successResponse(); - // case UtilityEnum.EDIT_MODAL_ID: - // const boardURL = this.context.getInteractionData().view.submit?.url - // console.log("boardURL", boardURL) - // if(boardURL){ - // this.http.get(boardURL) - // } - // return this.context - // .getInteractionResponder() - // .successResponse(); - case UtilityEnum.PERMISSION_MODAL_ID: const boardMessageId = this.context.getInteractionData().view.submit ?.value; - // console.log("MessageId inside Permission Modal ID", messageId) if(boardMessageId){ const room = await this.read .getMessageReader() .getRoom(boardMessageId); if(room){ - // console.log("Checking interaction data", this.context.getInteractionData().view.submit?.value) + const boardData = await getBoardRecordByMessageId(this.read.getPersistenceReader(), boardMessageId) - // console.log("Board data", boardData) + for(let i=0; i obj.id === user.id) + if(match){ + // if the user is admin or board Owner + const response = await removeUserFromBoardOwner(this.room, this.persistence, userName, requiredBoardData) + if(response !== undefined){ + const message = {room: room, sender: appSender, text: `**${userName}** has been removed from the rights of **${boardName}**.`} + return this.read.getNotifier().notifyUser(user, message); + } + else{ + const message = {room: room, sender: appSender, text: "Some error occured!"} + return this.read.getNotifier().notifyUser(user, message); + } + + } + else{ + // if the user is not admin or board Owner + const message = {room: room, sender: appSender, text: "You are not authorized to perform this action"} + return this.read.getNotifier().notifyUser(user, message); + } + } + } public async resolveCommand(context: WhiteboardSlashCommandContext) { switch (this.command[0]) { @@ -374,9 +384,9 @@ export class CommandUtility implements ExecutorProps { case "delete": await this.deleteBoardCommand(); break; - // case "check": - // await this.checkCommand(); - // break; + case "deny": + await this.denyUser(); + break; default: const appSender: IUser = (await this.read .getUserReader() diff --git a/whiteboard/lib/messages.ts b/whiteboard/lib/messages.ts index cd957f92a0..bc2e316b29 100644 --- a/whiteboard/lib/messages.ts +++ b/whiteboard/lib/messages.ts @@ -183,6 +183,7 @@ export async function helperMessage( \`/whiteboard delete \` - Delete a whiteboard \`/whiteboard help\` - Display helper message \`/whiteboard list\` - List all the board names in the room + \`/whiteboard deny of \` - Deny a user to edit the board You can use \`Create Whiteboard\` Action Button to create a new whiteboard as well \n Refer https://github.com/RocketChat/Apps.Whiteboard for more details 🚀 `; @@ -356,3 +357,39 @@ export async function addUsertoBoardOwner( return undefined } } + + +// function to remove user from boardRights +export const removeUserFromBoardOwner = async ( + room: IRoom, + persistance: IPersistence, + userName: string, + board: any, +) => { + + // Add the user to the boardOwner + const boardOwners = board.boardOwner + + // Filter the user from the boardOwner + const boardOwnerArray = boardOwners.filter((boardOwner) => boardOwner.username !== userName) + + if(boardOwnerArray === boardOwners){ + return undefined + } + else{ + // Update the boardData in the database + await storeBoardRecord( + persistance, + room.id, + board.id, + board.boardData, + board.messageId, + board.cover, + board.title, + board.privateMessageId, + board.status, + boardOwnerArray + ) + return boardOwnerArray + } +} \ No newline at end of file diff --git a/whiteboard/persistence/boardInteraction.ts b/whiteboard/persistence/boardInteraction.ts index 9eadf9563c..dd8ea514dd 100644 --- a/whiteboard/persistence/boardInteraction.ts +++ b/whiteboard/persistence/boardInteraction.ts @@ -411,7 +411,6 @@ export const getMessageIdByBoardName = async ( for (const board of boardData) { if (board.title === boardName) { - console.log("Board name mil gaya!"); let messageId = board.messageId; return messageId; }