Skip to content

Commit f8df167

Browse files
committed
Merge branch 'may25' into syncable-scoping
2 parents 215d53d + 7481229 commit f8df167

15 files changed

Lines changed: 246 additions & 86 deletions

.php-cs-fixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
->in([
133133
$project_path . '/src',
134134
])
135+
->exclude('Enums')
135136
->name('*.php')
136137
->notName('*.blade.php')
137138
->ignoreDotFiles(true)

composer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
"ext-json": "*",
2121
"illuminate/support": "^12.0",
2222
"laravel/tinker": "^2.0",
23-
"facade/ignition-contracts": "^1.0.2",
24-
"spatie/ignition": "^1.4",
2523
"ramsey/uuid": "^4.7.3",
2624
"stancl/jobpipeline": "2.0.0-rc5",
2725
"stancl/virtualcolumn": "^1.5.0",

src/Commands/CreateUserWithRLSPolicies.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ class CreateUserWithRLSPolicies extends Command
2222

2323
protected $description = "Creates RLS policies for all tables related to the tenant table. Also creates the RLS user if it doesn't exist yet";
2424

25+
/**
26+
* Force, rather than just enable, the created RLS policies.
27+
*
28+
* By default, table owners bypass RLS policies. When this is enabled,
29+
* they also need the BYPASSRLS permission. If your setup lets you create
30+
* a user with BYPASSRLS, you may prefer leaving this on for additional
31+
* safety. Otherwise, if you can't use BYPASSRLS, you can set this to false
32+
* and depend on the behavior of table owners bypassing RLS automatically.
33+
*
34+
* This setting generally doesn't affect behavior at all with "default"
35+
* setups, however if you have a more custom setup, with additional users
36+
* involved (e.g. central connection user not being the same user that
37+
* creates tables, or the created "RLS user" creating some tables) you
38+
* should take care with how you configure this.
39+
*/
40+
public static bool $forceRls = true;
41+
2542
public function handle(PermissionControlledPostgreSQLSchemaManager $manager): int
2643
{
2744
$username = config('tenancy.rls.user.username');
@@ -49,14 +66,9 @@ protected function enableRLS(string $table): void
4966
// Enable RLS scoping on the table (without this, queries won't be scoped using RLS)
5067
DB::statement("ALTER TABLE {$table} ENABLE ROW LEVEL SECURITY");
5168

52-
/**
53-
* Force RLS scoping on the table, so that the table owner users
54-
* don't bypass the scoping – table owners bypass RLS by default.
55-
*
56-
* E.g. when using a custom implementation where you create tables as the RLS user,
57-
* the queries won't be scoped for the RLS user unless we force the RLS scoping using this query.
58-
*/
59-
DB::statement("ALTER TABLE {$table} FORCE ROW LEVEL SECURITY");
69+
if (static::$forceRls) {
70+
DB::statement("ALTER TABLE {$table} FORCE ROW LEVEL SECURITY");
71+
}
6072
}
6173

6274
/**

src/Contracts/TenantCouldNotBeIdentifiedException.php

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,11 @@
55
namespace Stancl\Tenancy\Contracts;
66

77
use Exception;
8-
use Spatie\ErrorSolutions\Contracts\BaseSolution;
9-
use Spatie\ErrorSolutions\Contracts\ProvidesSolution;
108

11-
abstract class TenantCouldNotBeIdentifiedException extends Exception implements ProvidesSolution
9+
abstract class TenantCouldNotBeIdentifiedException extends Exception
1210
{
13-
/** Default solution title. */
14-
protected string $solutionTitle = 'Tenant could not be identified';
15-
16-
/** Default solution description. */
17-
protected string $solutionDescription = 'Are you sure this tenant exists?';
18-
19-
/** Set the message. */
20-
protected function tenantCouldNotBeIdentified(string $how): static
11+
protected function tenantCouldNotBeIdentified(string $how): void
2112
{
2213
$this->message = 'Tenant could not be identified ' . $how;
23-
24-
return $this;
25-
}
26-
27-
/** Set the solution title. */
28-
protected function title(string $solutionTitle): static
29-
{
30-
$this->solutionTitle = $solutionTitle;
31-
32-
return $this;
33-
}
34-
35-
/** Set the solution description. */
36-
protected function description(string $solutionDescription): static
37-
{
38-
$this->solutionDescription = $solutionDescription;
39-
40-
return $this;
41-
}
42-
43-
/** Get the Ignition description. */
44-
public function getSolution(): BaseSolution
45-
{
46-
return BaseSolution::create($this->solutionTitle)
47-
->setSolutionDescription($this->solutionDescription)
48-
->setDocumentationLinks([
49-
'Tenants' => 'https://tenancyforlaravel.com/docs/v3/tenants',
50-
'Tenant Identification' => 'https://tenancyforlaravel.com/docs/v3/tenant-identification',
51-
]);
5214
}
5315
}

