Skip to content

Commit

Permalink
Merge branch 'develop' into temp-route-plan-lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
LianaHarris360 authored Oct 17, 2024
2 parents b9da77e + aa97a15 commit 1bff2ae
Show file tree
Hide file tree
Showing 39 changed files with 1,161 additions and 498 deletions.
89 changes: 44 additions & 45 deletions .github/workflows/add_contributor.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
name: Add new contributor to AUTHORS.md

on:
pull_request:
types: [opened]
pull_request_target:
types:
- closed

jobs:
check_contributor_exists:
update-authors:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

outputs:
is_contributor_in_file: ${{ steps.check_contributor_step.outputs.exists }}

steps:
- name: Checkout repository
- name: Checkout develop branch
uses: actions/checkout@v4
with:
sparse-checkout: .
ref: 'develop'
fetch-depth: 0
persist-credentials: false

- name: Check if contributor already exists
id: check_contributor_step
- name: Check if author is in AUTHORS.md
id: check-author
run: |
exists=$(grep -c -F "${{ github.event.pull_request.user.login }}" AUTHORS.md || true)
if [[ $exists -gt 0 ]]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
GH_USER="${{ github.event.pull_request.user.login }}"
# AUTHORS.md file already exist in repo, so can skip the conditional logic to create one if not exists
if ! grep -q "| ${GH_USER} |" AUTHORS.md; then
echo "new_author=true" >> $GITHUB_ENV
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "new_author=false" >> $GITHUB_ENV
fi
add_contributor:
runs-on: ubuntu-latest
needs: check_contributor_exists

if: needs.check_contributor_exists.outputs.is_contributor_in_file == 'false'

