Skip to content

Commit

Permalink
Error handling on ServerCards (#829)
Browse files Browse the repository at this point in the history
* catch cUrl error code 6

* check lti and show message after server configuration

* Show failure icon on ServerCard and show error message

* Show default workflow config after server creation + bug fixes

* Fix propper LTIAuthentication like in PR 826
  • Loading branch information
ssrahn authored Nov 6, 2023
1 parent 40c0583 commit 9cadc92
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 59 deletions.
5 changes: 5 additions & 0 deletions assets/css/opencast.scss
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,11 @@ h2.oc--loadingbar, .oc--loadingbar-title {
text-align: right;
margin-right: 10px;
}

.oc--admin--server-icons {
float: left;
margin-top: 8px;
}
}

.oc--admin--server-data {
Expand Down
29 changes: 19 additions & 10 deletions lib/Models/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,32 @@ public function updateEndpoints($container)
$comp = $services_client->getRESTComponents();
}
catch(\Exception $e) {
return [
'type' => 'error',
'text' => sprintf(
_('%s'),
$e->getMessage()
)
];
if (str_starts_with($e->getMessage(), 'cURL error 6')) {
return [
'type' => 'error',
'text' => sprintf(
_('Die angegebene URL %s konnte nicht gefunden werden. Überprüfen Sie bitte ihre Eingabe und versuchen Sie es erneut.'),
$service_host
)
];
}
else {
return [
'type' => 'error',
'text' => sprintf(
_('%s'),
$e->getMessage()
)
];
}
}
} catch (AccessDeniedException $e) {
Endpoints::removeEndpoint($this->id, 'services');

$message = [
'type' => 'error',
'text' => sprintf(
_('Fehlerhafte Zugangsdaten für die Opencast Installation mit der URL "%s". Überprüfen Sie bitte die eingebenen Daten.'),
_('Fehlerhafte Zugangsdaten für die Opencast Installation mit der URL "%s". Überprüfen Sie bitte die eingegebenen Daten.'),
$service_host
)
];
Expand Down Expand Up @@ -252,8 +263,6 @@ public function updateEndpoints($container)
'type' => 'success',
'text' => implode('<br>', $success_message)
];

