From e2c15feb2b8dc9cd22a09d6f110e61c687b78df7 Mon Sep 17 00:00:00 2001 From: Farhaan Bukhsh Date: Fri, 13 Dec 2024 03:08:36 +0530 Subject: [PATCH 1/8] feat: Adding human readable 403 error access restricted Signed-off-by: Farhaan Bukhsh --- src/course-outline/page-alerts/PageAlerts.jsx | 14 +++++++++++--- src/course-outline/page-alerts/messages.js | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/course-outline/page-alerts/PageAlerts.jsx b/src/course-outline/page-alerts/PageAlerts.jsx index 4b12996395..dc8822f0c0 100644 --- a/src/course-outline/page-alerts/PageAlerts.jsx +++ b/src/course-outline/page-alerts/PageAlerts.jsx @@ -344,10 +344,18 @@ const PageAlerts = ({ let errorList = Object.entries(errors).filter(obj => obj[1] !== null).map(([k, v]) => { switch (v.type) { case API_ERROR_TYPES.serverError: + let description = v.data || intl.formatMessage(messages.serverErrorAlertBody); + let alertTitle = intl.formatMessage(messages.serverErrorAlert); + if (v.status === 403) { + description = intl.formatMessage(messages.forbiddenAlertBody, { + LMS: {intl.formatMessage(messages.forbiddenAlertLmsUrl)} + }); + alertTitle = intl.formatMessage(messages.forbiddenAlert); + } return { key: k, - desc: v.data || intl.formatMessage(messages.serverErrorAlertBody), - title: intl.formatMessage(messages.serverErrorAlert), + desc: description, + title: alertTitle, dismissible: v.dismissible, }; case API_ERROR_TYPES.networkError: @@ -378,7 +386,7 @@ const PageAlerts = ({ dismissError={() => dispatch(dismissError(msgObj.key))} > {msgObj.title} - {msgObj.desc && {msgObj.desc}} + {msgObj.desc} ) : ( Date: Fri, 13 Dec 2024 23:21:58 +0530 Subject: [PATCH 2/8] fixup! feat: Adding human readable 403 error access restricted --- src/course-outline/page-alerts/PageAlerts.jsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/course-outline/page-alerts/PageAlerts.jsx b/src/course-outline/page-alerts/PageAlerts.jsx index dc8822f0c0..bed95754f2 100644 --- a/src/course-outline/page-alerts/PageAlerts.jsx +++ b/src/course-outline/page-alerts/PageAlerts.jsx @@ -343,12 +343,20 @@ const PageAlerts = ({ const renderApiErrors = () => { let errorList = Object.entries(errors).filter(obj => obj[1] !== null).map(([k, v]) => { switch (v.type) { - case API_ERROR_TYPES.serverError: + case API_ERROR_TYPES.serverError: { let description = v.data || intl.formatMessage(messages.serverErrorAlertBody); let alertTitle = intl.formatMessage(messages.serverErrorAlert); if (v.status === 403) { description = intl.formatMessage(messages.forbiddenAlertBody, { - LMS: {intl.formatMessage(messages.forbiddenAlertLmsUrl)} + LMS: ( + + {intl.formatMessage(messages.forbiddenAlertLmsUrl)} + + ), }); alertTitle = intl.formatMessage(messages.forbiddenAlert); } @@ -358,6 +366,7 @@ const PageAlerts = ({ title: alertTitle, dismissible: v.dismissible, }; + } case API_ERROR_TYPES.networkError: return { key: k, @@ -386,7 +395,8 @@ const PageAlerts = ({ dismissError={() => dispatch(dismissError(msgObj.key))} > {msgObj.title} - {msgObj.desc} + {(typeof msgObj.desc === 'object') + ? msgObj.desc : {msgObj.desc}} ) : ( Date: Sun, 15 Dec 2024 19:35:25 +0530 Subject: [PATCH 3/8] fixup! feat: Adding human readable 403 error access restricted --- src/course-outline/page-alerts/PageAlerts.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/course-outline/page-alerts/PageAlerts.jsx b/src/course-outline/page-alerts/PageAlerts.jsx index bed95754f2..7dc50010a2 100644 --- a/src/course-outline/page-alerts/PageAlerts.jsx +++ b/src/course-outline/page-alerts/PageAlerts.jsx @@ -395,8 +395,8 @@ const PageAlerts = ({ dismissError={() => dispatch(dismissError(msgObj.key))} > {msgObj.title} - {(typeof msgObj.desc === 'object') - ? msgObj.desc : {msgObj.desc}} + {(typeof msgObj.desc === 'string') + ? {msgObj.desc} : msgObj.desc} ) : ( Date: Sun, 15 Dec 2024 20:03:19 +0530 Subject: [PATCH 4/8] fixup! feat: Adding human readable 403 error access restricted --- src/course-outline/page-alerts/PageAlerts.test.jsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/course-outline/page-alerts/PageAlerts.test.jsx b/src/course-outline/page-alerts/PageAlerts.test.jsx index 6d646f7cb4..9dab8aa913 100644 --- a/src/course-outline/page-alerts/PageAlerts.test.jsx +++ b/src/course-outline/page-alerts/PageAlerts.test.jsx @@ -218,4 +218,15 @@ describe('', () => { expect(queryByText('some error')).toBeInTheDocument(); expect(queryByText('some unknown error')).toBeInTheDocument(); }); + + it('renders forbidden api error alerts', async () => { + const { queryByText } = renderComponent({ + ...pageAlertsData, + errors: { + outlineIndexApi: { data: 'some error', status: 403, type: API_ERROR_TYPES.serverError }, + }, + }); + expect(queryByText(messages.forbiddenAlert.defaultMessage)).toBeInTheDocument(); + expect(queryByText(messages.forbiddenAlertBody.defaultMessage)).toBeInTheDocument(); + }); }); From c4627557c18570bd0b6c8d7c589668c2b2608cb3 Mon Sep 17 00:00:00 2001 From: Farhaan Bukhsh Date: Sun, 15 Dec 2024 22:59:16 +0530 Subject: [PATCH 5/8] fixup! feat: Adding human readable 403 error access restricted --- src/course-outline/page-alerts/PageAlerts.test.jsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/course-outline/page-alerts/PageAlerts.test.jsx b/src/course-outline/page-alerts/PageAlerts.test.jsx index 9dab8aa913..b8bb04821c 100644 --- a/src/course-outline/page-alerts/PageAlerts.test.jsx +++ b/src/course-outline/page-alerts/PageAlerts.test.jsx @@ -229,4 +229,14 @@ describe('', () => { expect(queryByText(messages.forbiddenAlert.defaultMessage)).toBeInTheDocument(); expect(queryByText(messages.forbiddenAlertBody.defaultMessage)).toBeInTheDocument(); }); + +it('renders api error alerts when status is not 403', async () => { + const { queryByText } = renderComponent({ + ...pageAlertsData, + errors: { + outlineIndexApi: { data: 'some error', status: 500, type: API_ERROR_TYPES.serverError }, + }, + }); + expect(queryByText('some error')).toBeInTheDocument(); + }); }); From 56bf190b060a4a2e691e32fbbd176afd7253913b Mon Sep 17 00:00:00 2001 From: Farhaan Bukhsh Date: Sun, 15 Dec 2024 23:03:43 +0530 Subject: [PATCH 6/8] fixup! feat: Adding human readable 403 error access restricted --- .../page-alerts/PageAlerts.test.jsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/course-outline/page-alerts/PageAlerts.test.jsx b/src/course-outline/page-alerts/PageAlerts.test.jsx index b8bb04821c..69f80ac5a7 100644 --- a/src/course-outline/page-alerts/PageAlerts.test.jsx +++ b/src/course-outline/page-alerts/PageAlerts.test.jsx @@ -230,13 +230,13 @@ describe('', () => { expect(queryByText(messages.forbiddenAlertBody.defaultMessage)).toBeInTheDocument(); }); -it('renders api error alerts when status is not 403', async () => { - const { queryByText } = renderComponent({ - ...pageAlertsData, - errors: { - outlineIndexApi: { data: 'some error', status: 500, type: API_ERROR_TYPES.serverError }, - }, + it('renders api error alerts when status is not 403', async () => { + const { queryByText } = renderComponent({ + ...pageAlertsData, + errors: { + outlineIndexApi: { data: 'some error', status: 500, type: API_ERROR_TYPES.serverError }, + }, + }); + expect(queryByText('some error')).toBeInTheDocument(); }); - expect(queryByText('some error')).toBeInTheDocument(); - }); }); From 84a883cd125c6c549d8695173ff9b7e68be9f91f Mon Sep 17 00:00:00 2001 From: Farhaan Bukhsh Date: Sun, 15 Dec 2024 23:10:35 +0530 Subject: [PATCH 7/8] fixup! feat: Adding human readable 403 error access restricted --- src/course-outline/page-alerts/PageAlerts.test.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/course-outline/page-alerts/PageAlerts.test.jsx b/src/course-outline/page-alerts/PageAlerts.test.jsx index 69f80ac5a7..fc30c8108c 100644 --- a/src/course-outline/page-alerts/PageAlerts.test.jsx +++ b/src/course-outline/page-alerts/PageAlerts.test.jsx @@ -231,12 +231,12 @@ describe('', () => { }); it('renders api error alerts when status is not 403', async () => { - const { queryByText } = renderComponent({ - ...pageAlertsData, - errors: { - outlineIndexApi: { data: 'some error', status: 500, type: API_ERROR_TYPES.serverError }, - }, - }); - expect(queryByText('some error')).toBeInTheDocument(); + const { queryByText } = renderComponent({ + ...pageAlertsData, + errors: { + outlineIndexApi: { data: 'some error', status: 500, type: API_ERROR_TYPES.serverError }, + }, }); + expect(queryByText('some error')).toBeInTheDocument(); + }); }); From 5f4f2574992a8ff27cf19187313986078fb24cc1 Mon Sep 17 00:00:00 2001 From: Farhaan Bukhsh Date: Mon, 16 Dec 2024 16:38:33 +0530 Subject: [PATCH 8/8] fixup! feat: Adding human readable 403 error access restricted --- src/course-outline/page-alerts/PageAlerts.test.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/course-outline/page-alerts/PageAlerts.test.jsx b/src/course-outline/page-alerts/PageAlerts.test.jsx index fc30c8108c..c68d2b84d3 100644 --- a/src/course-outline/page-alerts/PageAlerts.test.jsx +++ b/src/course-outline/page-alerts/PageAlerts.test.jsx @@ -223,7 +223,7 @@ describe('', () => { const { queryByText } = renderComponent({ ...pageAlertsData, errors: { - outlineIndexApi: { data: 'some error', status: 403, type: API_ERROR_TYPES.serverError }, + outlineIndexApi: { data: 'some error', status: 403, type: API_ERROR_TYPES.serverError, dismissable: true }, }, }); expect(queryByText(messages.forbiddenAlert.defaultMessage)).toBeInTheDocument(); @@ -234,7 +234,7 @@ describe('', () => { const { queryByText } = renderComponent({ ...pageAlertsData, errors: { - outlineIndexApi: { data: 'some error', status: 500, type: API_ERROR_TYPES.serverError }, + outlineIndexApi: { data: 'some error', status: 500, type: API_ERROR_TYPES.serverError, dismissable: true }, }, }); expect(queryByText('some error')).toBeInTheDocument();