-
Notifications
You must be signed in to change notification settings - Fork 1
[55] additional admins migrations #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
df4924e
b8a9963
2651b37
f52446e
e8338dd
fb258ec
54358a9
73cc686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Hash; | ||
use RonasIT\Support\Traits\MigrationTrait; | ||
|
||
class {{ $migrationName }} extends Migration | ||
{ | ||
use MigrationTrait; | ||
|
||
public function up(): void | ||
{ | ||
if (!App::environment('testing')) { | ||
DB::table('admins')->insert([ | ||
'email' => '{{ $email }}', | ||
'password' => Hash::make('{{ $password }}'), | ||
]); | ||
} | ||
} | ||
|
||
public function down(): void | ||
{ | ||
if (!App::environment('testing')) { | ||
DB::table('admins') | ||
->where('email', '{{ $email }}') | ||
->delete(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -261,29 +261,21 @@ protected function setAutoDocContactEmail(string $email): void | |||||||
$config->write(); | ||||||||
} | ||||||||
|
||||||||
protected function createAdminUser(string $kebabName): void | ||||||||
protected function createAdminUser(string $kebabName, string $serviceName = '', string $adminPrefix = 'an'): array | ||||||||
{ | ||||||||
$adminEmail = $serviceName ? "admin.{$serviceName}@{$kebabName}.com" : "admin@{$kebabName}.com"; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
$defaultPassword = substr(md5(uniqid()), 0, 8); | ||||||||
|
||||||||
$this->adminCredentials = [ | ||||||||
'email' => $this->ask('Please enter an admin email', "admin@{$kebabName}.com"), | ||||||||
'password' => $this->ask('Please enter an admin password', $defaultPassword), | ||||||||
$adminCredentials = [ | ||||||||
'email' => $this->ask("Please enter {$adminPrefix} admin email", $adminEmail), | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
'password' => $this->ask("Please enter {$adminPrefix} admin password", $defaultPassword), | ||||||||
]; | ||||||||
|
||||||||
if ($this->authType === AuthTypeEnum::Clerk) { | ||||||||
$this->publishMigration( | ||||||||
view: view('initializator::admins_create_table')->with($this->adminCredentials), | ||||||||
migrationName: 'admins_create_table', | ||||||||
); | ||||||||
} else { | ||||||||
$this->adminCredentials['name'] = $this->ask('Please enter an admin name', 'Admin'); | ||||||||
$this->adminCredentials['role_id'] = $this->ask('Please enter an admin role id', RoleEnum::Admin->value); | ||||||||
|
||||||||
$this->publishMigration( | ||||||||
view: view('initializator::add_default_user')->with($this->adminCredentials), | ||||||||
migrationName: 'add_default_user', | ||||||||
); | ||||||||
if (!$serviceName) { | ||||||||
$this->adminCredentials = $adminCredentials; | ||||||||
} | ||||||||
|
||||||||
return $this->publishAdminMigration($adminCredentials, $adminPrefix, $serviceName); | ||||||||
} | ||||||||
|
||||||||
protected function fillReadme(): void | ||||||||
|
@@ -402,18 +394,15 @@ protected function fillCredentialsAndAccess(string $kebabName): void | |||||||
continue; | ||||||||
} | ||||||||
|
||||||||
if (!empty($this->adminCredentials) && $this->confirm("Is {$title}'s admin the same as default one?", true)) { | ||||||||
$email = $this->adminCredentials['email']; | ||||||||
$password = $this->adminCredentials['password']; | ||||||||
if (isset($this->adminCredentials['email']) && $this->confirm("Is {$title}'s admin the same as default one?", true)) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
$adminCredentials['email'] = $this->adminCredentials['email']; | ||||||||
$adminCredentials['password'] = $this->adminCredentials['password']; | ||||||||
Comment on lines
+398
to
+399
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} else { | ||||||||
$defaultPassword = substr(md5(uniqid()), 0, 8); | ||||||||
|
||||||||
$email = $this->ask("Please enter a {$title}'s admin email", "admin@{$kebabName}.com"); | ||||||||
$password = $this->ask("Please enter a {$title}'s admin password", $defaultPassword); | ||||||||
$adminCredentials = $this->createAdminUser($kebabName, $key, "{$title}'s"); | ||||||||
} | ||||||||
|
||||||||
$this->setReadmeValue($filePart, "{$key}_email", $email); | ||||||||
$this->setReadmeValue($filePart, "{$key}_password", $password); | ||||||||
$this->setReadmeValue($filePart, "{$key}_email", $adminCredentials['email']); | ||||||||
$this->setReadmeValue($filePart, "{$key}_password", $adminCredentials['password']); | ||||||||
$this->removeTag($filePart, "{$key}_credentials"); | ||||||||
} | ||||||||
|
||||||||
|
@@ -607,4 +596,41 @@ protected function publishWebLogin(): void | |||||||
|
||||||||
file_put_contents(base_path('routes/web.php'), "\nAuth::routes();\n", FILE_APPEND); | ||||||||
} | ||||||||
|
||||||||
protected function publishAdminMigration(array $adminCredentials, string $adminPrefix, string $serviceName): array | ||||||||
{ | ||||||||
if ($this->authType === AuthTypeEnum::Clerk) { | ||||||||
if (isset($this->adminCredentials['is_table_created'])) { | ||||||||
$viewName = 'admins_add_additional_admin'; | ||||||||
$migrationName = "add_{$serviceName}_admin"; | ||||||||
|
||||||||
$adminCredentials['migrationName'] = Str::studly($migrationName); | ||||||||
} else { | ||||||||
$viewName = $migrationName = 'admins_create_table'; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure that such view is exists. Anyway, let's pusblish migration for the admins table creation outside of this method just after we decided that need to create user with the cleark auth |
||||||||
|
||||||||
$this->adminCredentials['is_table_created'] = true; | ||||||||
} | ||||||||
|
||||||||
$this->publishMigration( | ||||||||
view: view("initializator::{$viewName}")->with($adminCredentials), | ||||||||
migrationName: $migrationName, | ||||||||
); | ||||||||
} else { | ||||||||
$adminCredentials['name'] = $this->ask("Please enter {$adminPrefix} admin name", 'Admin'); | ||||||||
$adminCredentials['role_id'] = $this->ask("Please enter {$adminPrefix} admin role id", RoleEnum::Admin->value); | ||||||||
|
||||||||
$migrationName = !empty($this->adminCredentials) && !$serviceName | ||||||||
? 'add_default_user' | ||||||||
: "add_{$serviceName}_user"; | ||||||||
|
||||||||
$adminCredentials['migrationName'] = Str::studly($migrationName); | ||||||||
|
||||||||
$this->publishMigration( | ||||||||
view: view('initializator::add_default_user')->with($adminCredentials), | ||||||||
migrationName: $migrationName, | ||||||||
); | ||||||||
} | ||||||||
|
||||||||
return $adminCredentials; | ||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.