Added user banning
This commit is contained in:
parent
3268618f26
commit
31e0158606
12 changed files with 43 additions and 1 deletions
1
TODO
1
TODO
|
@ -62,7 +62,6 @@ everything related to posts:
|
||||||
(move post snapshot factory methods to PostService)
|
(move post snapshot factory methods to PostService)
|
||||||
|
|
||||||
everything related to users:
|
everything related to users:
|
||||||
- banning
|
|
||||||
- show link to user's uploads
|
- show link to user's uploads
|
||||||
- show link to user's favs
|
- show link to user's favs
|
||||||
- show link to user's liked posts
|
- show link to user's liked posts
|
||||||
|
|
|
@ -38,6 +38,7 @@ changeAllNames = moderator, administrator
|
||||||
changeAllPasswords = moderator, administrator
|
changeAllPasswords = moderator, administrator
|
||||||
changeAccessRank = administrator
|
changeAccessRank = administrator
|
||||||
viewAllEmailAddresses = moderator, administrator
|
viewAllEmailAddresses = moderator, administrator
|
||||||
|
ban = moderator, administrator
|
||||||
|
|
||||||
listSafePosts = anonymous, regularUser, powerUser, moderator, administrator
|
listSafePosts = anonymous, regularUser, powerUser, moderator, administrator
|
||||||
listSketchyPosts = anonymous, regularUser, powerUser, moderator, administrator
|
listSketchyPosts = anonymous, regularUser, powerUser, moderator, administrator
|
||||||
|
|
|
@ -17,6 +17,7 @@ App.Auth = function(_, jQuery, util, api, appState, promise) {
|
||||||
changeAllPasswords: 'changeAllPasswords',
|
changeAllPasswords: 'changeAllPasswords',
|
||||||
deleteOwnAccount: 'deleteOwnAccount',
|
deleteOwnAccount: 'deleteOwnAccount',
|
||||||
deleteAllAccounts: 'deleteAllAccounts',
|
deleteAllAccounts: 'deleteAllAccounts',
|
||||||
|
ban: 'ban',
|
||||||
|
|
||||||
listSafePosts: 'listSafePosts',
|
listSafePosts: 'listSafePosts',
|
||||||
listSketchyPosts: 'listSketchyPosts',
|
listSketchyPosts: 'listSketchyPosts',
|
||||||
|
|
|
@ -22,6 +22,8 @@ App.Presenters.UserAccountSettingsPresenter = function(
|
||||||
target = args.target;
|
target = args.target;
|
||||||
|
|
||||||
privileges = {
|
privileges = {
|
||||||
|
canBan:
|
||||||
|
auth.hasPrivilege(auth.privileges.ban),
|
||||||
canChangeAccessRank:
|
canChangeAccessRank:
|
||||||
auth.hasPrivilege(auth.privileges.changeAccessRank),
|
auth.hasPrivilege(auth.privileges.changeAccessRank),
|
||||||
canChangeAvatarStyle:
|
canChangeAvatarStyle:
|
||||||
|
@ -105,6 +107,9 @@ App.Presenters.UserAccountSettingsPresenter = function(
|
||||||
if (privileges.canChangeAccessRank) {
|
if (privileges.canChangeAccessRank) {
|
||||||
formData.accessRank = $el.find('[name=access-rank]:checked').val();
|
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)) {
|
if (!validateAccountSettingsFormData(formData)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -67,6 +67,19 @@
|
||||||
</div>
|
</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) { %>
|
<% if (canChangeAccessRank) { %>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label class="form-label" for="account-settings-access-rank">Access rank:</label>
|
<label class="form-label" for="account-settings-access-rank">Access rank:</label>
|
||||||
|
|
|
@ -21,6 +21,7 @@ class UserViewProxy extends AbstractViewProxy
|
||||||
$result->registrationTime = $user->getRegistrationTime();
|
$result->registrationTime = $user->getRegistrationTime();
|
||||||
$result->lastLoginTime = $user->getLastLoginTime();
|
$result->lastLoginTime = $user->getLastLoginTime();
|
||||||
$result->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleToString($user->getAvatarStyle());
|
$result->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleToString($user->getAvatarStyle());
|
||||||
|
$result->banned = $user->isBanned();
|
||||||
|
|
||||||
if ($this->privilegeService->isLoggedIn($user))
|
if ($this->privilegeService->isLoggedIn($user))
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
|
||||||
'avatarStyle' => $entity->getAvatarStyle(),
|
'avatarStyle' => $entity->getAvatarStyle(),
|
||||||
'browsingSettings' => $entity->getBrowsingSettings(),
|
'browsingSettings' => $entity->getBrowsingSettings(),
|
||||||
'accountConfirmed' => $entity->isAccountConfirmed(),
|
'accountConfirmed' => $entity->isAccountConfirmed(),
|
||||||
|
'banned' => $entity->isBanned(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
|
||||||
$entity->setAvatarStyle(intval($array['avatarStyle']));
|
$entity->setAvatarStyle(intval($array['avatarStyle']));
|
||||||
$entity->setBrowsingSettings($array['browsingSettings']);
|
$entity->setBrowsingSettings($array['browsingSettings']);
|
||||||
$entity->setAccountConfirmed($array['accountConfirmed']);
|
$entity->setAccountConfirmed($array['accountConfirmed']);
|
||||||
|
$entity->setBanned($array['banned']);
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ final class User extends Entity
|
||||||
protected $avatarStyle;
|
protected $avatarStyle;
|
||||||
protected $browsingSettings;
|
protected $browsingSettings;
|
||||||
protected $accountConfirmed = false;
|
protected $accountConfirmed = false;
|
||||||
|
protected $banned = false;
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -57,6 +58,16 @@ final class User extends Entity
|
||||||
$this->emailUnconfirmed = $emailUnconfirmed;
|
$this->emailUnconfirmed = $emailUnconfirmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isBanned()
|
||||||
|
{
|
||||||
|
return $this->banned;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBanned($banned)
|
||||||
|
{
|
||||||
|
$this->banned = boolval($banned);
|
||||||
|
}
|
||||||
|
|
||||||
public function isAccountConfirmed()
|
public function isAccountConfirmed()
|
||||||
{
|
{
|
||||||
return $this->accountConfirmed;
|
return $this->accountConfirmed;
|
||||||
|
|
|
@ -10,6 +10,7 @@ class UserEditFormData implements \Szurubooru\IValidatable
|
||||||
public $avatarStyle;
|
public $avatarStyle;
|
||||||
public $avatarContent;
|
public $avatarContent;
|
||||||
public $browsingSettings;
|
public $browsingSettings;
|
||||||
|
public $banned;
|
||||||
|
|
||||||
public function __construct($inputReader = null)
|
public function __construct($inputReader = null)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +25,7 @@ class UserEditFormData implements \Szurubooru\IValidatable
|
||||||
$this->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleFromString($inputReader->avatarStyle);
|
$this->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleFromString($inputReader->avatarStyle);
|
||||||
$this->avatarContent = $inputReader->decodeBase64($inputReader->avatarContent);
|
$this->avatarContent = $inputReader->decodeBase64($inputReader->avatarContent);
|
||||||
$this->browsingSettings = $inputReader->browsingSettings;
|
$this->browsingSettings = $inputReader->browsingSettings;
|
||||||
|
$this->banned = boolval($inputReader->banned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ class Privilege
|
||||||
const CHANGE_ALL_PASSWORDS = 'changeAllPasswords';
|
const CHANGE_ALL_PASSWORDS = 'changeAllPasswords';
|
||||||
const DELETE_OWN_ACCOUNT = 'deleteOwnAccount';
|
const DELETE_OWN_ACCOUNT = 'deleteOwnAccount';
|
||||||
const DELETE_ALL_ACCOUNTS = 'deleteAllAccounts';
|
const DELETE_ALL_ACCOUNTS = 'deleteAllAccounts';
|
||||||
|
const BAN = 'ban';
|
||||||
|
|
||||||
const LIST_SAFE_POSTS = 'listSafePosts';
|
const LIST_SAFE_POSTS = 'listSafePosts';
|
||||||
const LIST_SKETCHY_POSTS = 'listSketchyPosts';
|
const LIST_SKETCHY_POSTS = 'listSketchyPosts';
|
||||||
|
|
|
@ -101,5 +101,8 @@ class AuthService
|
||||||
{
|
{
|
||||||
if (!$user->isAccountConfirmed() and $this->config->security->needEmailActivationToRegister)
|
if (!$user->isAccountConfirmed() and $this->config->security->needEmailActivationToRegister)
|
||||||
throw new \DomainException('User didn\'t confirm account yet.');
|
throw new \DomainException('User didn\'t confirm account yet.');
|
||||||
|
|
||||||
|
if ($user->isBanned())
|
||||||
|
throw new \DomainException('Banned!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,9 @@ class UserService
|
||||||
if ($formData->browsingSettings !== null)
|
if ($formData->browsingSettings !== null)
|
||||||
$this->updateUserBrowsingSettings($user, $formData->browsingSettings);
|
$this->updateUserBrowsingSettings($user, $formData->browsingSettings);
|
||||||
|
|
||||||
|
if ($formData->banned !== $user->isBanned())
|
||||||
|
$user->setBanned(boolval($formData->banned));
|
||||||
|
|
||||||
return $this->userDao->save($user);
|
return $this->userDao->save($user);
|
||||||
};
|
};
|
||||||
return $this->transactionManager->commit($transactionFunc);
|
return $this->transactionManager->commit($transactionFunc);
|
||||||
|
|
Loading…
Reference in a new issue