Fixed post safety user settings
This commit is contained in:
parent
c377ac8216
commit
0e6ed74682
4 changed files with 7 additions and 35 deletions
|
@ -50,34 +50,6 @@ $.fn.bindOnce = function(name, eventName, callback)
|
|||
|
||||
|
||||
|
||||
//safety trigger
|
||||
$(function()
|
||||
{
|
||||
$('.safety a').click(function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var aDom = $(this);
|
||||
if (aDom.hasClass('inactive'))
|
||||
return;
|
||||
aDom.addClass('inactive');
|
||||
|
||||
var url = $(this).attr('href') + '?json';
|
||||
$.get(url).success(function(data)
|
||||
{
|
||||
window.location.reload();
|
||||
}).error(function(xhr)
|
||||
{
|
||||
alert(xhr.responseJSON
|
||||
? xhr.responseJSON.message
|
||||
: 'Fatal error');
|
||||
aDom.removeClass('inactive');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
//basic event listeners
|
||||
$(function()
|
||||
{
|
||||
|
|
|
@ -83,7 +83,7 @@ class UserController
|
|||
if (!is_array($suppliedSafety))
|
||||
$suppliedSafety = [];
|
||||
foreach (PostSafety::getAll() as $safety)
|
||||
$user->enableSafety($safety, in_array($safety, $suppliedSafety));
|
||||
$user->enableSafety($safety, in_array($safety->toInteger(), $suppliedSafety));
|
||||
|
||||
$user->enableEndlessScrolling(InputHelper::get('endless-scrolling'));
|
||||
$user->enablePostTagTitles(InputHelper::get('post-tag-titles'));
|
||||
|
|
|
@ -48,6 +48,9 @@ final class UserEntity extends AbstractEntity implements IValidatable
|
|||
$this->validateAccessRank();
|
||||
$this->validateEmails();
|
||||
|
||||
if (!$this->getSetting(UserModel::SETTING_SAFETY))
|
||||
$this->setSetting(UserModel::SETTING_SAFETY, (new PostSafety(PostSafety::Safe))->toFlag());
|
||||
|
||||
if (empty($this->getAccessRank()))
|
||||
throw new Exception('No access rank detected');
|
||||
|
||||
|
@ -275,8 +278,8 @@ final class UserEntity extends AbstractEntity implements IValidatable
|
|||
{
|
||||
$all = $this->getSetting(UserModel::SETTING_SAFETY);
|
||||
if (!$all)
|
||||
return $safety->toInteger() == PostSafety::Safe;
|
||||
return $all & $safety->toFlag();
|
||||
return $safety->toInteger() == (new PostSafety(PostSafety::Safe))->toInteger();
|
||||
return ($all & $safety->toFlag()) == $safety->toFlag();
|
||||
}
|
||||
|
||||
public function enableSafety(PostSafety $safety, $enabled)
|
||||
|
@ -293,9 +296,6 @@ final class UserEntity extends AbstractEntity implements IValidatable
|
|||
$new |= $safety->toFlag();
|
||||
}
|
||||
|
||||
if (!$new)
|
||||
$new = (new PostSafety(PostSafety::Safe))->toFlag();
|
||||
|
||||
$this->setSetting(UserModel::SETTING_SAFETY, $new);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class PostSafety extends Enum implements IValidatable
|
|||
|
||||
public function toFlag()
|
||||
{
|
||||
return pow(2, $this->safety);
|
||||
return pow(2, $this->safety - 1);
|
||||
}
|
||||
|
||||
public function toString()
|
||||
|
|
Loading…
Reference in a new issue