1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 07:54:03 +00:00

Merge branch 'db-users-rewrite' of github.com:stancl/tenancy into db-users-rewrite

This commit is contained in:
Samuel Štancl 2020-04-30 20:48:50 +02:00
commit ea72a7b4c7
5 changed files with 16 additions and 10 deletions

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Stancl\Tenancy\Contracts; namespace Stancl\Tenancy\Contracts;
use Stancl\Tenancy\DatabaseConfig; use Stancl\Tenancy\DatabaseConfig;
@ -7,5 +9,6 @@ use Stancl\Tenancy\DatabaseConfig;
interface ManagesDatabaseUsers interface ManagesDatabaseUsers
{ {
public function createUser(DatabaseConfig $databaseConfig): void; public function createUser(DatabaseConfig $databaseConfig): void;
public function deleteUser(DatabaseConfig $databaseConfig): void; public function deleteUser(DatabaseConfig $databaseConfig): void;
} }

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Stancl\Tenancy; namespace Stancl\Tenancy;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
@ -10,7 +12,7 @@ use Stancl\Tenancy\Contracts\TenantDatabaseManager;
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException; use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
class DatabaseConfig class DatabaseConfig
{ {
/** @var Tenant */ /** @var Tenant */
public $tenant; public $tenant;
@ -104,7 +106,7 @@ class DatabaseConfig
// and it doesn't exist, we'll go for the default DB template. // and it doesn't exist, we'll go for the default DB template.
if (! array_key_exists($name, config('database.connections'))) { if (! array_key_exists($name, config('database.connections'))) {
$name = config('tenancy.database.template_connection') ?? DatabaseManager::$originalDefaultConnectionName; $name = config('tenancy.database.template_connection') ?? DatabaseManager::$originalDefaultConnectionName;
}; }
return $name; return $name;
} }

View file

@ -98,7 +98,7 @@ class DatabaseManager
/** /**
* Check if a tenant can be created. * Check if a tenant can be created.
* *
* @throws TenantCannotBeCreatedException * @throws TenantCannotBeCreatedException
* @throws DatabaseManagerNotRegisteredException * @throws DatabaseManagerNotRegisteredException
* @throws TenantDatabaseAlreadyExistsException * @throws TenantDatabaseAlreadyExistsException
@ -160,7 +160,7 @@ class DatabaseManager
} }
foreach ($afterCreating as $item) { foreach ($afterCreating as $item) {
if (is_object($item) && !$item instanceof Closure) { if (is_object($item) && ! $item instanceof Closure) {
$item->handle($tenant); $item->handle($tenant);
} else { } else {
$item($tenant); $item($tenant);
@ -170,7 +170,7 @@ class DatabaseManager
/** /**
* Delete a tenant's database. * Delete a tenant's database.
* *
* @throws DatabaseManagerNotRegisteredException * @throws DatabaseManagerNotRegisteredException
*/ */
public function deleteDatabase(Tenant $tenant) public function deleteDatabase(Tenant $tenant)

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Stancl\Tenancy\TenantDatabaseManagers; namespace Stancl\Tenancy\TenantDatabaseManagers;
use Stancl\Tenancy\Contracts\ManagesDatabaseUsers; use Stancl\Tenancy\Contracts\ManagesDatabaseUsers;
@ -19,7 +21,7 @@ class PermissionControlledMySQLDatabaseManager extends MySQLDatabaseManager impl
$username = $databaseConfig->getUsername(); $username = $databaseConfig->getUsername();
$hostname = $databaseConfig->connection()['host']; $hostname = $databaseConfig->connection()['host'];
$password = $databaseConfig->getPassword(); $password = $databaseConfig->getPassword();
$this->database()->statement("CREATE USER `{$username}`@`{$hostname}` IDENTIFIED BY `{$password}`"); $this->database()->statement("CREATE USER `{$username}`@`{$hostname}` IDENTIFIED BY `{$password}`");
$grants = implode(', ', static::$grants); $grants = implode(', ', static::$grants);
@ -44,4 +46,4 @@ class PermissionControlledMySQLDatabaseManager extends MySQLDatabaseManager impl
{ {
$this->database()->statement("DROP USER IF EXISTS '{$databaseConfig->username}'"); $this->database()->statement("DROP USER IF EXISTS '{$databaseConfig->username}'");
} }
} }

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
namespace Stancl\Tenancy\Tests; namespace Stancl\Tenancy\Tests;
class DatabaseUsersTest extends TestCase class DatabaseUsersTest extends TestCase
@ -7,18 +9,15 @@ class DatabaseUsersTest extends TestCase
/** @test */ /** @test */
public function users_are_created_when_permission_controlled_mysql_manager_is_used() public function users_are_created_when_permission_controlled_mysql_manager_is_used()
{ {
} }
/** @test */ /** @test */
public function correct_grants_are_given_to_the_users() public function correct_grants_are_given_to_the_users()
{ {
} }
/** @test */ /** @test */
public function having_existing_databases_without_users_and_switching_to_permission_controlled_mysql_manager_doesnt_break_existing_dbs() public function having_existing_databases_without_users_and_switching_to_permission_controlled_mysql_manager_doesnt_break_existing_dbs()
{ {
} }
} }