Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning when resetting user's password with masterkey encryption #36523

Merged
merged 2 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/36523
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: suppress warning when resetting user password with masterkey encryption

When an admin wanted to reset user's password over the Users management page with masterkey encryption in place, a warning was displayed about data recovery not being available. The behavior has now been fixed.

https://github.com/owncloud/core/pull/36523
26 changes: 10 additions & 16 deletions settings/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ class UsersController extends Controller {
private $fromMailAddress;
/** @var IURLGenerator */
private $urlGenerator;
/** @var bool contains the state of the encryption app */
private $isEncryptionAppEnabled;
/** @var bool contains the state of the admin recovery setting */
private $isRestoreEnabled = false;
/** @var IAvatarManager */
Expand Down Expand Up @@ -153,8 +151,7 @@ public function __construct($appName,
$this->eventDispatcher = $eventDispatcher;

// check for encryption state - TODO see formatUserForIndex
$this->isEncryptionAppEnabled = $appManager->isEnabledForUser('encryption');
if ($this->isEncryptionAppEnabled) {
if ($appManager->isEnabledForUser('encryption')) {
// putting this directly in empty is possible in PHP 5.5+
$result = $config->getAppValue('encryption', 'recoveryAdminEnabled', 0);
$this->isRestoreEnabled = !empty($result);
Expand All @@ -176,20 +173,17 @@ private function formatUserForIndex(IUser $user, array $userGroups = null) {
// below
$restorePossible = false;

if ($this->isEncryptionAppEnabled) {
if ($this->isRestoreEnabled) {
// check for the users recovery setting
$recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0');
// method call inside empty is possible with PHP 5.5+
$recoveryModeEnabled = !empty($recoveryMode);
if ($recoveryModeEnabled) {
// user also has recovery mode enabled
$restorePossible = true;
}
if ($this->isRestoreEnabled) {
// check for the users recovery setting
$recoveryMode = $this->config->getUserValue($user->getUID(), 'encryption', 'recoveryEnabled', '0');
// method call inside empty is possible with PHP 5.5+
$recoveryModeEnabled = !empty($recoveryMode);
if ($recoveryModeEnabled) {
// user also has recovery mode enabled
$restorePossible = true;
}
} else {
// recovery is possible if encryption is disabled (plain files are
// available)
// masterkey encryption or no encryption in place
$restorePossible = true;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Settings/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ public function testRestoreNotPossibleWithoutAdminRestore() {
)
->will($this->returnValue(true));

$expectedResult['isRestoreDisabled'] = true;
$expectedResult['isRestoreDisabled'] = false;

$subadmin = $this->getMockBuilder('\OC\SubAdmin')
->disableOriginalConstructor()
Expand Down