Skip to content

Commit

Permalink
Optimize LTI checks and show proper Warning message if failed
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrahn committed Oct 20, 2023
1 parent 2f1613a commit 06d1ab5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 32 deletions.
61 changes: 41 additions & 20 deletions vueapp/components/Videos/VideosTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ export default {
'playlist',
'course_config',
'isLTIAuthenticated',
'simple_config_list'
'simple_config_list',
'errors'
]),
numberOfColumns() {
Expand Down Expand Up @@ -485,6 +486,44 @@ export default {
getPlaylistLink(token) {
return window.STUDIP.URLHelper.getURL('plugins.php/opencast/contents/index#/contents/playlists/' + token + '/edit', {}, ['cid'])
},
checkLTIPeriodically() {
let view = this;
this.$store.dispatch('simpleConfigListRead').then(() => {
const error_msg = this.$gettext('Es ist ein Verbindungsfehler zum Opencast Server aufgetreten. Einige Aktionen könnten nicht richtig funktionieren.');
const server_ids = Object.keys(view.simple_config_list['server']);
// periodically check, if lti is authenticated
view.interval = setInterval(async () => {
// Create an array of promises for checking each server in parallel
const promises = server_ids.map(async (id) => {
await view.$store.dispatch('checkLTIAuthentication', view.simple_config_list['server'][id]);
// Remove server from list, if authenticated
if (view.isLTIAuthenticated[id]) {
server_ids.splice(server_ids.indexOf(id), 1);
}
});
// Wait for all checks to finish
await Promise.all(promises);
if (server_ids.length === 0) {
view.$store.dispatch('errorRemove', error_msg);
clearInterval(view.interval);
} else {
if (!view.errors.find((e) => e === error_msg)) {
view.$store.dispatch('errorCommit', error_msg);
}
}
view.interval_counter++;
if (view.interval_counter > 10) {
clearInterval(view.interval);
}
}, 2000);
});
}
},
async mounted() {
Expand All @@ -511,25 +550,7 @@ export default {
}
})
// periodically check, if lti is authenticated
let view = this;
this.$store.dispatch('simpleConfigListRead').then(() => {
view.interval = setInterval(() => {
for (let id in view.simple_config_list['server']) {
if (!view.isLTIAuthenticated[id]) {
view.$store.dispatch('checkLTIAuthentication', view.simple_config_list['server'][id]);
}
}
view.interval_counter++;
// prevent spamming of oc server
if (view.interval_counter > 10) {
clearInterval(view.interval);
}
}, 2000);
});
this.checkLTIPeriodically();
},
watch: {
Expand Down
11 changes: 11 additions & 0 deletions vueapp/store/error.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const actions = {
context.commit('errorsAdd', error);
},

errorRemove(context, error) {
context.commit('errorsRemove', error);
},

errorClear(context) {
context.commit('errorsClear');
}
Expand All @@ -23,6 +27,13 @@ const mutations = {
state.errors.push(data);
},

errorsRemove(state, data) {
let idx = state.errors.indexOf(data);
if (idx !== -1) {
state.errors.splice(idx, 1);
}
},

errorsClear(state) {
state.errors = [];
}
Expand Down
31 changes: 19 additions & 12 deletions vueapp/store/opencast.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,20 @@ const actions = {
return ApiService.put('courses/' + data.cid + '/upload/' + data.upload);
},

checkLTIAuthentication({ commit }, server)
async checkLTIAuthentication({ commit }, server)
{
axios({
method: 'GET',
url: server.name + "/lti/info.json",
crossDomain: true,
withCredentials: true,
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
}).then((response) => {
if (response.status == 200) {
try {
const response = await axios({
method: 'GET',
url: server.name + "/lti/info.json",
crossDomain: true,
withCredentials: true,
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
});

if (response.status === 200) {
commit('setLTIStatus', {
server: server.id,
authenticated: true
Expand All @@ -155,7 +157,12 @@ const actions = {
authenticated: false
});
}
});
} catch (error) {
commit('setLTIStatus', {
server: server.id,
authenticated: false
});
}
}
}

Expand Down

0 comments on commit 06d1ab5

Please sign in to comment.