feat: add -g option to shield:user create#1164
Conversation
| $userModel->addToDefaultGroup($user); | ||
|
|
||
| $this->write('The user is added to the default group.', 'green'); | ||
| } else { |
There was a problem hiding this comment.
What happens if an invalid group is set?
shield:user create -n user1 -e user1@example.com -g xxx
There was a problem hiding this comment.
$ ./spark shield:user create -n user2 -e user2@example.com -g xxx
CodeIgniter v4.5.3 Command Line Tool - Server Time: 2024-08-20 04:13:43 UTC+00:00
Password : password
Password confirmation : password
User "user2" created
[CodeIgniter\Shield\Authorization\AuthorizationException]
xxx is not a valid group.
at VENDORPATH/codeigniter4/shield/src/Authorization/AuthorizationException.php:24
Backtrace:
1 VENDORPATH/codeigniter4/shield/src/Authorization/Traits/Authorizable.php:50
CodeIgniter\Shield\Authorization\AuthorizationException::forUnknownGroup('xxx')
2 VENDORPATH/codeigniter4/shield/src/Commands/User.php:324
CodeIgniter\Shield\Entities\User()->addGroup('xxx')
3 VENDORPATH/codeigniter4/shield/src/Commands/User.php:163
CodeIgniter\Shield\Commands\User()->create('user2', 'user2@example.com', 'xxx')
4 SYSTEMPATH/CLI/Commands.php:70
CodeIgniter\Shield\Commands\User()->run([...])
5 SYSTEMPATH/CLI/Console.php:48
CodeIgniter\CLI\Commands()->run('shield:user', [...])
6 SYSTEMPATH/Boot.php:351
CodeIgniter\CLI\Console()->run()
7 SYSTEMPATH/Boot.php:104
CodeIgniter\Boot::runCommand(Object(CodeIgniter\CLI\Console))
8 ROOTPATH/spark:84
CodeIgniter\Boot::bootSpark(Object(Config\Paths))There was a problem hiding this comment.
The above is not good, but the same as addgroup.
$ ./spark shield:user addgroup -n user1 -g mygroup
CodeIgniter v4.5.3 Command Line Tool - Server Time: 2024-08-20 04:12:13 UTC+00:00
Add the user "user1" to the group "mygroup" ? [y, n]: y
[CodeIgniter\Shield\Authorization\AuthorizationException]
mygroup is not a valid group.
at VENDORPATH/codeigniter4/shield/src/Authorization/AuthorizationException.php:24
Backtrace:
1 VENDORPATH/codeigniter4/shield/src/Authorization/Traits/Authorizable.php:50
CodeIgniter\Shield\Authorization\AuthorizationException::forUnknownGroup('mygroup')
2 VENDORPATH/codeigniter4/shield/src/Commands/User.php:600
CodeIgniter\Shield\Entities\User()->addGroup('mygroup')
3 VENDORPATH/codeigniter4/shield/src/Commands/User.php:195
CodeIgniter\Shield\Commands\User()->addgroup('mygroup', 'user1', null)
4 SYSTEMPATH/CLI/Commands.php:70
CodeIgniter\Shield\Commands\User()->run([...])
5 SYSTEMPATH/CLI/Console.php:48
CodeIgniter\CLI\Commands()->run('shield:user', [...])
6 SYSTEMPATH/Boot.php:351
CodeIgniter\CLI\Console()->run()
7 SYSTEMPATH/Boot.php:104
CodeIgniter\Boot::runCommand(Object(CodeIgniter\CLI\Console))
8 ROOTPATH/spark:84
CodeIgniter\Boot::bootSpark(Object(Config\Paths))There was a problem hiding this comment.
Added checking the group name.
$ ./spark shield:user create -n user2 -e user2@example.com -g xxx
CodeIgniter v4.5.4 Command Line Tool - Server Time: 2024-08-20 06:02:07 UTC+00:00
Password : password
Password confirmation : password
Invalid group: "xxx"|
|
||
| $this->write('The user is added to the default group.', 'green'); | ||
| } else { | ||
| $user->addGroup($group); |
There was a problem hiding this comment.
I prefer to be able to set up multiple groups. For example:
$user->addGroup('admin', 'beta');shield:user create -n user1 -e user1@example.com -g admin,betaThere was a problem hiding this comment.
This is another enhancement.
If we add this, it is better to change all -g option.
shield:user create -n newusername -e newuser@example.com -g mygroup
shield:user addgroup -n username -g mygroup
shield:user removegroup -n username -g mygroup
|
Lines 113 to 115 in a0fcea8 |
|
What do you think about adding interactions to show users a step-by-step guide. i created a similar command in a personal project to create a user like this. Complete the following form:
-----------------------------
User Name : Emilia
User Email : foo@example.com
User Group : admin
New Password : 12345678
Confirm Password : 12345678
Account created!
----------------
Name Emilia
Email foo@example.com
Group admin
Password 12345678
Done. |
c8a94c4 to
56662ca
Compare
Needs #1162Description
shield:user createGroupModel::isValidGroup()Checklist: