Skip to content
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
9 changes: 1 addition & 8 deletions core/src/Controllers/Password.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php namespace EvolutionCMS\Controllers;

use EvolutionCMS\Models;
use EvolutionCMS\Interfaces\ManagerTheme;

class Password extends AbstractController implements ManagerTheme\PageControllerInterface
Expand All @@ -12,13 +11,7 @@ class Password extends AbstractController implements ManagerTheme\PageController
*/
public function checkLocked(): ?string
{
$out = Models\ActiveUser::locked(28)
->first();
if ($out !== null) {
return sprintf($this->managerTheme->getLexicon('error_no_privileges'), $out->username);
}

return $out;
return null;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion core/src/Controllers/Users/ChangePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function process() : bool
}
}

header("Location: index.php?a=99");
// not the user list (a=99): it needs edit_user, which this action does not require
header("Location: index.php?a=2");
exit();
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/Controllers/Users/DeleteUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function process() : bool
}
}
}
header("Location: index.php?a=99");
// the user list needs edit_user, which this action does not require
$landing = $this->managerTheme->getCore()->hasPermission('edit_user') ? 99 : 2;
header("Location: index.php?a={$landing}");
exit();
}

Expand Down
21 changes: 21 additions & 0 deletions core/tests/Unit/Controllers/ChangePasswordRedirectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

// #2553: the password is already saved by then, so a refused landing page reports a failure that did not happen
test('a saved password lands on a page every role that may change it can open', function () {
$core = dirname(__DIR__, 3);
$controller = (string) file_get_contents($core . '/src/Controllers/Users/ChangePassword.php');
$theme = (string) file_get_contents($core . '/src/ManagerTheme.php');
$dashboard = (string) file_get_contents(dirname($core) . '/manager/views/page/2.blade.php');

expect($controller)
->toContain('header("Location: index.php?a=2");')
->not->toContain('Location: index.php?a=99')
->and($theme)->toMatch('/^\s*2 => null,/m')
->and($dashboard)->not->toContain('error_no_privileges');
});

test('the user list stays closed to roles without edit_user', function () {
$list = (string) file_get_contents(dirname(__DIR__, 4) . '/manager/actions/web_user_management.static.php');

expect($list)->toContain("hasPermission('edit_user')");
});
11 changes: 11 additions & 0 deletions core/tests/Unit/Controllers/DeleteUserRedirectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

// the user is already deleted by then, so a refused landing page reports a failure that did not happen
test('a deleted user lands on the user list only for a role that may open it', function () {
$source = (string) file_get_contents(dirname(__DIR__, 3) . '/src/Controllers/Users/DeleteUser.php');

expect($source)
->toContain("\$landing = \$this->managerTheme->getCore()->hasPermission('edit_user') ? 99 : 2;")
->toContain('header("Location: index.php?a={$landing}");')
->not->toContain('header("Location: index.php?a=99");');
});
10 changes: 10 additions & 0 deletions core/tests/Unit/Controllers/PasswordPageLockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use EvolutionCMS\Controllers\Password;

// the form changes the viewer's own password only, so another manager on it conflicts with nothing
test('the change password page is never locked by another manager', function () {
$controller = (new ReflectionClass(Password::class))->newInstanceWithoutConstructor();

expect($controller->checkLocked())->toBeNull();
});
Loading