src/Enums/RouteMode.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
namespace Stancl\Tenancy\Enums;
66

7-
enum RouteMode
7+
/**
8+
* Note: The backing values are not part of the public API and are subject to change.
9+
*/
10+
enum RouteMode: int
811
{
9-
case TENANT;
10-
case CENTRAL;
11-
case UNIVERSAL;
12+
case CENTRAL = 0b01;
13+
case TENANT = 0b10;
14+
case UNIVERSAL = 0b11;
1215
}

src/Exceptions/TenantColumnNotWhitelistedException.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class TenantColumnNotWhitelistedException extends TenantCouldNotBeIdentifiedExce
1010
{
1111
public function __construct(int|string $tenant_id)
1212
{
13-
$this
14-
->tenantCouldNotBeIdentified("on path with tenant key: $tenant_id (column not whitelisted)")
15-
->title('Tenant could not be identified on this route because the used column is not whitelisted.')
16-
->description('Please add the column to the list of allowed columns in the PathTenantResolver config.');
13+
$this->tenantCouldNotBeIdentified("on path with tenant key: $tenant_id (column not whitelisted)");
1714
}
1815
}

src/Exceptions/TenantCouldNotBeIdentifiedByIdException.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class TenantCouldNotBeIdentifiedByIdException extends TenantCouldNotBeIdentified
1010
{
1111
public function __construct(int|string $tenant_id)
1212
{
13-
$this
14-
->tenantCouldNotBeIdentified("by tenant key: $tenant_id")
15-
->title('Tenant could not be identified with that key')
16-
->description('Are you sure the key is correct and the tenant exists?');
13+
$this->tenantCouldNotBeIdentified("by tenant key: $tenant_id");
1714
}
1815
}

src/Exceptions/TenantCouldNotBeIdentifiedByPathException.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class TenantCouldNotBeIdentifiedByPathException extends TenantCouldNotBeIdentifi
1010
{
1111
public function __construct(int|string $tenant_id)
1212
{
13-
$this
14-
->tenantCouldNotBeIdentified("on path with tenant key: $tenant_id")
15-
->title('Tenant could not be identified on this path')
16-
->description('Did you forget to create a tenant for this path?');
13+
$this->tenantCouldNotBeIdentified("on path with tenant key: $tenant_id");
1714
}
1815
}

src/Exceptions/TenantCouldNotBeIdentifiedByRequestDataException.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class TenantCouldNotBeIdentifiedByRequestDataException extends TenantCouldNotBeI
1010
{
1111
public function __construct(mixed $payload)
1212
{
13-
$this
14-
->tenantCouldNotBeIdentified("by request data with payload: $payload")
15-
->title('Tenant could not be identified using this request data')
16-
->description('Did you forget to create a tenant with this id?');
13+
$this->tenantCouldNotBeIdentified("by request data with payload: $payload");
1714
}
1815
}

src/Exceptions/TenantCouldNotBeIdentifiedOnDomainException.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class TenantCouldNotBeIdentifiedOnDomainException extends TenantCouldNotBeIdenti
1010
{
1111
public function __construct(string $domain)
1212
{
13-
$this
14-
->tenantCouldNotBeIdentified("on domain $domain")
15-
->title('Tenant could not be identified on this domain')
16-
->description('Did you forget to create a tenant for this domain?');
13+
$this->tenantCouldNotBeIdentified("on domain $domain");
1714
}
1815
}

0 commit comments

Comments
 (0)