Allow use of same domain in different workspaces
This commit is contained in:
parent
2dbbc38ba4
commit
039b03a5b3
|
@ -24,10 +24,6 @@ class CustomDomainRestriction
|
||||||
|
|
||||||
$customDomain = $request->header(self::CUSTOM_DOMAIN_HEADER);
|
$customDomain = $request->header(self::CUSTOM_DOMAIN_HEADER);
|
||||||
if (!preg_match(CustomDomainRequest::CUSTOM_DOMAINS_REGEX, $customDomain)) {
|
if (!preg_match(CustomDomainRequest::CUSTOM_DOMAINS_REGEX, $customDomain)) {
|
||||||
\Log::info('[CUSTOM_DOMAIN]: Invalid domain', [
|
|
||||||
'domain' => $customDomain,
|
|
||||||
'ip' => $request->ip(),
|
|
||||||
]);
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => 'Invalid domain',
|
'message' => 'Invalid domain',
|
||||||
|
@ -42,11 +38,7 @@ class CustomDomainRestriction
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if domain is known
|
// Check if domain is known
|
||||||
if (!$workspace = Workspace::whereJsonContains('custom_domains',$customDomain)->first()) {
|
if (!$workspaces = Workspace::whereJsonContains('custom_domains',$customDomain)->get()) {
|
||||||
\Log::info('[CUSTOM_DOMAIN]: Unknown domain', [
|
|
||||||
'domain' => $customDomain,
|
|
||||||
'ip' => $request->ip(),
|
|
||||||
]);
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => 'Unknown domain',
|
'message' => 'Unknown domain',
|
||||||
|
@ -54,16 +46,12 @@ class CustomDomainRestriction
|
||||||
], 420);
|
], 420);
|
||||||
}
|
}
|
||||||
|
|
||||||
\Log::info('[CUSTOM_DOMAIN]: Applying scopes', [
|
$workspacesIds = $workspaces->pluck('id')->toArray();
|
||||||
'domain' => $customDomain,
|
Workspace::addGlobalScope('domain-restricted', function (Builder $builder) use ($workspacesIds) {
|
||||||
'ip' => $request->ip(),
|
$builder->whereIn('id', $workspacesIds);
|
||||||
'workspace' => $workspace->id,
|
|
||||||
]);
|
|
||||||
Workspace::addGlobalScope('domain-restricted', function (Builder $builder) use ($workspace) {
|
|
||||||
$builder->where('workspaces.id', $workspace->id);
|
|
||||||
});
|
});
|
||||||
Form::addGlobalScope('domain-restricted', function (Builder $builder) use ($workspace) {
|
Form::addGlobalScope('domain-restricted', function (Builder $builder) use ($workspacesIds) {
|
||||||
$builder->where('forms.workspace_id', $workspace->id);
|
$builder->whereIn('workspace_id', $workspacesIds);
|
||||||
});
|
});
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|
|
@ -41,10 +41,7 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
||||||
if (!customDomainAllowedRoutes.includes(to.name)) {
|
if (!customDomainAllowedRoutes.includes(to.name)) {
|
||||||
// Custom domain only allowed for form url
|
// Custom domain only allowed for form url
|
||||||
return redirectToMainDomain({
|
return redirectToMainDomain({
|
||||||
reason: 'route_not_allowed',
|
reason: 'route_not_allowed'
|
||||||
route: to,
|
|
||||||
from: from,
|
|
||||||
customDomainAllowedRoutes: customDomainAllowedRoutes
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue