Added user banning

This commit is contained in:
Marcin Kurczewski 2014-09-30 13:22:11 +02:00
parent 3268618f26
commit 31e0158606
12 changed files with 43 additions and 1 deletions

1
TODO
View file

@ -62,7 +62,6 @@ everything related to posts:
(move post snapshot factory methods to PostService)
everything related to users:
- banning
- show link to user's uploads
- show link to user's favs
- show link to user's liked posts

View file

@ -38,6 +38,7 @@ changeAllNames = moderator, administrator
changeAllPasswords = moderator, administrator
changeAccessRank = administrator
viewAllEmailAddresses = moderator, administrator
ban = moderator, administrator
listSafePosts = anonymous, regularUser, powerUser, moderator, administrator
listSketchyPosts = anonymous, regularUser, powerUser, moderator, administrator

View file

@ -17,6 +17,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
changeAllPasswords: 'changeAllPasswords',
deleteOwnAccount: 'deleteOwnAccount',
deleteAllAccounts: 'deleteAllAccounts',
ban: 'ban',
listSafePosts: 'listSafePosts',
listSketchyPosts: 'listSketchyPosts',

View file

@ -22,6 +22,8 @@ App.Presenters.UserAccountSettingsPresenter = function(
target = args.target;
privileges = {
canBan:
auth.hasPrivilege(auth.privileges.ban),
canChangeAccessRank:
auth.hasPrivilege(auth.privileges.changeAccessRank),
canChangeAvatarStyle:
@ -105,6 +107,9 @@ App.Presenters.UserAccountSettingsPresenter = function(
if (privileges.canChangeAccessRank) {
formData.accessRank = $el.find('[name=access-rank]:checked').val();
}
if (privileges.canBan) {
formData.banned = $el.find('[name=ban]').is(':checked') ? 1 : 0;
}
if (!validateAccountSettingsFormData(formData)) {
return;

View file

@ -67,6 +67,19 @@
</div>
<% } %>
<% if (canBan) { %>
<div class="form-row">
<label class="form-label" for="account-settings-ban">Ban:</label>
<div class="form-input">
<input name="ban" type="checkbox" id="ban" <% print(user.banned ? 'checked="checked"' : '') %>>
<label for="ban">
Enabled
</label>
</div>
</div>
<% } %>
<% if (canChangeAccessRank) { %>
<div class="form-row">
<label class="form-label" for="account-settings-access-rank">Access rank:</label>

View file

@ -21,6 +21,7 @@ class UserViewProxy extends AbstractViewProxy
$result->registrationTime = $user->getRegistrationTime();
$result->lastLoginTime = $user->getLastLoginTime();
$result->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleToString($user->getAvatarStyle());
$result->banned = $user->isBanned();
if ($this->privilegeService->isLoggedIn($user))
{

View file

@ -18,6 +18,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
'avatarStyle' => $entity->getAvatarStyle(),
'browsingSettings' => $entity->getBrowsingSettings(),
'accountConfirmed' => $entity->isAccountConfirmed(),
'banned' => $entity->isBanned(),
];
}
@ -34,6 +35,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
$entity->setAvatarStyle(intval($array['avatarStyle']));
$entity->setBrowsingSettings($array['browsingSettings']);
$entity->setAccountConfirmed($array['accountConfirmed']);
$entity->setBanned($array['banned']);
return $entity;
}
}

View file

@ -26,6 +26,7 @@ final class User extends Entity
protected $avatarStyle;
protected $browsingSettings;
protected $accountConfirmed = false;
protected $banned = false;
public function getName()
{
@ -57,6 +58,16 @@ final class User extends Entity
$this->emailUnconfirmed = $emailUnconfirmed;
}
public function isBanned()
{
return $this->banned;
}
public function setBanned($banned)
{
$this->banned = boolval($banned);
}
public function isAccountConfirmed()
{
return $this->accountConfirmed;

View file

@ -10,6 +10,7 @@ class UserEditFormData implements \Szurubooru\IValidatable
public $avatarStyle;
public $avatarContent;
public $browsingSettings;
public $banned;
public function __construct($inputReader = null)
{
@ -24,6 +25,7 @@ class UserEditFormData implements \Szurubooru\IValidatable
$this->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleFromString($inputReader->avatarStyle);
$this->avatarContent = $inputReader->decodeBase64($inputReader->avatarContent);
$this->browsingSettings = $inputReader->browsingSettings;
$this->banned = boolval($inputReader->banned);
}
}

View file

@ -17,6 +17,7 @@ class Privilege
const CHANGE_ALL_PASSWORDS = 'changeAllPasswords';
const DELETE_OWN_ACCOUNT = 'deleteOwnAccount';
const DELETE_ALL_ACCOUNTS = 'deleteAllAccounts';
const BAN = 'ban';
const LIST_SAFE_POSTS = 'listSafePosts';
const LIST_SKETCHY_POSTS = 'listSketchyPosts';

View file

@ -101,5 +101,8 @@ class AuthService
{
if (!$user->isAccountConfirmed() and $this->config->security->needEmailActivationToRegister)
throw new \DomainException('User didn\'t confirm account yet.');
if ($user->isBanned())
throw new \DomainException('Banned!');
}
}

View file

@ -137,6 +137,9 @@ class UserService
if ($formData->browsingSettings !== null)
$this->updateUserBrowsingSettings($user, $formData->browsingSettings);
if ($formData->banned !== $user->isBanned())
$user->setBanned(boolval($formData->banned));
return $this->userDao->save($user);
};
return $this->transactionManager->commit($transactionFunc);