mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:14:03 +00:00
Update specific attributes of pending tenants while they're being pulled (#59)
* Add option to update attributes of pending tenants while pulling them * Fix failing toEqualCanonicalizing tests * Fix code style (php-cs-fixer) * fix code errors * lock phpcsfixer to 3.62.0 due to a bug in 3.63.1 --------- Co-authored-by: PHP CS Fixer <phpcsfixer@example.com> Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
87e02f207f
commit
6b74589d76
5 changed files with 11 additions and 12 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -130,7 +130,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Install php-cs-fixer
|
- name: Install php-cs-fixer
|
||||||
run: composer global require friendsofphp/php-cs-fixer
|
run: composer global require friendsofphp/php-cs-fixer:3.62.0
|
||||||
- name: Run php-cs-fixer
|
- name: Run php-cs-fixer
|
||||||
run: $HOME/.composer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php
|
run: $HOME/.composer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php
|
||||||
- name: Commit changes from php-cs-fixer
|
- name: Commit changes from php-cs-fixer
|
||||||
|
|
|
||||||
|
|
@ -140,5 +140,6 @@ $finder = Finder::create()
|
||||||
return (new Config())
|
return (new Config())
|
||||||
->setFinder($finder)
|
->setFinder($finder)
|
||||||
->setRules($rules)
|
->setRules($rules)
|
||||||
|
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
|
||||||
->setRiskyAllowed(true)
|
->setRiskyAllowed(true)
|
||||||
->setUsingCache(true);
|
->setUsingCache(true);
|
||||||
|
|
|
||||||
|
|
@ -73,14 +73,14 @@ trait HasPending
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Try to pull a tenant from the pool of pending tenants. */
|
/** Try to pull a tenant from the pool of pending tenants. */
|
||||||
public static function pullPendingFromPool(bool $firstOrCreate = false): ?Tenant
|
public static function pullPendingFromPool(bool $firstOrCreate = false, array $attributes = []): ?Tenant
|
||||||
{
|
{
|
||||||
if (! static::onlyPending()->exists()) {
|
if (! static::onlyPending()->exists()) {
|
||||||
if (! $firstOrCreate) {
|
if (! $firstOrCreate) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static::createPending();
|
static::createPending($attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A pending tenant is surely available at this point
|
// A pending tenant is surely available at this point
|
||||||
|
|
@ -89,9 +89,9 @@ trait HasPending
|
||||||
|
|
||||||
event(new PullingPendingTenant($tenant));
|
event(new PullingPendingTenant($tenant));
|
||||||
|
|
||||||
$tenant->update([
|
$tenant->update(array_merge($attributes, [
|
||||||
'pending_since' => null,
|
'pending_since' => null,
|
||||||
]);
|
]));
|
||||||
|
|
||||||
event(new PendingTenantPulled($tenant));
|
event(new PendingTenantPulled($tenant));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,14 +98,14 @@ test('CloneRoutesAsTenant registers prefixed duplicates of universal routes corr
|
||||||
// Universal flag is excluded from the route middleware
|
// Universal flag is excluded from the route middleware
|
||||||
expect(tenancy()->getRouteMiddleware($newRoutes->first()))
|
expect(tenancy()->getRouteMiddleware($newRoutes->first()))
|
||||||
->toEqualCanonicalizing(
|
->toEqualCanonicalizing(
|
||||||
array_filter(array_merge(tenancy()->getRouteMiddleware($universalRoute), ['tenant']),
|
array_values(array_filter(array_merge(tenancy()->getRouteMiddleware($universalRoute), ['tenant']),
|
||||||
fn($middleware) => $middleware !== 'universal')
|
fn($middleware) => $middleware !== 'universal'))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Universal flag is provided statically in the route's controller, so we cannot exclude it
|
// Universal flag is provided statically in the route's controller, so we cannot exclude it
|
||||||
expect(tenancy()->getRouteMiddleware($newRoutes->last()))
|
expect(tenancy()->getRouteMiddleware($newRoutes->last()))
|
||||||
->toEqualCanonicalizing(
|
->toEqualCanonicalizing(
|
||||||
array_merge(tenancy()->getRouteMiddleware($universalRoute2), ['tenant'])
|
array_values(array_merge(tenancy()->getRouteMiddleware($universalRoute2), ['tenant']))
|
||||||
);
|
);
|
||||||
|
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
|
|
@ -236,7 +236,7 @@ test('routes with the clone flag get cloned without making the routes universal'
|
||||||
|
|
||||||
$clonedRoute = RouteFacade::getRoutes()->getByName('tenant.' . $routeName);
|
$clonedRoute = RouteFacade::getRoutes()->getByName('tenant.' . $routeName);
|
||||||
|
|
||||||
expect($clonedRoute->middleware())->toEqualCanonicalizing(['tenant', $identificationMiddleware]);
|
expect(array_values($clonedRoute->middleware()))->toEqualCanonicalizing(['tenant', $identificationMiddleware]);
|
||||||
|
|
||||||
// The original route is not accessible
|
// The original route is not accessible
|
||||||
pest()->get(route($routeName))->assertServerError();
|
pest()->get(route($routeName))->assertServerError();
|
||||||
|
|
|
||||||
|
|
@ -535,9 +535,7 @@ test('table rls manager generates relationship trees with tables related to the
|
||||||
})->with([true, false]);
|
})->with([true, false]);
|
||||||
|
|
||||||
test('table rls manager generates queries correctly', function() {
|
test('table rls manager generates queries correctly', function() {
|
||||||
$sessionVariableName = config('tenancy.rls.session_variable_name');
|
expect(array_values(app(TableRLSManager::class)->generateQueries()))->toEqualCanonicalizing([
|
||||||
|
|
||||||
expect(app(TableRLSManager::class)->generateQueries())->toEqualCanonicalizing([
|
|
||||||
<<<SQL
|
<<<SQL
|
||||||
CREATE POLICY authors_rls_policy ON authors USING (
|
CREATE POLICY authors_rls_policy ON authors USING (
|
||||||
tenant_id::text = current_setting('my.current_tenant')
|
tenant_id::text = current_setting('my.current_tenant')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue