Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions whiteboard/blocks/UtilityBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function buildHeaderBlockAfterPermission(
UtilityEnum.PREVIEW_BLOCK_ID,
UtilityEnum.SETTINGS_BUTTON_ACTION_ID,
appId,
"Settings",
`${boardURL}, ${boardname}`,
undefined
);

Expand Down Expand Up @@ -163,7 +163,7 @@ export async function permissionHeaderBlock(
`${username}, ${boardname}, ${userForBoardPermission}`,
ButtonStyle.PRIMARY
);


const denyPermissionButton = getButton(
"Deny",
Expand Down
58 changes: 40 additions & 18 deletions whiteboard/handlers/ExecuteBlockActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { PermissionModal } from '../modals/PermissionModal';
import { IMessage } from "@rocket.chat/apps-engine/definition/messages";
import { RocketChatAssociationModel, RocketChatAssociationRecord } from "@rocket.chat/apps-engine/definition/metadata";
import { EditModal } from "../modals/EditModal";
import { getAllBoardIds, getBoardName, getBoardRecord, getBoardRecordByRoomId } from '../persistence/boardInteraction';

// ExecuteBlockActionHandler is used to handle the block actions
export class ExecuteBlockActionHandler {
Expand All @@ -43,6 +44,15 @@ export class ExecuteBlockActionHandler {
container,
} = data;

console.log('DATA', data);

const persistenceReader = this.app.getAccessors().reader.getPersistenceReader();
const boardRecord = await getBoardRecordByRoomId(persistenceReader, room?.id)
const boardNames = await getBoardName(persistenceReader, room?.id);
const boardIds = await getAllBoardIds(persistenceReader);
console.log('BoardRecord: ', boardRecord);
this.app.getLogger().info('BoardIds: ', boardIds);

const read = this.read;
const appId = data.appId;
// The id of the message (created when the user created the whiteboard)
Expand All @@ -56,12 +66,24 @@ export class ExecuteBlockActionHandler {
boolean = await hasPermission(user, read, messageId)
}


let boardURL, interactionBoardName;
if (boolean) {
switch (actionId) {
case UtilityEnum.SETTINGS_BUTTON_ACTION_ID:
if (messageId) {
const modal = await SettingsModal(appId, messageId);
const settingsBoardData = this.context.getInteractionData().value;
boardURL = settingsBoardData?.split(",")[0].trim();
interactionBoardName = settingsBoardData?.split(",")[1].trim();
const boardId = boardURL.split('id=')[1];

const boardRecord = await getBoardRecord(persistenceReader, boardId);

if (messageId && interactionBoardName && boardRecord) {
const modal = await SettingsModal(
appId,
messageId,
interactionBoardName,
boardRecord.status
);
await Promise.all([
this.modify.getUiController().openSurfaceView(
modal,
Expand All @@ -78,7 +100,7 @@ export class ExecuteBlockActionHandler {

// Add the case for the delete button action
case UtilityEnum.DELETE_BUTTON_ACTION_ID:

if (messageId) {
const modal = await DeleteModal(appId, messageId);
await Promise.all([
Expand All @@ -95,18 +117,18 @@ export class ExecuteBlockActionHandler {
return this.context
.getInteractionResponder()
.successResponse();

case UtilityEnum.YES_ACTION_ID:
return this.context
.getInteractionResponder()
.successResponse();

case UtilityEnum.OPEN_BUTTON_ACTION_ID:
const boardData = this.context.getInteractionData().value
const boardURL = boardData?.split(",")[0].trim();
const interactionBoardName = boardData?.split(",")[1].trim();

boardURL = boardData?.split(",")[0].trim();
interactionBoardName = boardData?.split(",")[1].trim();

if (boardURL && messageId && interactionBoardName) {
const modal = await EditModal(appId, boardURL, messageId, interactionBoardName);
await Promise.all([
Expand All @@ -118,12 +140,12 @@ export class ExecuteBlockActionHandler {
user
),
]);

}
return this.context
.getInteractionResponder()
.successResponse();

case UtilityEnum.ALLOW_BUTTON_ACTION_ID:
const data = this.context.getInteractionData();
const userName = data.value?.split(",")[0].trim();
Expand All @@ -138,26 +160,26 @@ export class ExecuteBlockActionHandler {
if(room && userName && boardName && userForBoardPermission){
const userForBoardPermissionData = await addUsertoBoardOwner(this.read, room, this.persistence, userName.trim(), boardName, userForBoardPermission, "allow")
const boardOwnerData = await read.getUserReader().getByUsername(userName)
const message:IMessage = {text:`Permission granted for board ${boardName}`, room:room, sender: appSender}
const message:IMessage = {text:`Permission granted for board ${boardName}`, room:room, sender: appSender}
if(userForBoardPermissionData){
this.modify.getNotifier().notifyUser(userForBoardPermissionData, message)
}
else{
console.log("UserData", userForBoardPermissionData)
}

}

return this.context
.getInteractionResponder()
.successResponse();

case UtilityEnum.DENY_BUTTON_ACTION_ID:

if(room && userName && boardName && userForBoardPermission){
const userData = await addUsertoBoardOwner(this.read, room, this.persistence, userName.trim(), boardName.trim(), userForBoardPermission.trim(), "deny")
const message:IMessage = {text:"Permission denied", room:room, sender: appSender}

const message:IMessage = {text:"Permission denied", room:room, sender: appSender}
if(userData)
this.modify.getNotifier().notifyUser(userData, message)
else
Expand All @@ -179,7 +201,7 @@ export class ExecuteBlockActionHandler {
}
else {
if (messageId) {

const modal = await PermissionModal(appId, messageId);
await Promise.all([
this.modify.getUiController().openSurfaceView(
Expand Down
10 changes: 7 additions & 3 deletions whiteboard/modals/SettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {

export async function SettingsModal(
appId: string,
messageId: string
messageId: string,
boardName?: string,
boardStatus?: string,
): Promise<IUIKitSurfaceViewParam> {
const block: Block[] = [];

Expand All @@ -28,7 +30,8 @@ export async function SettingsModal(
UtilityEnum.BOARD_INPUT_PLACEHOLDER,
UtilityEnum.BOARD_INPUT_BLOCK_ID,
UtilityEnum.BOARD_INPUT_ACTION_ID,
appId
appId,
boardName,
);
block.push(boardInputBlock);

Expand All @@ -55,7 +58,8 @@ export async function SettingsModal(
options,
appId,
UtilityEnum.BOARD_SELECT_BLOCK_ID,
UtilityEnum.BOARD_SELECT_ACTION_ID
UtilityEnum.BOARD_SELECT_ACTION_ID,
boardStatus === "Public" ? UtilityEnum.PUBLIC : UtilityEnum.PRIVATE,
);

// Event handling for dropdown selection
Expand Down
4 changes: 2 additions & 2 deletions whiteboard/persistence/boardInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const storeBoardRecord = async (
// query all records within the "scope" - room
export const getBoardRecordByRoomId = async (
persistenceRead: IPersistenceRead,
roomId: string
roomId: string | undefined,
): Promise<any> => {
const association = new RocketChatAssociationRecord(
RocketChatAssociationModel.ROOM,
Expand Down Expand Up @@ -156,7 +156,7 @@ export const getAllBoardIds = async (
// function to get new board name
export const getBoardName = async (
persis: IPersistenceRead,
roomId: string
roomId: string | undefined,
): Promise<string> => {
const boardArray = await getBoardRecordByRoomId(persis, roomId);

Expand Down