Skip to content

Commit

Permalink
MDL-61667 analytics: Remove duplicated capability checks
Browse files Browse the repository at this point in the history
\core_analytics\model::create and \core_analytics\model::enable methods
are called from install/upgrade scripts. Therefore, they should not
include any capability check. Their capability checks are actually
redundant, as the user capabilities are already checked in the
entry-point scripts.
  • Loading branch information
David Monllaó authored and mudrd8mz committed Apr 1, 2019
1 parent d887b0c commit f54a409
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions analytics/classes/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ public static function create(\core_analytics\local\target\base $target, array $
$timesplittingid = false, $processor = null) {
global $USER, $DB;

\core_analytics\manager::check_can_manage_models();

$indicatorclasses = self::indicator_classes($indicators);

$now = time();
Expand All @@ -360,6 +358,10 @@ public static function create(\core_analytics\local\target\base $target, array $
$modelobj->timemodified = $now;
$modelobj->usermodified = $USER->id;

if ($target->based_on_assumptions()) {
$modelobj->trained = 1;
}

if ($timesplittingid) {
if (!\core_analytics\manager::is_valid($timesplittingid, '\core_analytics\local\time_splitting\base')) {
throw new \moodle_exception('errorinvalidtimesplitting', 'analytics');
Expand All @@ -385,10 +387,6 @@ public static function create(\core_analytics\local\target\base $target, array $

$model = new static($modelobj);

if ($model->is_static()) {
$model->mark_as_trained();
}

return $model;
}

Expand Down Expand Up @@ -1059,8 +1057,6 @@ protected function save_predictions($records) {
public function enable($timesplittingid = false) {
global $DB, $USER;

\core_analytics\manager::check_can_manage_models();

$now = time();

if ($timesplittingid && $timesplittingid !== $this->model->timesplitting) {
Expand Down

0 comments on commit f54a409

Please sign in to comment.