mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 14:54:03 +00:00
wip
This commit is contained in:
parent
77c5ae1f32
commit
f13460d91f
3 changed files with 46 additions and 2 deletions
|
|
@ -18,4 +18,6 @@ interface Syncable
|
||||||
|
|
||||||
/** Get the attributes used for creating the *other* model (i.e. tenant if this is the central one, and central if this is the tenant one). */
|
/** Get the attributes used for creating the *other* model (i.e. tenant if this is the central one, and central if this is the tenant one). */
|
||||||
public function getSyncedCreationAttributes(): array|null; // todo come up with a better name
|
public function getSyncedCreationAttributes(): array|null; // todo come up with a better name
|
||||||
|
|
||||||
|
public function shouldSync(): bool;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@ trait ResourceSyncing
|
||||||
public static function bootResourceSyncing(): void
|
public static function bootResourceSyncing(): void
|
||||||
{
|
{
|
||||||
static::saved(function (Syncable $model) {
|
static::saved(function (Syncable $model) {
|
||||||
/** @var ResourceSyncing $model */
|
dump($model->shouldSync());
|
||||||
$model->triggerSyncEvent();
|
if ($model->shouldSync()) {
|
||||||
|
$model->triggerSyncEvent();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
static::creating(function (self $model) {
|
static::creating(function (self $model) {
|
||||||
|
|
@ -37,4 +39,9 @@ trait ResourceSyncing
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shouldSync(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -763,6 +763,25 @@ function creatingResourceInTenantDatabaseCreatesAndMapInCentralDatabase()
|
||||||
expect(ResourceUser::first()->role)->toBe('commenter');
|
expect(ResourceUser::first()->role)->toBe('commenter');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test('resources are synced only when sync is enabled', function () {
|
||||||
|
[$tenant1, $tenant2] = createTenantsAndRunMigrations();
|
||||||
|
|
||||||
|
tenancy()->initialize($tenant1);
|
||||||
|
|
||||||
|
TenantUserWithDisabledSync::create([
|
||||||
|
'global_id' => 'absd',
|
||||||
|
'name' => 'John Doe',
|
||||||
|
'email' => 'john@localhost',
|
||||||
|
'password' => 'password',
|
||||||
|
'role' => 'commenter',
|
||||||
|
]);
|
||||||
|
|
||||||
|
tenancy()->end();
|
||||||
|
|
||||||
|
expect(CentralUser::all())->toHaveCount(0);
|
||||||
|
|
||||||
|
})->group('current');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create two tenants and run migrations for those tenants.
|
* Create two tenants and run migrations for those tenants.
|
||||||
*/
|
*/
|
||||||
|
|
@ -979,3 +998,19 @@ class ResourceUserProvidingMixture extends ResourceUser
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CentralUserWithDisabledSync extends CentralUser
|
||||||
|
{
|
||||||
|
public function shouldSync(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TenantUserWithDisabledSync extends CentralUser
|
||||||
|
{
|
||||||
|
public function shouldSync(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue