mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-59153 analytics: No access to disabled models predictions
This commit is contained in:
parent
b3cfb01316
commit
3e0f33aa4b
@ -115,7 +115,9 @@ class models_list implements \renderable, \templatable {
|
||||
}
|
||||
|
||||
// Model predictions list.
|
||||
if ($model->uses_insights()) {
|
||||
if (!$model->is_enabled()) {
|
||||
$modeldata->noinsights = get_string('disabledmodel', 'analytics');
|
||||
} else if ($model->uses_insights()) {
|
||||
$predictioncontexts = $model->get_predictions_contexts();
|
||||
if ($predictioncontexts) {
|
||||
|
||||
|
@ -443,7 +443,12 @@ class model {
|
||||
|
||||
// Reset trained flag.
|
||||
$this->model->trained = 0;
|
||||
|
||||
} else if ($this->model->enabled != $enabled) {
|
||||
// We purge the cached contexts with insights as some will not be visible anymore.
|
||||
$this->purge_insights_cache();
|
||||
}
|
||||
|
||||
$this->model->enabled = intval($enabled);
|
||||
$this->model->indicators = $indicatorsstr;
|
||||
$this->model->timesplitting = $timesplittingid;
|
||||
@ -971,6 +976,13 @@ class model {
|
||||
$this->model->timesplitting = $timesplittingid;
|
||||
$this->model->version = $now;
|
||||
}
|
||||
|
||||
// Purge pages with insights as this may change things.
|
||||
if ($timesplittingid && $timesplittingid !== $this->model->timesplitting ||
|
||||
$this->model->enabled != 1) {
|
||||
$this->purge_insights_cache();
|
||||
}
|
||||
|
||||
$this->model->enabled = 1;
|
||||
$this->model->timemodified = $now;
|
||||
|
||||
@ -1375,6 +1387,13 @@ class model {
|
||||
|
||||
// We don't expect people to clear models regularly and the cost of filling the cache is
|
||||
// 1 db read per context.
|
||||
$this->purge_insights_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Purges the insights cache.
|
||||
*/
|
||||
private function purge_insights_cache() {
|
||||
$cache = \cache::make('core', 'contextwithinsights');
|
||||
$cache->purge();
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ $string['analyticslogstore_help'] = 'The log store that will be used by the anal
|
||||
$string['analyticssettings'] = 'Analytics settings';
|
||||
$string['coursetoolong'] = 'The course is too long';
|
||||
$string['enabledtimesplittings'] = 'Time splitting methods';
|
||||
$string['disabledmodel'] = 'Disabled model';
|
||||
$string['erroralreadypredict'] = '{$a} file has already been used to predict';
|
||||
$string['errorcannotreaddataset'] = 'Dataset file {$a} can not be read';
|
||||
$string['errorcannotwritedataset'] = 'Dataset file {$a} can not be written';
|
||||
|
@ -45,7 +45,7 @@ if (!isset($actions[$actionname])) {
|
||||
}
|
||||
|
||||
$modelready = $model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
|
||||
if (!$modelready && !has_capability('moodle/analytics:managemodels', $context)) {
|
||||
if (!$modelready) {
|
||||
|
||||
$PAGE->set_pagelayout('report');
|
||||
|
||||
@ -53,7 +53,7 @@ if (!$modelready && !has_capability('moodle/analytics:managemodels', $context))
|
||||
$PAGE->set_title($context->get_context_name());
|
||||
$PAGE->set_heading($context->get_context_name());
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->notification(get_string('disabledmodel', 'analytics'), \core\output\notification::NOTIFY_INFO);
|
||||
echo $OUTPUT->notification(get_string('disabledmodel', 'report_insights'), \core\output\notification::NOTIFY_INFO);
|
||||
echo $OUTPUT->footer();
|
||||
exit(0);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ class renderer extends plugin_renderer_base {
|
||||
$PAGE->set_heading($insightinfo->contextname);
|
||||
|
||||
$output = $OUTPUT->header();
|
||||
$output .= $OUTPUT->notification(get_string('disabledmodel', 'analytics'), \core\output\notification::NOTIFY_INFO);
|
||||
$output .= $OUTPUT->notification(get_string('disabledmodel', 'report_insights'), \core\output\notification::NOTIFY_INFO);
|
||||
$output .= $OUTPUT->footer();
|
||||
|
||||
return $output;
|
||||
|
@ -76,7 +76,7 @@ $insightinfo->contextname = $context->get_context_name();
|
||||
$insightinfo->insightname = $model->get_target()->get_name();
|
||||
$title = get_string('insightinfo', 'analytics', $insightinfo);
|
||||
|
||||
if (!$model->is_enabled() && !has_capability('moodle/analytics:managemodels', $context)) {
|
||||
if (!$model->is_enabled()) {
|
||||
echo $renderer->render_model_disabled($insightinfo);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ $insightinfo->insightname = $model->get_target()->get_name();
|
||||
$title = get_string('insightinfo', 'analytics', $insightinfo);
|
||||
|
||||
$modelready = $model->is_enabled() && $model->is_trained() && $model->predictions_exist($context);
|
||||
if (!$modelready && !has_capability('moodle/analytics:managemodels', $context)) {
|
||||
if (!$modelready) {
|
||||
echo $renderer->render_model_disabled($insightinfo);
|
||||
exit(0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user