Skip to content

Commit

Permalink
MDL-74634 theme_boost: remove old drawer-open-nav user preference.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Jun 12, 2022
1 parent ca583bd commit 47d1199
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 57 deletions.
8 changes: 8 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4565,5 +4565,13 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2022060300.01);
}

if ($oldversion < 2022061000.01) {
// Remove drawer-open-nav user preference for every user.
$DB->delete_records('user_preferences', ['name' => 'drawer-open-nav']);

// Main savepoint reached.
upgrade_main_savepoint(true, 2022061000.01);
}

return true;
}
18 changes: 0 additions & 18 deletions theme/boost/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ class provider implements
// This plugin has some sitewide user preferences to export.
\core_privacy\local\request\user_preference_provider {

/** The user preference for the navigation drawer. */
const DRAWER_OPEN_NAV = 'drawer-open-nav';

/** The user preferences for the course index. */
const DRAWER_OPEN_INDEX = 'drawer-open-index';

Expand All @@ -56,7 +53,6 @@ class provider implements
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $items) : collection {
$items->add_user_preference(self::DRAWER_OPEN_NAV, 'privacy:metadata:preference:draweropennav');
$items->add_user_preference(self::DRAWER_OPEN_INDEX, 'privacy:metadata:preference:draweropenindex');
$items->add_user_preference(self::DRAWER_OPEN_BLOCK, 'privacy:metadata:preference:draweropenblock');
return $items;
Expand All @@ -68,20 +64,6 @@ public static function get_metadata(collection $items) : collection {
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
$draweropennavpref = get_user_preferences(self::DRAWER_OPEN_NAV, null, $userid);

if (isset($draweropennavpref)) {
$preferencestring = get_string('privacy:drawernavclosed', 'theme_boost');
if ($draweropennavpref == 'true') {
$preferencestring = get_string('privacy:drawernavopen', 'theme_boost');
}
\core_privacy\local\request\writer::export_user_preference(
'theme_boost',
self::DRAWER_OPEN_NAV,
$draweropennavpref,
$preferencestring
);
}

$draweropenindexpref = get_user_preferences(self::DRAWER_OPEN_INDEX, null, $userid);

Expand Down
2 changes: 2 additions & 0 deletions theme/boost/lang/en/deprecated.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
totop,theme_boost
privacy:drawernavclosed,theme_boost
privacy:drawernavopen,theme_boost
6 changes: 4 additions & 2 deletions theme/boost/lang/en/theme_boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@
$string['privacy:drawerindexopen'] = 'The current preference for the index drawer is open.';
$string['privacy:drawerblockclosed'] = 'The current preference for the block drawer is closed.';
$string['privacy:drawerblockopen'] = 'The current preference for the block drawer is open.';
$string['privacy:drawernavclosed'] = 'The current preference for the navigation drawer is closed.';
$string['privacy:drawernavopen'] = 'The current preference for the navigation drawer is open.';

// Deprecated since Moodle 4.0.
$string['totop'] = 'Go to top';

// Deprecated since Moodle 4.1.
$string['privacy:drawernavclosed'] = 'The current preference for the navigation drawer is closed.';
$string['privacy:drawernavopen'] = 'The current preference for the navigation drawer is open.';
1 change: 0 additions & 1 deletion theme/boost/layout/columns2.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

defined('MOODLE_INTERNAL') || die();

user_preference_allow_ajax_update('drawer-open-nav', PARAM_ALPHA);
require_once($CFG->libdir . '/behat/lib.php');

// Add block button in editing mode.
Expand Down
1 change: 0 additions & 1 deletion theme/boost/layout/drawers.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
// Add block button in editing mode.
$addblockbutton = $OUTPUT->addblockbutton();

user_preference_allow_ajax_update('drawer-open-nav', PARAM_ALPHA);
user_preference_allow_ajax_update('drawer-open-index', PARAM_BOOL);
user_preference_allow_ajax_update('drawer-open-block', PARAM_BOOL);

Expand Down
65 changes: 31 additions & 34 deletions theme/boost/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,63 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Privacy tests for theme_boost.
*
* @package theme_boost
* @category test
* @copyright 2018 Adrian Greeve <adriangreeve.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace theme_boost\privacy;

defined('MOODLE_INTERNAL') || die();

use theme_boost\privacy\provider;
use context_user;
use core_privacy\local\request\writer;

/**
* Unit tests for theme_boost/classes/privacy/policy
* Privacy tests for theme_boost.
*
* @package theme_boost
* @category test
* @covers \theme_boost\privacy\provider
* @copyright 2018 Adrian Greeve <adriangreeve.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {

/**
* Data provider for {@see test_export_user_preferences}
*
* @return array[]
*/
public function export_user_preference_provider(): array {
return [
'Index drawer open' => [provider::DRAWER_OPEN_INDEX, true, 'privacy:drawerindexopen'],
'Index drawer closed' => [provider::DRAWER_OPEN_INDEX, false, 'privacy:drawerindexclosed'],
'Block drawer open' => [provider::DRAWER_OPEN_BLOCK, true, 'privacy:drawerblockopen'],
'Block drawer closed' => [provider::DRAWER_OPEN_BLOCK, false, 'privacy:drawerblockclosed'],
];
}

/**
* Test for provider::test_export_user_preferences().
*
* @param string $preference
* @param bool $value
* @param string $expectdescription
*
* @dataProvider export_user_preference_provider
*/
public function test_export_user_preferences() {
public function test_export_user_preferences(string $preference, bool $value, string $expectdescription): void {
$this->resetAfterTest();

// Test setup.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);

// Add a user home page preference for the User.
set_user_preference(provider::DRAWER_OPEN_NAV, 'false', $user);

// Test the user preferences export contains 1 user preference record for the User.
provider::export_user_preferences($user->id);
$contextuser = \context_user::instance($user->id);
$writer = \core_privacy\local\request\writer::with_context($contextuser);
$this->assertTrue($writer->has_any_data());

$exportedpreferences = $writer->get_user_preferences('theme_boost');
$this->assertCount(1, (array) $exportedpreferences);
$this->assertEquals('false', $exportedpreferences->{provider::DRAWER_OPEN_NAV}->value);
$this->assertEquals(get_string('privacy:drawernavclosed', 'theme_boost'),
$exportedpreferences->{provider::DRAWER_OPEN_NAV}->description);

// Add a user home page preference for the User.
set_user_preference(provider::DRAWER_OPEN_NAV, 'true', $user);
set_user_preference($preference, $value, $user);

// Test the user preferences export contains 1 user preference record for the User.
provider::export_user_preferences($user->id);
$contextuser = \context_user::instance($user->id);
$writer = \core_privacy\local\request\writer::with_context($contextuser);
$writer = writer::with_context(context_user::instance($user->id));
$this->assertTrue($writer->has_any_data());

$exportedpreferences = $writer->get_user_preferences('theme_boost');
$this->assertCount(1, (array) $exportedpreferences);
$this->assertEquals('true', $exportedpreferences->{provider::DRAWER_OPEN_NAV}->value);
$this->assertEquals(get_string('privacy:drawernavopen', 'theme_boost'),
$exportedpreferences->{provider::DRAWER_OPEN_NAV}->description);
$this->assertEquals($value, (bool) $exportedpreferences->{$preference}->value);
$this->assertEquals(get_string($expectdescription, 'theme_boost'), $exportedpreferences->{$preference}->description);
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2022061000.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2022061000.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.1dev (Build: 20220610)'; // Human-friendly version name
Expand Down

0 comments on commit 47d1199

Please sign in to comment.