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; } 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) { 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",