permissions:
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Git and checkout PR's branch
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git fetch origin refs/pull/${{ github.event.number }}/head:pr
git checkout pr
- name: Get contributor's full name and append to AUTHORS.md file
- name: Add author to AUTHORS.md if not present
if: env.new_author == 'true'
run: |
username=${{ github.event.pull_request.user.login }}
full_name=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/users/$username" | jq -r '.name')
if [[ "$full_name" == "" || "$full_name" == "null" ]]; then
full_name='-'
GH_USER="${{ github.event.pull_request.user.login }}"
AUTHOR_NAME=$(curl -s https://api.github.com/users/${GH_USER} | jq -r '.name')
if [ -z "$AUTHOR_NAME" ]; then
AUTHOR_NAME="-"
fi
echo "| $full_name | $username |" >> AUTHORS.md
echo "| $AUTHOR_NAME | $GH_USER |" >> AUTHORS.md
- name: Commit and push changes to the contributor's PR branch
- name: Commit updated AUTHORS.md
if: env.new_author == 'true'
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add AUTHORS.md
git commit -m "Add ${{ github.event.pull_request.user.login }} to AUTHORS.md"
git push origin pr:${{ github.event.pull_request.head.ref }}
- name: GitHub App token
if: env.new_author == 'true'
uses: tibdex/github-app-token@v2
id: generate-token
with:
app_id: ${{ secrets.LE_BOT_APP_ID }}
private_key: ${{ secrets.LE_BOT_PRIVATE_KEY }}

- name: Push changes to develop
if: env.new_author == 'true'
uses: ad-m/[email protected]
with:
github_token: ${{ steps.generate-token.outputs.token }}
branch: 'develop'
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ If you have contributed to Kolibri, feel free to add your name and Github accoun
| Mazen Oweiss | moweiss |
| Eshaan Aggarwal | EshaanAgg |
| Nikhil Sharma | ThEditor |
| - | BabyElias |
1 change: 0 additions & 1 deletion kolibri/core/assets/src/kolibri_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
44 changes: 0 additions & 44 deletions kolibri/core/assets/src/state/modules/core/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ import {
FacilityResource,
FacilityDatasetResource,
UserSyncStatusResource,
PingbackNotificationResource,
PingbackNotificationDismissedResource,
} from 'kolibri.resources';
import { setServerTime } from 'kolibri.utils.serverClock';
import urls from 'kolibri.urls';
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,
Expand All @@ -36,16 +32,6 @@ 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
*
Expand Down Expand Up @@ -179,36 +165,6 @@ 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 => {
store.commit('CORE_SET_FACILITIES', [...facilities]);
Expand Down
2 changes: 0 additions & 2 deletions kolibri/core/assets/src/views/InteractionList/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@

<script>
import responsiveElementMixin from 'kolibri-design-system/lib/KResponsiveElementMixin';
import InteractionItem from './InteractionItem';
export default {
name: 'InteractionList',
components: { InteractionItem },
mixins: [responsiveElementMixin],
props: {
interactions: {
type: Array,
Expand Down
2 changes: 0 additions & 2 deletions kolibri/core/assets/src/views/MultiPaneLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@
<script>
import useKResponsiveWindow from 'kolibri-design-system/lib/composables/useKResponsiveWindow';
import responsiveElementMixin from 'kolibri-design-system/lib/KResponsiveElementMixin';
export default {
name: 'MultiPaneLayout',
mixins: [responsiveElementMixin],
setup() {
const { windowHeight } = useKResponsiveWindow();
return {
Expand Down
61 changes: 59 additions & 2 deletions kolibri/core/assets/src/views/NotificationsRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
import { mapState } from 'vuex';
import Lockr from 'lockr';
import {
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';
Expand All @@ -63,11 +67,12 @@
UpdateNotification,
},
setup() {
const { isAdmin, isSuperuser } = useUser();
const { isAdmin, isSuperuser, user_id } = useUser();
return {
isAdmin,
isSuperuser,
user_id,
};
},
props: {
Expand Down Expand Up @@ -95,13 +100,13 @@
},
data() {
return {
notifications: [],
notificationModalShown: true,
};
},
computed: {
...mapState({
error: state => state.core.error,
notifications: state => state.core.notifications,
}),
notAuthorized() {
// catch "not authorized" error, display AuthMessage
Expand All @@ -127,6 +132,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];
Expand All @@ -147,16 +155,65 @@
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) {
try {
await PingbackNotificationDismissedResource.saveModel({
data: {
user: this.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);
} else {
this.saveDismissedNotification(this.mostRecentNotification.id);
}
},
dispatchError(error) {
this.$store.dispatch('handleApiError', { error });
},
removeNotification(notificationId) {
this.notifications = this.notifications.filter(n => n.id !== notificationId);
},
},
};
function _notificationListState(data) {
if (!data || data.length === 0) {
return [];
}
return data.map(notification => ({
id: notification.id,
version_range: notification.version_range,
timestamp: notification.timestamp,
link_url: notification.link_url,
i18n: notification.i18n,
}));
}
</script>


Expand Down
3 changes: 1 addition & 2 deletions kolibri/core/assets/src/views/SideNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import { UserKinds, NavComponentSections } from 'kolibri.coreVue.vuex.constants';
import useKResponsiveWindow from 'kolibri-design-system/lib/composables/useKResponsiveWindow';
import responsiveElementMixin from 'kolibri-design-system/lib/KResponsiveElementMixin';
import CoreMenu from 'kolibri.coreVue.components.CoreMenu';
import CoreMenuOption from 'kolibri.coreVue.components.CoreMenuOption';
import CoreLogo from 'kolibri.coreVue.components.CoreLogo';
Expand Down Expand Up @@ -299,7 +298,7 @@
LanguageSwitcherModal,
BottomNavigationBar,
},
mixins: [commonCoreStrings, responsiveElementMixin],
mixins: [commonCoreStrings],
setup() {
const { windowIsSmall, windowIsLarge } = useKResponsiveWindow();
const {
Expand Down
11 changes: 9 additions & 2 deletions kolibri/core/assets/src/views/SlotTruncator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@
<script>
import debounce from 'lodash/debounce';
import responsiveElementMixin from 'kolibri-design-system/lib/KResponsiveElementMixin';
import useKResponsiveElement from 'kolibri-design-system/lib/composables/useKResponsiveElement';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
export default {
name: 'SlotTruncator',
mixins: [commonCoreStrings, responsiveElementMixin],
mixins: [commonCoreStrings],
setup() {
const { elementWidth, elementHeight } = useKResponsiveElement();
return {
elementWidth,
elementHeight,
};
},
props: {
maxHeight: {
type: Number,
Expand Down
1 change: 0 additions & 1 deletion kolibri/core/assets/test/kolibri_app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ describe('KolibriApp', function () {
core: {
actions: {
getCurrentSession: jest.fn().mockResolvedValue(),
getNotifications: jest.fn().mockResolvedValue(),
},
},
},
Expand Down
Loading

0 comments on commit 1bff2ae

Please sign in to comment.