mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 14:44:05 +00:00
wip fix hardcoded values making assumptions about the parameters used in routing
This commit is contained in:
parent
b278d1f61a
commit
9755bcdc10
5 changed files with 19 additions and 5 deletions
|
|
@ -88,16 +88,17 @@ class FortifyRouteBootstrapper implements TenancyBootstrapper
|
|||
|
||||
protected function useTenantRoutesInFortify(Tenant $tenant): void
|
||||
{
|
||||
$tenantKey = $tenant->getTenantKey();
|
||||
// todo0 this should be just using 'tenant' and the tenant key with query identification - if we can't detect that easily, just add a static property for query id (default false)
|
||||
$tenantParameterName = PathTenantResolver::tenantParameterName();
|
||||
$tenantParameterValue = PathTenantResolver::tenantParameterValue($tenant);
|
||||
|
||||
$generateLink = function (array $redirect) use ($tenantKey, $tenantParameterName) {
|
||||
$generateLink = function (array $redirect) use ($tenantParameterValue, $tenantParameterName) {
|
||||
// Specifying the context is only required with query string identification
|
||||
// because with path identification, the tenant parameter should always present
|
||||
$passTenantParameter = static::$passTenantParameter && $redirect['context'] === Context::TENANT;
|
||||
|
||||
// Only pass the tenant parameter when the user should be redirected to a tenant route
|
||||
return route($redirect['route_name'], $passTenantParameter ? [$tenantParameterName => $tenantKey] : []);
|
||||
return route($redirect['route_name'], $passTenantParameter ? [$tenantParameterName => $tenantParameterValue] : []);
|
||||
};
|
||||
|
||||
// Get redirect URLs for the configured redirect routes
|
||||
|
|
@ -108,7 +109,8 @@ class FortifyRouteBootstrapper implements TenancyBootstrapper
|
|||
|
||||
if (static::$fortifyHome) {
|
||||
// Generate the home route URL with the tenant parameter and make it the Fortify home route
|
||||
$this->config->set('fortify.home', route(static::$fortifyHome, [$tenantParameterName => $tenantKey]));
|
||||
// todo0 this should ALSO be only when static::$passTenantParameter, otherwise [], but shouldn't we also check the context here?
|
||||
$this->config->set('fortify.home', route(static::$fortifyHome, [$tenantParameterName => $tenantParameterValue]));
|
||||
}
|
||||
|
||||
$this->config->set('fortify.redirects', $redirects);
|
||||
|
|
|
|||
|
|
@ -69,7 +69,10 @@ class UrlGeneratorBootstrapper implements TenancyBootstrapper
|
|||
if (static::$addTenantParameterToDefaults) {
|
||||
$defaultParameters = array_merge(
|
||||
$defaultParameters,
|
||||
[PathTenantResolver::tenantParameterName() => $tenant->getTenantKey()]
|
||||
[
|
||||
PathTenantResolver::tenantParameterName() => PathTenantResolver::tenantParameterValue($tenant), // path identification
|
||||
'tenant' => $tenant->getTenantKey(), // query string identification
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ use Illuminate\Routing\Events\RouteMatched;
|
|||
use Stancl\Tenancy\Enums\RouteMode;
|
||||
use Stancl\Tenancy\Resolvers\PathTenantResolver;
|
||||
|
||||
// todo@earlyIdReview
|
||||
|
||||
/**
|
||||
* Remove the tenant parameter from the matched route when path identification is used globally.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ class TenancyUrlGenerator extends UrlGenerator
|
|||
*/
|
||||
protected function prefixRouteName(string $name): string
|
||||
{
|
||||
// todo0 review
|
||||
$tenantPrefix = PathTenantResolver::tenantRouteNamePrefix();
|
||||
|
||||
if (static::$prefixRouteNames && ! str($name)->startsWith($tenantPrefix)) {
|
||||
|
|
@ -166,6 +167,7 @@ class TenancyUrlGenerator extends UrlGenerator
|
|||
*/
|
||||
protected function addTenantParameter(array $parameters): array
|
||||
{
|
||||
// todo0 fix - should use tenantParameterValue(), but with query identification this should just be 'tenant', not even tenantParameterName()
|
||||
return tenant() && static::$passTenantParameterToRoutes ? array_merge($parameters, [PathTenantResolver::tenantParameterName() => tenant()->getTenantKey()]) : $parameters;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,11 @@ class PathTenantResolver extends Contracts\CachedTenantResolver
|
|||
return config('tenancy.identification.resolvers.' . static::class . '.tenant_model_column') ?? tenancy()->model()->getTenantKeyName();
|
||||
}
|
||||
|
||||
public static function tenantParameterValue(Tenant $tenant): string
|
||||
{
|
||||
return $tenant->getAttribute(static::tenantModelColumn());
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public static function allowedExtraModelColumns(): array
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue