Skip to content

Commit

Permalink
Fixing server card issues (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrahn committed Aug 31, 2023
1 parent 4a6f11c commit c4649b0
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 15 deletions.
14 changes: 12 additions & 2 deletions lib/Models/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ public function updateEndpoints($container)
];

Endpoints::deleteBySql('config_id = ?', [$this->id]);
Config::deleteBySql('id = ?', [$this->id]);
} else {
$service_host =
$service_url['scheme'] .'://' .
Expand All @@ -186,7 +185,18 @@ public function updateEndpoints($container)
$services_client = new ServicesClient($this->id);

$comp = null;
$comp = $services_client->getRESTComponents();
try {
$comp = $services_client->getRESTComponents();
}
catch(\Exception $e) {
return [
'type' => 'error',
'text' => sprintf(
_('%s'),
$e->getMessage()
)
];
}
} catch (AccessDeniedException $e) {
Endpoints::removeEndpoint($this->id, 'services');

Expand Down
25 changes: 25 additions & 0 deletions lib/Models/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,31 @@ static function getMyCourses($user_id)
return $courses;
}

/**
* Check and make sure, that a valid server is set.
* If no server is detected, -1 will be stored.
*
* @return
*/
static function validateDefaultServer() {
$config = new \SimpleCollection(Config::findBySql(1));
$config_ids = $config->pluck('id');

$value = \Config::get()->OPENCAST_DEFAULT_SERVER;
$valid_value = $value;

if (empty($config_ids)) {
$valid_value = -1;
}
elseif (in_array($value, $config_ids) === false) {
$valid_value = reset($config_ids);
}
if ($valid_value != $value) {
$value = $valid_value;
\Config::get()->store('OPENCAST_DEFAULT_SERVER', $valid_value);
}
}

/**
* Check if the default course playlists exists and create if necessary
*
Expand Down
8 changes: 8 additions & 0 deletions lib/Routes/Config/ConfigAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Opencast\Models\Endpoints;
use Opencast\Models\SeminarEpisodes;
use Opencast\Models\LTI\LtiHelper;
use Opencast\Models\Helpers;

use Opencast\Models\I18N as _;

Expand Down Expand Up @@ -52,9 +53,16 @@ public function __invoke(Request $request, Response $response, $args)

// check settings and store them to the database
$config->updateSettings($json['config']);
// Validate that a correct default server is set
Helpers::validateDefaultServer();

// check configuration and load endpoints
$message = $config->updateEndpoints($this->container);
// Dont save configuration if it failed
if ($message['type'] == 'error') {
Endpoints::removeEndpoint($config->id, 'services');
Config::deleteBySql('id = ?', [$config->id]);
}

$ret_config = $config->toArray();
$ret_config = array_merge($ret_config, $ret_config['settings']);
Expand Down
4 changes: 4 additions & 0 deletions lib/Routes/Config/ConfigDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Opencast\OpencastController;
use Opencast\Models\Config;
use Opencast\Models\Videos;
use Opencast\Models\Helpers;

class ConfigDelete extends OpencastController
{
Expand All @@ -30,6 +31,9 @@ public function __invoke(Request $request, Response $response, $args)
if (!$config->delete()) {
throw new Error('Could not delete config.', 500);
}

// Validate that a correct default server is set
Helpers::validateDefaultServer();

return $response->withStatus(204);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/Routes/Config/ConfigEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __invoke(Request $request, Response $response, $args)
$duplicate_url = false;

$config = Config::find($args['id']);
$config_old = $config->toArray();

if (empty($config)) {
throw new Error('Could not find config with id '. $args['id'] .'.', 500);
Expand All @@ -38,6 +39,11 @@ public function __invoke(Request $request, Response $response, $args)

// check configuration and load endpoints
$message = $config->updateEndpoints($this->container);
// Restore configuration if it failed
if ($message['type'] == 'error') {
$config->setData($config_old);
$config->store();
}

$ret_config = $config->toArray();
$ret_config = array_merge($ret_config, $ret_config['settings']);
Expand Down
13 changes: 3 additions & 10 deletions lib/Routes/Config/ConfigUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Opencast\OpencastTrait;
use Opencast\OpencastController;
use Opencast\Models\ScheduleHelper;
use Opencast\Models\Helpers;
use Opencast\Models\Config;
use Opencast\Models\WorkflowConfig;

Expand All @@ -24,22 +25,14 @@ public function __invoke(Request $request, Response $response, $args)
// load oc server configs
$config = new \SimpleCollection(Config::findBySql(1));

$config_ids = $config->pluck('id');

// Storing General Configs.
foreach ($json['settings'] as $config) {
// validate values
if ($config['name'] == 'OPENCAST_DEFAULT_SERVER') {
// check, that a correct server is set
if (in_array($config['value'], $config_ids) === false) {
$config['value'] = reset($config_ids);
}
}

if (in_array($config['name'], $constants['global_config_options'])) {
\Config::get()->store($config['name'], $config['value']);
}
}
// Validate that a correct default server is set
Helpers::validateDefaultServer();

// Storing Resources Configs.
$messages = [];
Expand Down
1 change: 1 addition & 0 deletions vueapp/components/Config/AdminConfigs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default {
}
this.$store.dispatch('configListUpdate', params)
.then(({ data }) => {
this.$store.dispatch('configListRead');
if (data.messages.length) {
for (let i = 0; i < data.messages.length; i++ ) {
this.$store.dispatch('addMessage', data.messages[i]);
Expand Down
4 changes: 2 additions & 2 deletions vueapp/components/Config/ConfigOption.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@change="setValue(setting.value)">
</label>

<label v-if="setting.type == 'string' && setting.options">
<label v-if="(setting.type == 'string' || setting.type == 'integer') && setting.options">
<span :class="{
required: setting.required
}">
Expand All @@ -61,7 +61,7 @@
@option:selected="setValue(setting.value)"/>
</label>

<label v-if="setting.type == 'integer'">
<label v-if="setting.type == 'integer' && !setting.options">
<span :class="{
required: setting.required
}">
Expand Down
26 changes: 25 additions & 1 deletion vueapp/components/Config/GlobalOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export default {
setting.options = this.downloadOptions;
settings.push(setting);
}
else if (this.config_list.settings[id].name == 'OPENCAST_DEFAULT_SERVER') {
let setting = this.config_list.settings[id];
setting.options = this.defaultServerOptions;
settings.push(setting);
}
else if (this.config_list.settings[id].name != 'OPENCAST_TOS') {
settings.push(this.config_list.settings[id]);
}
Expand Down Expand Up @@ -98,6 +102,26 @@ export default {
];
},
defaultServerOptions() {
let options = [];
this.config_list.server.forEach(server => {
options.push({
value: server.id,
description: '[#' + server.id + '] ' + server.service_url + ''
})
});
if (options.length === 0) {
options.push({
value: -1,
description: 'Es sind keine Server eingerichtet'
})
}
return options;
},
opencastTos() {
for (let id in this.config_list.settings) {
if (this.config_list.settings[id].name == 'OPENCAST_TOS') {
Expand Down

0 comments on commit c4649b0

Please sign in to comment.