From 25af6e848dc0d6f536a4d08f17757d14de0dda0d Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Thu, 5 Sep 2024 05:17:53 +0530 Subject: [PATCH 01/15] issue #12626 --- .bas_hprofile | 0 .bash_profile | 0 .../assets/src/views/NotificationsRoot.vue | 275 ++++++++++-------- 3 files changed, 152 insertions(+), 123 deletions(-) create mode 100644 .bas_hprofile create mode 100644 .bash_profile diff --git a/.bas_hprofile b/.bas_hprofile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/.bash_profile b/.bash_profile new file mode 100644 index 00000000000..e69de29bb2d diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index 6cd1cbe415b..0a856dd6e8c 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -3,11 +3,8 @@
- + @@ -17,24 +14,15 @@ -
+
- +
@@ -42,120 +30,161 @@ From c0ea5655b3b3416c2b1679d2be826c88884abfd0 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Fri, 6 Sep 2024 00:28:14 +0530 Subject: [PATCH 02/15] removed vuex mutations --- kolibri/core/assets/src/kolibri_app.js | 1 - .../assets/src/state/modules/core/actions.js | 28 ------------------- kolibri/core/assets/test/kolibri_app.spec.js | 1 - 3 files changed, 30 deletions(-) diff --git a/kolibri/core/assets/src/kolibri_app.js b/kolibri/core/assets/src/kolibri_app.js index 70ec3c7eb17..1cb45ab1e65 100644 --- a/kolibri/core/assets/src/kolibri_app.js +++ b/kolibri/core/assets/src/kolibri_app.js @@ -104,7 +104,6 @@ export default class KolibriApp extends KolibriModule { ready() { this.setupVue(); return heartbeat.startPolling().then(() => { - this.store.dispatch('getNotifications'); return Promise.all([ // Invoke each of the state setters before initializing the app. ...this.stateSetters.map(setter => setter(this.store)), diff --git a/kolibri/core/assets/src/state/modules/core/actions.js b/kolibri/core/assets/src/state/modules/core/actions.js index e8588008173..c5aeeb74bb3 100644 --- a/kolibri/core/assets/src/state/modules/core/actions.js +++ b/kolibri/core/assets/src/state/modules/core/actions.js @@ -179,35 +179,7 @@ export function setPageVisibility(store) { _setPageVisibility(store, document.visibilityState === 'visible'); } -export function getNotifications(store) { - const { isAdmin, isSuperuser } = useUser(); - if (get(isAdmin) || get(isSuperuser)) { - return PingbackNotificationResource.fetchCollection() - .then(notifications => { - logging.info('Notifications set.'); - store.commit('CORE_SET_NOTIFICATIONS', _notificationListState(notifications)); - }) - .catch(error => { - store.dispatch('handleApiError', { error }); - }); - } - return Promise.resolve(); -} -export function saveDismissedNotification(store, notification_id) { - const { user_id } = useUser(); - const dismissedNotificationData = { - user: get(user_id), - notification: notification_id, - }; - return PingbackNotificationDismissedResource.saveModel({ data: dismissedNotificationData }) - .then(() => { - store.commit('CORE_REMOVE_NOTIFICATION', notification_id); - }) - .catch(error => { - store.dispatch('handleApiError', { error }); - }); -} export function getFacilities(store) { return FacilityResource.fetchCollection({ force: true }).then(facilities => { diff --git a/kolibri/core/assets/test/kolibri_app.spec.js b/kolibri/core/assets/test/kolibri_app.spec.js index 7bd1af62ec4..dcfad872703 100644 --- a/kolibri/core/assets/test/kolibri_app.spec.js +++ b/kolibri/core/assets/test/kolibri_app.spec.js @@ -58,7 +58,6 @@ describe('KolibriApp', function () { core: { actions: { getCurrentSession: jest.fn().mockResolvedValue(), - getNotifications: jest.fn().mockResolvedValue(), }, }, }, From 90113523576c04e585d54d41e8c8224e20dc3c14 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:08:36 +0000 Subject: [PATCH 03/15] [pre-commit.ci lite] apply automatic fixes --- .../assets/src/state/modules/core/actions.js | 2 - .../assets/src/views/NotificationsRoot.vue | 308 +++++++++--------- 2 files changed, 160 insertions(+), 150 deletions(-) diff --git a/kolibri/core/assets/src/state/modules/core/actions.js b/kolibri/core/assets/src/state/modules/core/actions.js index c5aeeb74bb3..c3c72fa05e2 100644 --- a/kolibri/core/assets/src/state/modules/core/actions.js +++ b/kolibri/core/assets/src/state/modules/core/actions.js @@ -179,8 +179,6 @@ export function setPageVisibility(store) { _setPageVisibility(store, document.visibilityState === 'visible'); } - - export function getFacilities(store) { return FacilityResource.fetchCollection({ force: true }).then(facilities => { store.commit('CORE_SET_FACILITIES', [...facilities]); diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index 0a856dd6e8c..b30b8720181 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -3,8 +3,11 @@
- + @@ -14,15 +17,24 @@ -
+
- +
@@ -30,161 +42,161 @@ From 939aab9049c2b9613906ca43754bbe28519d70de Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 7 Sep 2024 22:33:33 +0530 Subject: [PATCH 04/15] removed empty bashrc files --- .bas_hprofile | 0 .bash_profile | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .bas_hprofile delete mode 100644 .bash_profile diff --git a/.bas_hprofile b/.bas_hprofile deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/.bash_profile b/.bash_profile deleted file mode 100644 index e69de29bb2d..00000000000 From 07c14d4b801a998c94534f64e3fcb5c97e9e79e8 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sun, 15 Sep 2024 17:26:17 +0530 Subject: [PATCH 05/15] fixed import errors --- .../core/assets/src/state/modules/core/actions.js | 12 +----------- kolibri/core/assets/src/views/NotificationsRoot.vue | 7 +++++++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/kolibri/core/assets/src/state/modules/core/actions.js b/kolibri/core/assets/src/state/modules/core/actions.js index c3c72fa05e2..9de7c597303 100644 --- a/kolibri/core/assets/src/state/modules/core/actions.js +++ b/kolibri/core/assets/src/state/modules/core/actions.js @@ -6,8 +6,6 @@ import { FacilityResource, FacilityDatasetResource, UserSyncStatusResource, - PingbackNotificationResource, - PingbackNotificationDismissedResource, } from 'kolibri.resources'; import { setServerTime } from 'kolibri.utils.serverClock'; import urls from 'kolibri.urls'; @@ -36,15 +34,7 @@ const logging = logger.getLogger(__filename); * the API to state in the Vuex store */ -function _notificationListState(data) { - return data.map(notification => ({ - id: notification.id, - version_range: notification.version_range, - timestamp: notification.timestamp, - link_url: notification.link_url, - i18n: notification.i18n, - })); -} + /** * Actions diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index b30b8720181..9d6cda08af0 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -44,6 +44,13 @@ import { mapState } from 'vuex'; import Lockr from 'lockr'; + import { + FacilityResource, + FacilityDatasetResource, + UserSyncStatusResource, + PingbackNotificationResource, + PingbackNotificationDismissedResource, +} from 'kolibri.resources'; import { UPDATE_MODAL_DISMISSED } from 'kolibri.coreVue.vuex.constants'; import { currentLanguage, defaultLanguage } from 'kolibri.utils.i18n'; import AuthMessage from 'kolibri.coreVue.components.AuthMessage'; From d519363e1c3f81741cf68d441e330c54157fcf0e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 07:52:14 +0000 Subject: [PATCH 06/15] [pre-commit.ci lite] apply automatic fixes --- .../core/assets/src/state/modules/core/actions.js | 2 -- kolibri/core/assets/src/views/NotificationsRoot.vue | 12 ++++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/kolibri/core/assets/src/state/modules/core/actions.js b/kolibri/core/assets/src/state/modules/core/actions.js index 9de7c597303..eb7e8cbc755 100644 --- a/kolibri/core/assets/src/state/modules/core/actions.js +++ b/kolibri/core/assets/src/state/modules/core/actions.js @@ -34,8 +34,6 @@ const logging = logger.getLogger(__filename); * the API to state in the Vuex store */ - - /** * Actions * diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index 9d6cda08af0..1706eebc066 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -45,12 +45,12 @@ import { mapState } from 'vuex'; import Lockr from 'lockr'; import { - FacilityResource, - FacilityDatasetResource, - UserSyncStatusResource, - PingbackNotificationResource, - PingbackNotificationDismissedResource, -} from 'kolibri.resources'; + FacilityResource, + FacilityDatasetResource, + UserSyncStatusResource, + PingbackNotificationResource, + PingbackNotificationDismissedResource, + } from 'kolibri.resources'; import { UPDATE_MODAL_DISMISSED } from 'kolibri.coreVue.vuex.constants'; import { currentLanguage, defaultLanguage } from 'kolibri.utils.i18n'; import AuthMessage from 'kolibri.coreVue.components.AuthMessage'; From 1b474dcf7327ebfabf549a4dca9dd16a387879be Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Fri, 27 Sep 2024 19:53:13 +0530 Subject: [PATCH 07/15] fixed error handling --- .../assets/src/views/NotificationsRoot.vue | 56 ++----------------- 1 file changed, 4 insertions(+), 52 deletions(-) diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index 1706eebc066..6cd1cbe415b 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -44,13 +44,6 @@ import { mapState } from 'vuex'; import Lockr from 'lockr'; - import { - FacilityResource, - FacilityDatasetResource, - UserSyncStatusResource, - PingbackNotificationResource, - PingbackNotificationDismissedResource, - } from 'kolibri.resources'; import { UPDATE_MODAL_DISMISSED } from 'kolibri.coreVue.vuex.constants'; import { currentLanguage, defaultLanguage } from 'kolibri.utils.i18n'; import AuthMessage from 'kolibri.coreVue.components.AuthMessage'; @@ -102,11 +95,14 @@ }, data() { return { - notifications: [], notificationModalShown: true, }; }, computed: { + ...mapState({ + error: state => state.core.error, + notifications: state => state.core.notifications, + }), notAuthorized() { // catch "not authorized" error, display AuthMessage if ( @@ -151,60 +147,16 @@ return null; }, }, - created() { - this.getNotifications(); - }, methods: { - async getNotifications() { - const { isAdmin, isSuperuser } = useUser(); - if (isAdmin || isSuperuser) { - try { - const notifications = await PingbackNotificationResource.fetchCollection(); - this.notifications = _notificationListState(notifications); - } catch (error) { - this.dispatchError(error); - } - } - }, - async saveDismissedNotification(notificationId) { - const { user_id } = useUser(); - try { - await PingbackNotificationDismissedResource.saveModel({ - data: { - user: user_id, - notification: notificationId, - }, - }); - this.removeNotification(notificationId); - } catch (error) { - this.dispatchError(error); - } - }, dismissUpdateModal() { if (this.notifications.length === 0) { this.notificationModalShown = false; Lockr.set(UPDATE_MODAL_DISMISSED, true); } }, - dispatchError(error) { - this.$store.dispatch('handleApiError', { error }); - }, - removeNotification(notificationId) { - this.notifications = this.notifications.filter(n => n.id !== notificationId); - }, }, }; - function _notificationListState(data) { - return data.map(notification => ({ - id: notification.id, - version_range: notification.version_range, - timestamp: notification.timestamp, - link_url: notification.link_url, - i18n: notification.i18n, - })); - } - From 37960ba3ded3a0263ca26efcf5f113703d71870b Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 28 Sep 2024 01:08:18 +0530 Subject: [PATCH 08/15] fixed errors --- .../assets/src/views/NotificationsRoot.vue | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index 6cd1cbe415b..b826ce71dbb 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -1,5 +1,4 @@ - - From 37fdf0842b8769821820d2ea1f6bffacea34b013 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 28 Sep 2024 01:09:40 +0530 Subject: [PATCH 09/15] fixed errors --- kolibri/core/assets/src/views/NotificationsRoot.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index b826ce71dbb..794ea770393 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -40,6 +40,13 @@ + From 6ce4a0bbdb96132b82c2be13da6a4f9299e4983c Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 28 Sep 2024 04:02:55 +0530 Subject: [PATCH 12/15] fixed notifications data undefining issue --- kolibri/core/assets/src/views/NotificationsRoot.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index ad7e38bf6fa..f976cfcf8d7 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -134,6 +134,9 @@ return false; }, mostRecentNotification() { + if (this.notifications.length === 0) { + return null; + } let languageCode = defaultLanguage.id; // notifications should already be ordered by timestamp const notification = this.notifications[0]; @@ -199,6 +202,9 @@ }; function _notificationListState(data) { + if (!data || data.length === 0) { + return []; + } return data.map(notification => ({ id: notification.id, version_range: notification.version_range, From 9b0b03a5950a7e2d8fc85f1e72880fdfceab23fb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Sat, 28 Sep 2024 03:59:49 +0000 Subject: [PATCH 13/15] [pre-commit.ci lite] apply automatic fixes --- kolibri/core/assets/src/views/NotificationsRoot.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index f976cfcf8d7..68a0804909f 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -135,8 +135,8 @@ }, mostRecentNotification() { if (this.notifications.length === 0) { - return null; - } + return null; + } let languageCode = defaultLanguage.id; // notifications should already be ordered by timestamp const notification = this.notifications[0]; @@ -203,8 +203,8 @@ function _notificationListState(data) { if (!data || data.length === 0) { - return []; - } + return []; + } return data.map(notification => ({ id: notification.id, version_range: notification.version_range, From d9e03fb2a07fdd9e90c4d20e1ffddb9183b67d2c Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Wed, 9 Oct 2024 00:36:09 +0530 Subject: [PATCH 14/15] updated notificationsRoot.spec.js test file as per the changes made in its component file --- .../assets/src/state/modules/core/actions.js | 2 -- .../assets/src/views/NotificationsRoot.vue | 18 +++++++----------- .../test/views/NotificationsRoot.spec.js | 5 +++-- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/kolibri/core/assets/src/state/modules/core/actions.js b/kolibri/core/assets/src/state/modules/core/actions.js index fbaba715e16..c9007dbb8ad 100644 --- a/kolibri/core/assets/src/state/modules/core/actions.js +++ b/kolibri/core/assets/src/state/modules/core/actions.js @@ -14,8 +14,6 @@ import redirectBrowser from 'kolibri.utils.redirectBrowser'; import CatchErrors from 'kolibri.utils.CatchErrors'; import Vue from 'kolibri.lib.vue'; import Lockr from 'lockr'; -import { get } from '@vueuse/core'; -import useUser from 'kolibri.coreVue.composables.useUser'; import { DisconnectionErrorCodes, LoginErrors, diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index 68a0804909f..487d9105e04 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -1,5 +1,4 @@ - - diff --git a/kolibri/core/assets/test/views/NotificationsRoot.spec.js b/kolibri/core/assets/test/views/NotificationsRoot.spec.js index 92aed531b73..d554e0e6bbc 100644 --- a/kolibri/core/assets/test/views/NotificationsRoot.spec.js +++ b/kolibri/core/assets/test/views/NotificationsRoot.spec.js @@ -6,6 +6,7 @@ import { coreStoreFactory as makeStore } from '../../src/state/store'; import coreModule from '../../src/state/modules/core'; jest.mock('kolibri.coreVue.composables.useUser'); +jest.mock('kolibri.resources'); function makeWrapper(useUserMockObj = null) { const store = makeStore(); @@ -72,7 +73,7 @@ describe('NotificationsRoot', function () { it('notification modal should be rendered if the user is an admin/superuser, a notification exists, and there is a recent notification', async () => { const { wrapper, store } = makeWrapper({ isAdmin: true, isSuperuser: true }); store.state.core.loading = false; - store.state.core.notifications = [ + wrapper.vm.notifications = [ { id: 2, title: 'title', @@ -90,7 +91,7 @@ describe('NotificationsRoot', function () { const { wrapper, store } = makeWrapper(); store.commit('CORE_SET_SESSION', { kind: [UserKinds.ADMIN] }); store.state.core.loading = false; - store.state.core.notifications = []; + wrapper.vm.notifications = []; await wrapper.vm.$nextTick(); expect(wrapper.findComponent({ name: 'UpdateNotification' }).exists()).toBeFalsy(); From 094e8e7af02f31d0c0c961549f34adc784646472 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Wed, 9 Oct 2024 00:49:12 +0530 Subject: [PATCH 15/15] updated notificationsRoot.spec.js test file as per the changes made in its component file --- kolibri/core/assets/src/views/NotificationsRoot.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kolibri/core/assets/src/views/NotificationsRoot.vue b/kolibri/core/assets/src/views/NotificationsRoot.vue index 487d9105e04..2f3adabd88a 100644 --- a/kolibri/core/assets/src/views/NotificationsRoot.vue +++ b/kolibri/core/assets/src/views/NotificationsRoot.vue @@ -1,4 +1,5 @@ + +