Add "User::block()" to console command
This commit is contained in:
parent
b4f6e8fda1
commit
0c3f8b124b
|
@ -60,6 +60,8 @@ Usage
|
||||||
bin/console user add [<name> [<nickname> [<email> [<language>]]]] [-h|--help|-?] [-v]
|
bin/console user add [<name> [<nickname> [<email> [<language>]]]] [-h|--help|-?] [-v]
|
||||||
bin/console user allow [<nickname>] [-h|--help|-?] [-v]
|
bin/console user allow [<nickname>] [-h|--help|-?] [-v]
|
||||||
bin/console user deny [<nickname>] [-h|--help|-?] [-v]
|
bin/console user deny [<nickname>] [-h|--help|-?] [-v]
|
||||||
|
bin/console user block [<nickname>] [-h|--help|-?] [-v]
|
||||||
|
bin/console user unblock [<nickname>] [-h|--help|-?] [-v]
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Modify user settings per console commands.
|
Modify user settings per console commands.
|
||||||
|
@ -108,6 +110,10 @@ HELP;
|
||||||
return $this->pendingUser(true);
|
return $this->pendingUser(true);
|
||||||
case 'deny':
|
case 'deny':
|
||||||
return $this->pendingUser(false);
|
return $this->pendingUser(false);
|
||||||
|
case 'block':
|
||||||
|
return $this->blockUser(true);
|
||||||
|
case 'unblock':
|
||||||
|
return $this->blockUser(false);
|
||||||
default:
|
default:
|
||||||
throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.');
|
throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.');
|
||||||
}
|
}
|
||||||
|
@ -210,7 +216,7 @@ HELP;
|
||||||
* @return bool True, if allow was successful
|
* @return bool True, if allow was successful
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function pendingUser(bool $allow = true)
|
private function pendingUser(bool $allow = true)
|
||||||
{
|
{
|
||||||
$nick = $this->getArgument(1);
|
$nick = $this->getArgument(1);
|
||||||
|
|
||||||
|
@ -234,4 +240,32 @@ HELP;
|
||||||
|
|
||||||
return ($allow) ? UserModel::allow($pending['hash']) : UserModel::deny($pending['hash']);
|
return ($allow) ? UserModel::allow($pending['hash']) : UserModel::deny($pending['hash']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blocks/unblocks a user
|
||||||
|
*
|
||||||
|
* @param bool $block True, if the given user should get blocked
|
||||||
|
*
|
||||||
|
* @return bool True, if the command was successful
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
private function blockUser(bool $block = true)
|
||||||
|
{
|
||||||
|
$nick = $this->getArgument(1);
|
||||||
|
|
||||||
|
if (!$nick) {
|
||||||
|
$this->out($this->l10n->t('Enter user nickname: '));
|
||||||
|
$nick = CliPrompt::prompt();
|
||||||
|
if (empty($nick)) {
|
||||||
|
throw new RuntimeException('A nick name must be set.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->dba->selectFirst('user', ['uid'], ['nickname' => $nick]);
|
||||||
|
if (empty($user)) {
|
||||||
|
throw new RuntimeException($this->l10n->t('User not found'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $block ? UserModel::block($user['uid'] ?? 0) : UserModel::block($user['uid'] ?? 0, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -894,7 +894,7 @@ class User
|
||||||
*/
|
*/
|
||||||
public static function block(int $uid, bool $block = true)
|
public static function block(int $uid, bool $block = true)
|
||||||
{
|
{
|
||||||
return DBA::update('user', ['blocked' => 0], ['uid' => $uid]);
|
return DBA::update('user', ['blocked' => $block], ['uid' => $uid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1150,11 +1150,11 @@ class User
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object $uid user to remove
|
* @param int $uid user to remove
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function remove($uid)
|
public static function remove(int $uid)
|
||||||
{
|
{
|
||||||
if (!$uid) {
|
if (!$uid) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -130,14 +130,12 @@ class Users extends BaseAdmin
|
||||||
break;
|
break;
|
||||||
case 'block':
|
case 'block':
|
||||||
parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't');
|
parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't');
|
||||||
// @TODO Move this to Model\User:block([$uid]);
|
User::block($uid);
|
||||||
DBA::update('user', ['blocked' => 1], ['uid' => $uid]);
|
|
||||||
notice(DI::l10n()->t('User "%s" blocked', $user['username']));
|
notice(DI::l10n()->t('User "%s" blocked', $user['username']));
|
||||||
break;
|
break;
|
||||||
case 'unblock':
|
case 'unblock':
|
||||||
parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't');
|
parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't');
|
||||||
// @TODO Move this to Model\User:unblock([$uid]);
|
User::block($uid, false);
|
||||||
DBA::update('user', ['blocked' => 0], ['uid' => $uid]);
|
|
||||||
notice(DI::l10n()->t('User "%s" unblocked', $user['username']));
|
notice(DI::l10n()->t('User "%s" unblocked', $user['username']));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user