Skip to content

Commit

Permalink
Merge pull request #1162 from kenjis/fix-command-user-create-default-…
Browse files Browse the repository at this point in the history
…group

fix: `shield:user create` does not assign a default group
  • Loading branch information
kenjis authored Aug 20, 2024
2 parents 136e0c5 + a7ab351 commit 2554481
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Commands/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ private function create(?string $username = null, ?string $email = null): void
$userModel->save($user);
$this->write('User "' . $username . '" created', 'green');
}

// Add to default group
$user = $userModel->findById($userModel->getInsertID());
$userModel->addToDefaultGroup($user);

$this->write('The user is added to the default group.', 'green');
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/Commands/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Tests\Commands;

use CodeIgniter\Shield\Commands\User;
use CodeIgniter\Shield\Config\AuthGroups;
use CodeIgniter\Shield\Entities\User as UserEntity;
use CodeIgniter\Shield\Models\UserModel;
use CodeIgniter\Shield\Test\MockInputOutput;
Expand Down Expand Up @@ -93,6 +94,10 @@ public function testCreate(): void
'id' => $user->id,
'active' => 0,
]);
$this->seeInDatabase($this->tables['groups_users'], [
'user_id' => $user->id,
'group' => config(AuthGroups::class)->defaultGroup,
]);
}

public function testCreateNotUniqueName(): void
Expand Down

0 comments on commit 2554481

Please sign in to comment.