From 57d5be04f8b7178f1e8fe71ab3b6e0bb6a7255c0 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Mon, 15 Mar 2021 13:45:42 +0100 Subject: [PATCH 1/2] MDL-71107 core_contentbank: Fill content author when copying a course 'usercreated' and 'usermodified' fields can not be always mapped. We are filling those fields with 'old' users when working on the same site, or with current user when working on a different instance. --- backup/moodle2/restore_stepslib.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 024a9c11223..27b512e623a 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -4046,9 +4046,30 @@ class restore_contentbankcontent_structure_step extends restore_structure_step { $exists = $DB->record_exists('contentbank_content', $params); if (!$exists) { $params['configdata'] = $data->configdata; - $params['usercreated'] = $this->get_mappingid('user', $data->usercreated); - $params['usermodified'] = $this->get_mappingid('user', $data->usermodified); $params['timemodified'] = time(); + + // Trying to map users. Users cannot always be mapped, e.g. when copying. + $params['usercreated'] = $this->get_mappingid('user', $data->usercreated); + if (!$params['usercreated']) { + // Leave the content creator unchanged when we are restoring the same site. + // Otherwise use current user id. + if ($this->task->is_samesite()) { + $params['usercreated'] = $data->usercreated; + } else { + $params['usercreated'] = $this->task->get_userid(); + } + } + $params['usermodified'] = $this->get_mappingid('user', $data->usermodified); + if (!$params['usermodified']) { + // Leave the content modifier unchanged when we are restoring the same site. + // Otherwise use current user id. + if ($this->task->is_samesite()) { + $params['usermodified'] = $data->usermodified; + } else { + $params['usermodified'] = $this->task->get_userid(); + } + } + $newitemid = $DB->insert_record('contentbank_content', $params); $this->set_mapping('contentbank_content', $oldid, $newitemid, true); } From ff6ac0b2fd0b1d5714eb2e72540b71cc21ebde83 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Tue, 16 Mar 2021 13:18:10 +0100 Subject: [PATCH 2/2] MDL-71107 core_contentbank: Behat test. Authoring when copying a course --- contentbank/tests/behat/edit_content.feature | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/contentbank/tests/behat/edit_content.feature b/contentbank/tests/behat/edit_content.feature index 29108c7a2eb..ff95990cf08 100644 --- a/contentbank/tests/behat/edit_content.feature +++ b/contentbank/tests/behat/edit_content.feature @@ -159,3 +159,37 @@ Feature: Content bank use editor feature And I click on "Content bank" "link" And I follow "filltheblanks.h5p" Then "Edit" "link" should not exist in the "region-main" "region" + + Scenario: Teachers keep their content authoring in copied courses + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "contentbank content" exist: + | contextlevel | reference | contenttype | user | contentname | filepath | + | Course | C1 | contenttype_h5p | admin | filltheblanks.h5p | /h5p/tests/fixtures/filltheblanks.h5p | + | Course | C1 | contenttype_h5p | teacher1 | ipsums.h5p | /h5p/tests/fixtures/ipsums.h5p | + And I am on "Course 1" course homepage + And I navigate to "Copy course" in current page administration + And I set the following fields to these values: + | Course full name | Copy | + | Course short name | Copy | + | Teacher | 1 | + When I press "Copy and view" + And I trigger cron + And I am on homepage + And I log out + And I log in as "teacher1" + And I am on "Copy" course homepage + And I expand "Site pages" node + And I click on "Content bank" "link" + And I follow "ipsums.h5p" + Then "Edit" "link" should exist in the "region-main" "region" + And I click on "Content bank" "link" + And I follow "filltheblanks.h5p" + Then "Edit" "link" should not exist in the "region-main" "region"