Skip to content

Commit

Permalink
Merge pull request #49 from dmyers/patch-2
Browse files Browse the repository at this point in the history
[2.1] Added support for customizing tenant model
  • Loading branch information
breart authored Feb 11, 2023
2 parents 266c4eb + 0cdb0d0 commit a52e0a5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
11 changes: 11 additions & 0 deletions config/saml2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

return [

/*
|--------------------------------------------------------------------------
| Tenant Model
|--------------------------------------------------------------------------
|
| This will allow you to override the tenant model with your own.
|
*/

'tenantModel' => \Slides\Saml2\Models\Tenant::class,

/*
|--------------------------------------------------------------------------
| Use built-in routes
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/CreateTenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Slides\Saml2\Commands;

use Slides\Saml2\Helpers\ConsoleHelper;
use Slides\Saml2\Models\Tenant;
use Slides\Saml2\Repositories\TenantRepository;

/**
Expand Down Expand Up @@ -93,7 +94,8 @@ public function handle()
return;
}

$tenant = new \Slides\Saml2\Models\Tenant([
$class = config('saml2.tenantModel', Tenant::class);
$tenant = new $class([
'key' => $key,
'uuid' => \Ramsey\Uuid\Uuid::uuid4(),
'idp_entity_id' => $entityId,
Expand Down
7 changes: 4 additions & 3 deletions src/Commands/RendersTenants.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Slides\Saml2\Commands;

use Slides\Saml2\Models\Tenant;
use Illuminate\Support\Str;

/**
Expand All @@ -22,7 +23,7 @@ trait RendersTenants
protected function renderTenants($tenants, string $title = null)
{
/** @var \Slides\Saml2\Models\Tenant[]|\Illuminate\Database\Eloquent\Collection $tenants */
$tenants = $tenants instanceof \Slides\Saml2\Models\Tenant
$tenants = $tenants instanceof Tenant
? collect([$tenants])
: $tenants;

Expand Down Expand Up @@ -53,7 +54,7 @@ protected function renderTenants($tenants, string $title = null)
*
* @return array
*/
protected function getTenantColumns(\Slides\Saml2\Models\Tenant $tenant)
protected function getTenantColumns(Tenant $tenant)
{
return [
'ID' => $tenant->id,
Expand All @@ -79,7 +80,7 @@ protected function getTenantColumns(\Slides\Saml2\Models\Tenant $tenant)
*
* @return void
*/
protected function renderTenantCredentials(\Slides\Saml2\Models\Tenant $tenant)
protected function renderTenantCredentials(Tenant $tenant)
{
$this->output->section('Credentials for the tenant');

Expand Down
3 changes: 2 additions & 1 deletion src/Repositories/TenantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class TenantRepository
*/
public function query(bool $withTrashed = false)
{
$query = Tenant::query();
$class = config('saml2.tenantModel', Tenant::class);
$query = $class::query();

if($withTrashed) {
$query->withTrashed();
Expand Down
7 changes: 4 additions & 3 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ protected function bootRoutes()
*/
protected function bootPublishes()
{
$this->publishes([
__DIR__ . '/../config/saml2.php' => config_path('saml2.php'),
]);
$source = __DIR__ . '/../config/saml2.php';

$this->publishes([$source => config_path('saml2.php')]);
$this->mergeConfigFrom($source, 'saml2');
}

/**
Expand Down

0 comments on commit a52e0a5

Please sign in to comment.