1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 16:24:04 +00:00

Postgres RLS + permission controlled database managers (#33)

This PR adds Postgres RLS (trait manager + table manager approach) and permission controlled managers for PostgreSQL.

---------

Co-authored-by: lukinovec <lukinovec@gmail.com>
Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
This commit is contained in:
Samuel Štancl 2024-04-24 22:32:49 +02:00 committed by GitHub
parent 34297d3e1a
commit 7317d2638a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 2511 additions and 112 deletions

15
tests/RLS/Etc/Article.php Normal file
View file

@ -0,0 +1,15 @@
<?php
namespace Stancl\Tenancy\Tests\RLS\Etc;
use Illuminate\Database\Eloquent\Model;
use Stancl\Tenancy\Database\Concerns\BelongsToTenant;
use Stancl\Tenancy\Database\Concerns\RLSModel;
/** Used for testing TraitRLSManager */
class Article extends Model implements RLSModel
{
use BelongsToTenant;
protected $guarded = [];
}

27
tests/RLS/Etc/Comment.php Normal file
View file

@ -0,0 +1,27 @@
<?php
namespace Stancl\Tenancy\Tests\RLS\Etc;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Stancl\Tenancy\Database\Concerns\BelongsToPrimaryModel;
use Stancl\Tenancy\Database\Concerns\RLSModel;
class Comment extends Model implements RLSModel
{
use BelongsToPrimaryModel;
public $guarded = [];
public $table = 'comments';
public function getRelationshipToPrimaryModel(): string
{
return 'post';
}
public function post(): BelongsTo
{
return $this->belongsTo(Post::class, 'post_id');
}
}

25
tests/RLS/Etc/Post.php Normal file
View file

@ -0,0 +1,25 @@
<?php
namespace Stancl\Tenancy\Tests\RLS\Etc;
use Illuminate\Database\Eloquent\Model;
use Stancl\Tenancy\Database\Concerns\RLSModel;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Stancl\Tenancy\Database\Concerns\BelongsToTenant;
/** Used for testing TraitRLSManager */
class Post extends Model implements RLSModel
{
use BelongsToTenant;
public $table = 'posts';
public $timestamps = false;
protected $guarded = [];
public function comments(): HasMany
{
return $this->hasMany(Comment::class, 'post_id');
}
}