{{ message }}
feat: add -g option to shield:user create#1164
Merged
kenjis merged 7 commits intoAug 21, 2024
Merged
Conversation
5 tasks
warcooft
reviewed
Aug 12, 2024
datamweb
reviewed
Aug 12, 2024
Collaborator
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
Member
Author
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))
Member
Author
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))
Member
Author
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); |
Collaborator
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,beta
Member
Author
There 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
Member
Author
|
Lines 113 to 115 in a0fcea8 |
Contributor
c8a94c4 to
56662ca
Compare
warcooft
approved these changes
Aug 20, 2024
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Needs #1162Description
shield:user createGroupModel::isValidGroup()Checklist: