From 75f724a53635284ccfd4984038c2748887933b75 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 29 Aug 2024 19:30:43 -0300 Subject: [PATCH 1/3] Improve loginToImport message --- src/components/Board/Board.messages.js | 2 +- src/translations/src/cboard.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Board/Board.messages.js b/src/components/Board/Board.messages.js index 3d35d2390..dbd573bce 100644 --- a/src/components/Board/Board.messages.js +++ b/src/components/Board/Board.messages.js @@ -231,6 +231,6 @@ export default defineMessages({ loginToImport: { id: 'cboard.components.Board.loginToImport', defaultMessage: - 'In order to import a CBuilder board you have to be logged in.' + 'To import a CBuilder board, you must be logged in with the same account that was used to create the board.' } }); diff --git a/src/translations/src/cboard.json b/src/translations/src/cboard.json index d672202dc..faa33a10f 100644 --- a/src/translations/src/cboard.json +++ b/src/translations/src/cboard.json @@ -171,7 +171,7 @@ "cboard.components.Board.writeAndSay": "Write and say", "cboard.components.Board.importCbuilderBoardTitle": "Import CBuilder Board", "cboard.components.Board.importCbuilderBoardDesc": "You are trying to import a CBuilder board. In order to use and edit this board you have to copy it into your communicator boards.", - "cboard.components.Board.loginToImport": "In order to import a CBuilder board you have to be logged in.", + "cboard.components.Board.loginToImport": "To import a CBuilder board, you must be logged in with the same account that was used to create the board.", "cboard.components.Board.ImageEditor.title": "Image editor", "cboard.components.Board.ImageEditor.rotateRight": "Rotate right", "cboard.components.Board.ImageEditor.cropImage": "Crop image", From 0f107d9150a4416711e7bb518a815fec504e4ee6 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 29 Aug 2024 19:32:35 -0300 Subject: [PATCH 2/3] Refactor API method to fetch Cbuilder board data with authentication --- src/api/api.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/api/api.js b/src/api/api.js index 0db33d1be..152c52003 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -286,8 +286,19 @@ class API { return data; } - async getTemporaryBoard(id) { - const { data } = await this.axiosInstance.get(`/board/temporary/${id}`); + async getCbuilderBoard(id) { + const authToken = getAuthToken(); + if (!(authToken && authToken.length)) { + throw new Error('Need to be authenticated to perform this request', { + cause: 401 + }); + } + const headers = { + Authorization: `Bearer ${authToken}` + }; + const { data } = await this.axiosInstance.get(`/board/cbuilder/${id}`, { + headers + }); return data; } From 043c79f1140050e8a23663299fdabbd77f4444b1 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 29 Aug 2024 19:34:17 -0300 Subject: [PATCH 3/3] Refactor tryRemoteBoard to use the getCbuilderBoard and handle erros --- src/components/Board/Board.container.js | 53 +++++++++++++++---------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 2a89809be..7eaf8f3da 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -382,33 +382,42 @@ export class BoardContainer extends Component { const queryParams = new URLSearchParams(location.search); const isCbuilderBoard = queryParams.get('cbuilder'); - - const remoteBoard = isCbuilderBoard - ? await API.getTemporaryBoard(boardId) - : await API.getBoard(boardId); - this.setState({ isCbuilderBoard }); - //if requested board is from the user just add it - if ( - 'name' in userData && - 'email' in userData && - remoteBoard.email === userData.email && - remoteBoard.author === userData.name - ) { - if (isCbuilderBoard) { - this.setState({ copyPublicBoard: remoteBoard }); + + try { + const remoteBoard = isCbuilderBoard + ? await API.getCbuilderBoard(boardId) + : await API.getBoard(boardId); + + //if requested board is from the user just add it + if ( + 'name' in userData && + 'email' in userData && + remoteBoard.email === userData.email && + remoteBoard.author === userData.name + ) { + if (isCbuilderBoard) { + this.setState({ copyPublicBoard: remoteBoard }); + return null; + } + return remoteBoard; + } else { + //if requested board is public, ask about copy it + if (remoteBoard.isPublic) { + this.setState({ copyPublicBoard: remoteBoard }); + } else { + this.setState({ blockedPrivateBoard: true }); + } return null; } - return remoteBoard; - } else { - //if requested board is public, ask about copy it - if (remoteBoard.isPublic) { - this.setState({ copyPublicBoard: remoteBoard }); - } else { + } catch (err) { + if ( + isCbuilderBoard && + (err?.response?.status === 401 || err?.cause === 401) + ) this.setState({ blockedPrivateBoard: true }); - } + throw new Error('Cannot get the remote board'); } - return null; } translateBoard(board) {