Restored support for anonymous setting changes
This commit is contained in:
parent
087d50f61b
commit
95e37e55eb
7 changed files with 14 additions and 13 deletions
|
@ -20,6 +20,10 @@ class EditUserSettingsJob extends AbstractJob
|
|||
{
|
||||
$user->getSettings()->set($key, $value);
|
||||
}
|
||||
|
||||
if ($user->getAccessRank()->toInteger() == AccessRank::Anonymous)
|
||||
return $user;
|
||||
|
||||
return UserModel::save($user);
|
||||
}
|
||||
|
||||
|
@ -39,6 +43,6 @@ class EditUserSettingsJob extends AbstractJob
|
|||
|
||||
public function isAuthenticationRequired()
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,6 @@ class GetUserSettingsJob extends AbstractJob
|
|||
|
||||
public function isAuthenticationRequired()
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ class Auth
|
|||
|
||||
public static function tryAutoLogin()
|
||||
{
|
||||
if (self::isLoggedIn())
|
||||
return;
|
||||
|
||||
if (!isset($_COOKIE['auth']))
|
||||
return;
|
||||
|
||||
|
@ -77,7 +80,7 @@ class Auth
|
|||
|
||||
public static function getCurrentUser()
|
||||
{
|
||||
return self::isLoggedIn()
|
||||
return isset($_SESSION['user'])
|
||||
? unserialize($_SESSION['user'])
|
||||
: self::getAnonymousUser();
|
||||
}
|
||||
|
|
|
@ -80,7 +80,8 @@ function prepareEnvironment($testEnvironment)
|
|||
if (\Chibi\Database::connected())
|
||||
\Chibi\Database::disconnect();
|
||||
|
||||
Auth::setCurrentUser(null);
|
||||
if ($testEnvironment)
|
||||
Auth::setCurrentUser(null);
|
||||
Access::init();
|
||||
Logger::init();
|
||||
Mailer::init();
|
||||
|
|
|
@ -24,7 +24,7 @@ class ApiAuthTest extends AbstractFullApiTest
|
|||
$this->testAuth(new EditUserJob(), false);
|
||||
$this->testAuth(new EditUserNameJob(), false);
|
||||
$this->testAuth(new EditUserPasswordJob(), false);
|
||||
$this->testAuth(new EditUserSettingsJob(), true);
|
||||
$this->testAuth(new EditUserSettingsJob(), false);
|
||||
$this->testAuth(new FeaturePostJob(), true);
|
||||
$this->testAuth(new FlagPostJob(), false);
|
||||
$this->testAuth(new FlagUserJob(), false);
|
||||
|
@ -33,7 +33,7 @@ class ApiAuthTest extends AbstractFullApiTest
|
|||
$this->testAuth(new GetPostJob(), false);
|
||||
$this->testAuth(new GetPostThumbJob(), false);
|
||||
$this->testAuth(new GetUserJob(), false);
|
||||
$this->testAuth(new GetUserSettingsJob(), true);
|
||||
$this->testAuth(new GetUserSettingsJob(), false);
|
||||
$this->testAuth(new ListCommentsJob(), false);
|
||||
$this->testAuth(new ListLogsJob(), false);
|
||||
$this->testAuth(new ListPostsJob(), false);
|
||||
|
|
|
@ -5,7 +5,6 @@ class EditUserSettingsJobTest extends AbstractTest
|
|||
{
|
||||
$this->grantAccess('changeUserSettings');
|
||||
$user = $this->userMocker->mockSingle();
|
||||
$this->login($user);
|
||||
|
||||
$expectedSafety = (new PostSafety(PostSafety::Sketchy))->toFlag();
|
||||
$user = $this->assert->doesNotThrow(function() use ($user, $expectedSafety)
|
||||
|
@ -36,7 +35,6 @@ class EditUserSettingsJobTest extends AbstractTest
|
|||
{
|
||||
$this->grantAccess('changeUserSettings');
|
||||
$user = $this->userMocker->mockSingle();
|
||||
$this->login($user);
|
||||
|
||||
$user = $this->assert->doesNotThrow(function() use ($user)
|
||||
{
|
||||
|
@ -65,7 +63,6 @@ class EditUserSettingsJobTest extends AbstractTest
|
|||
{
|
||||
$this->grantAccess('changeUserSettings');
|
||||
$user = $this->userMocker->mockSingle();
|
||||
$this->login($user);
|
||||
|
||||
$user = $this->assert->doesNotThrow(function() use ($user)
|
||||
{
|
||||
|
@ -95,7 +92,6 @@ class EditUserSettingsJobTest extends AbstractTest
|
|||
{
|
||||
$this->grantAccess('changeUserSettings');
|
||||
$user = $this->userMocker->mockSingle();
|
||||
$this->login($user);
|
||||
|
||||
$this->assert->throws(function() use ($user)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,6 @@ class GetUserSettingsJobTest extends AbstractTest
|
|||
{
|
||||
$this->grantAccess('changeUserSettings');
|
||||
$user = $this->userMocker->mockSingle();
|
||||
$this->login($user);
|
||||
|
||||
$settings = $this->assert->doesNotThrow(function() use ($user)
|
||||
{
|
||||
|
@ -28,7 +27,6 @@ class GetUserSettingsJobTest extends AbstractTest
|
|||
{
|
||||
$this->grantAccess('changeUserSettings');
|
||||
$user = $this->userMocker->mockSingle();
|
||||
$this->login($user);
|
||||
|
||||
$user->getSettings()->enableSafety(new PostSafety(PostSafety::Sketchy), true);
|
||||
UserModel::save($user);
|
||||
|
@ -57,7 +55,6 @@ class GetUserSettingsJobTest extends AbstractTest
|
|||
{
|
||||
$this->grantAccess('changeUserSettings');
|
||||
$user = $this->userMocker->mockSingle();
|
||||
$this->login($user);
|
||||
|
||||
$user->getSettings()->enableSafety(new PostSafety(PostSafety::Sketchy), true);
|
||||
$user->getSettings()->enableSafety(new PostSafety(PostSafety::Safe), false);
|
||||
|
|
Loading…
Reference in a new issue