1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 20:34:03 +00:00

Merge branch 'master' of github.com:archtechx/tenancy

This commit is contained in:
Samuel Štancl 2023-04-14 17:28:32 +02:00
commit 6a26f712e7
6 changed files with 14 additions and 9 deletions

View file

@ -124,12 +124,12 @@ class TenancyServiceProvider extends ServiceProvider
* Example of CLI tenant URL root override: * Example of CLI tenant URL root override:
* *
* UrlTenancyBootstrapper::$rootUrlOverride = function (Tenant $tenant) { * UrlTenancyBootstrapper::$rootUrlOverride = function (Tenant $tenant) {
* $baseUrl = url('/'); * $baseUrl = env('APP_URL');
* $scheme = str($baseUrl)->before('://'); * $scheme = str($baseUrl)->before('://');
* $hostname = str($baseUrl)->after($scheme . '://'); * $hostname = str($baseUrl)->after($scheme . '://');
* *
* return $scheme . '://' . $tenant->getTenantKey() . '.' . $hostname; * return $scheme . '://' . $tenant->getTenantKey() . '.' . $hostname;
*}; * };
*/ */
} }

View file

@ -20,6 +20,7 @@ return new class extends Migration
$table->string('token', 128)->primary(); $table->string('token', 128)->primary();
$table->string(Tenancy::tenantKeyColumn()); $table->string(Tenancy::tenantKeyColumn());
$table->string('user_id'); $table->string('user_id');
$table->boolean('remember');
$table->string('auth_guard'); $table->string('auth_guard');
$table->string('redirect_url'); $table->string('redirect_url');
$table->timestamp('created_at'); $table->timestamp('created_at');

View file

@ -21,7 +21,7 @@
"facade/ignition-contracts": "^1.0.2", "facade/ignition-contracts": "^1.0.2",
"spatie/ignition": "^1.4", "spatie/ignition": "^1.4",
"ramsey/uuid": "^4.7.3", "ramsey/uuid": "^4.7.3",
"stancl/jobpipeline": "^1.6.2", "stancl/jobpipeline": "2.0.0-rc1",
"stancl/virtualcolumn": "^1.3.1", "stancl/virtualcolumn": "^1.3.1",
"spatie/invade": "^1.1" "spatie/invade": "^1.1"
}, },

View file

@ -18,6 +18,7 @@ use Stancl\Tenancy\Exceptions\StatefulGuardRequiredException;
* @property string $user_id * @property string $user_id
* @property string $auth_guard * @property string $auth_guard
* @property string $redirect_url * @property string $redirect_url
* @property bool $remember
* @property Carbon $created_at * @property Carbon $created_at
*/ */
class ImpersonationToken extends Model class ImpersonationToken extends Model

View file

@ -6,10 +6,12 @@ namespace Stancl\Tenancy\Exceptions;
use Exception; use Exception;
// todo@v4 improve all exception messages
class ModelNotSyncMasterException extends Exception class ModelNotSyncMasterException extends Exception
{ {
public function __construct(string $class) public function __construct(string $class)
{ {
parent::__construct("Model of $class class is not an SyncMaster model. Make sure you're using the central model to make changes to synced resources when you're in the central context"); parent::__construct("Model of $class class is not a SyncMaster model. Make sure you're using the central model to make changes to synced resources when you're in the central context");
} }
} }

View file

@ -18,12 +18,13 @@ class UserImpersonation implements Feature
public function bootstrap(Tenancy $tenancy): void public function bootstrap(Tenancy $tenancy): void
{ {
$tenancy->macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string $authGuard = null): ImpersonationToken { $tenancy->macro('impersonate', function (Tenant $tenant, string $userId, string $redirectUrl, string|null $authGuard = null, bool $remember = false): ImpersonationToken {
return ImpersonationToken::create([ return ImpersonationToken::create([
Tenancy::tenantKeyColumn() => $tenant->getTenantKey(), Tenancy::tenantKeyColumn() => $tenant->getTenantKey(),
'user_id' => $userId, 'user_id' => $userId,
'redirect_url' => $redirectUrl, 'redirect_url' => $redirectUrl,
'auth_guard' => $authGuard, 'auth_guard' => $authGuard,
'remember' => $remember,
]); ]);
}); });
} }
@ -44,7 +45,7 @@ class UserImpersonation implements Feature
abort_unless($tokenTenantId === $currentTenantId, 403); abort_unless($tokenTenantId === $currentTenantId, 403);
Auth::guard($token->auth_guard)->loginUsingId($token->user_id); Auth::guard($token->auth_guard)->loginUsingId($token->user_id, $token->remember);
$token->delete(); $token->delete();