$config_checked = true;
}
} else {
$message = [
Expand Down
3 changes: 1 addition & 2 deletions lib/Routes/Config/ConfigAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function __invoke(Request $request, Response $response, $args)

$json = $this->getRequestData($request);

$config_checked = false;
$duplicate_url = false;

// check, if a config with the same data already exists:
Expand Down Expand Up @@ -68,7 +67,7 @@ public function __invoke(Request $request, Response $response, $args)
$ret_config = array_merge($ret_config, $ret_config['settings']);
unset($ret_config['settings']);

if ($config_checked) {
if ($message['type'] == 'success') {
$lti = LtiHelper::getLaunchData($config->id);

return $this->createResponse([
Expand Down
3 changes: 1 addition & 2 deletions lib/Routes/Config/ConfigEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function __invoke(Request $request, Response $response, $args)

$json = $this->getRequestData($request);

$config_checked = false;
$duplicate_url = false;

$config = Config::find($args['id']);
Expand All @@ -49,7 +48,7 @@ public function __invoke(Request $request, Response $response, $args)
$ret_config = array_merge($ret_config, $ret_config['settings']);
unset($ret_config['settings']);

if ($config_checked) {
if ($message['type'] == 'success') {
$lti = LtiHelper::getLaunchData($config->id);

return $this->createResponse([
Expand Down
118 changes: 80 additions & 38 deletions vueapp/components/Config/EditServer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
@updateValue="updateValue" />
</fieldset>
<WorkflowOptions v-if="id != 'new'"/>
<WorkflowOptions :disabled="currentId === 'new'" ref="workflow-form"/>
</form>
<MessageList :float="true"/>
<Error :float="true"/>
</template>
<template v-slot:dialogButtons>
<button v-if="config !== null"
<button v-if="currentId !== 'new'"
class="button trash"
type="button"
@click="deleteConfig"
Expand Down Expand Up @@ -86,7 +86,8 @@ export default {
data() {
return {
currentConfig: {},
disabled: false
disabled: false,
newId: null
}
},
Expand All @@ -96,6 +97,10 @@ export default {
simple_config_list: 'simple_config_list'
}),
currentId() {
return this.newId ? this.newId : this.id;
},
settings() {
return [
{
Expand Down Expand Up @@ -171,7 +176,7 @@ export default {
this.currentConfig.checked = false;
if (this.id == 'new') {
if (this.currentId == 'new') {
this.$store.dispatch('configCreate', this.currentConfig)
.then(({ data }) => {
this.disabled = false;
Expand All @@ -193,10 +198,10 @@ export default {
deleteConfig() {
if (confirm(this.$gettext('Sind Sie sicher, dass Sie die Serverkonfiguration löschen möchten? Die damit verbundenen Videos werden danach nicht mehr in Stud.IP zur Verfügung stehen!'))) {
if (this.id == 'new') {
if (this.currentId == 'new') {
this.currentConfig = {}
} else {
this.$store.dispatch('configDelete', this.id)
this.$store.dispatch('configDelete', this.currentId)
.then(() => {
this.$store.dispatch('configListRead');
this.$store.dispatch('addMessage', {
Expand All @@ -212,43 +217,88 @@ export default {
},
checkConfigResponse(data) {
if (data.lti !== undefined) {
this.checkLti(data.lti);
}
if (data.message !== undefined) {
this.$store.dispatch('addMessage', {
type: data.message.type,
text: data.message.text
});
if (data.message.type === 'error') {
this.$store.dispatch('addMessage', {
type: data.message.type,
text: data.message.text
});
return;
}
else if (data.message.type === 'success') {
// Check if LTI connection is available
let lti_checked = false;
this.checkLti(data.lti).then((result) => {
lti_checked = result;
});
if (this.currentId !== 'new') {
// Just show success message if server was edited
this.$store.dispatch('addMessage', {
type: data.message.type,
text: data.message.text
});
}
else {
// On create, scroll to the default workflow configuration
this.$store.dispatch('addMessage', {
type: data.message.type,
text: data.message.text + ' Sie können nun die Standardworkflows einstellen oder die Konfiguration abschließen.'
});
this.newId = data.config.id;
this.$store.dispatch('simpleConfigListRead');
if(data.message.type == 'success'){
this.$emit('close');
let view = this;
// We need to wait for a short time so the component is actually visible
setTimeout(() => {
view.$refs['workflow-form'].$el.scrollIntoView({
behavior: 'smooth'
});
}, 10);
}
if (!lti_checked) {
// Show LTI error
this.postLtiCheckFailedMessage();
}
else if (this.currentId !== 'new') {
// Only close dialog, if lti successfull and no new server was created
this.$emit('close');
}
return;
}
}
this.$store.dispatch('addMessage', {
type: 'error',
text: this.$gettext('Bei der Konfiguration ist ein Fehler aufgetreten. Versuchen Sie es bitte erneut.')
});
},
async checkLti(data)
{
let view = this;
await this.$store.dispatch('authenticateLti');
// make an lti call to make sure it worked, there are some caveats though...
// - already succesful calls will not be revoked
// - unsuccesful calls will persist even if it worked now
axios({
url: data[0].launch_url,
method: "GET",
withCredentials: true,
}).then(({ data }) => {
if (data.user_id == undefined) {
view.postLtiCheckFailedMessage();
try {
const response = await axios({
url: data[0].launch_url,
method: "GET",
withCredentials: true,
});
if (response.user_id == undefined) {
return false;
} else {
view.postLtiCheckSucceededMessage();
return true;
}
}).catch(function (error) {
view.postLtiCheckFailedMessage();
});
} catch (error) {
return false;
}
},
postLtiCheckFailedMessage()
Expand All @@ -264,14 +314,6 @@ export default {
});
},
postLtiCheckSucceededMessage()
{
this.$store.dispatch('addMessage', {
type: 'success',
text: this.$gettext('Die LTI-Konfiguration wurde erfolgreich überprüft!')
});
},
updateValue(setting, newValue) {
this.currentConfig[setting.name] = newValue;
},
Expand All @@ -280,9 +322,9 @@ export default {
mounted() {
this.$store.dispatch('clearMessages');
if (this.id !== 'new') {
if (this.currentId !== 'new') {
if (!this.config) {
this.$store.dispatch('configRead', this.id)
this.$store.dispatch('configRead', this.currentId)
.then(() => {
this.currentConfig = this.configStore;
});
Expand Down
Loading

0 comments on commit 9cadc92

Please sign in to comment.