1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Joas Schilling <[email protected]> |
6
|
|
|
* @author Roeland Jago Douma <[email protected]> |
7
|
|
|
* @author Thomas Müller <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @license AGPL-3.0 |
10
|
|
|
* |
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
13
|
|
|
* as published by the Free Software Foundation. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
namespace OC\Core\Command\User; |
25
|
|
|
|
26
|
|
|
use OC\Core\Command\Base; |
27
|
|
|
use OCP\IUser; |
28
|
|
|
use OCP\IUserManager; |
29
|
|
|
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
30
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
31
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
32
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
33
|
|
|
|
34
|
|
|
class Enable extends Base { |
35
|
|
|
/** @var IUserManager */ |
36
|
|
|
protected $userManager; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param IUserManager $userManager |
40
|
|
|
*/ |
41
|
|
|
public function __construct(IUserManager $userManager) { |
42
|
|
|
$this->userManager = $userManager; |
43
|
|
|
parent::__construct(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function configure() { |
47
|
|
|
$this |
48
|
|
|
->setName('user:enable') |
49
|
|
|
->setDescription('enables the specified user') |
50
|
|
|
->addArgument( |
51
|
|
|
'uid', |
52
|
|
|
InputArgument::REQUIRED, |
53
|
|
|
'the username' |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int { |
58
|
|
|
$user = $this->userManager->get($input->getArgument('uid')); |
59
|
|
|
if (is_null($user)) { |
60
|
|
|
$output->writeln('<error>User does not exist</error>'); |
61
|
|
|
return 1; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$user->setEnabled(true); |
65
|
|
|
$output->writeln('<info>The specified user is enabled</info>'); |
66
|
|
|
return 0; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $argumentName |
71
|
|
|
* @param CompletionContext $context |
72
|
|
|
* @return string[] |
73
|
|
|
*/ |
74
|
|
|
public function completeArgumentValues($argumentName, CompletionContext $context) { |
75
|
|
|
if ($argumentName === 'uid') { |
76
|
|
|
return array_map( |
77
|
|
|
static fn (IUser $user) => $user->getUID(), |
78
|
|
|
array_filter( |
79
|
|
|
$this->userManager->search($context->getCurrentWord()), |
80
|
|
|
static fn (IUser $user) => !$user->isEnabled() |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
return []; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|