feat: add tenant menu visibility
This commit is contained in:
@@ -33,10 +33,14 @@ class TenantBootstrapService
|
|||||||
$tenant,
|
$tenant,
|
||||||
[
|
[
|
||||||
'eventDateChanges',
|
'eventDateChanges',
|
||||||
'menues' => fn ($query) => $query->whereHas(
|
'menues' => fn ($query) => $query
|
||||||
'roles',
|
->where(fn ($query) => $query
|
||||||
fn ($query) => $query->where('codigo', RoleCode::User->value)
|
->where('menues.code', 'help.contact')
|
||||||
),
|
->orWhere('tenants_menues.is_enabled', true))
|
||||||
|
->whereHas(
|
||||||
|
'roles',
|
||||||
|
fn ($query) => $query->where('codigo', RoleCode::User->value)
|
||||||
|
),
|
||||||
$tenant->storefront_website_type_code === 'onticket_multi_event'
|
$tenant->storefront_website_type_code === 'onticket_multi_event'
|
||||||
? 'eventCategories' : 'categories' => fn ($query) => $query->orderBy('nombre'),
|
? 'eventCategories' : 'categories' => fn ($query) => $query->orderBy('nombre'),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class Menu extends Model
|
|||||||
'codigo'
|
'codigo'
|
||||||
)
|
)
|
||||||
->using(TenantMenu::class)
|
->using(TenantMenu::class)
|
||||||
->withPivot('static_content')
|
->withPivot('static_content', 'is_enabled')
|
||||||
->withTimestamps();
|
->withTimestamps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,14 @@ class TenantMenu extends Pivot
|
|||||||
'tenant_code',
|
'tenant_code',
|
||||||
'menu_code',
|
'menu_code',
|
||||||
'static_content',
|
'static_content',
|
||||||
|
'is_enabled',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'static_content' => 'array',
|
'static_content' => 'array',
|
||||||
|
'is_enabled' => 'boolean',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ class Tenant extends Model
|
|||||||
'code'
|
'code'
|
||||||
)
|
)
|
||||||
->using(TenantMenu::class)
|
->using(TenantMenu::class)
|
||||||
->withPivot('static_content')
|
->withPivot('static_content', 'is_enabled')
|
||||||
->withTimestamps();
|
->withTimestamps();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ class EnsureTenantHasMenu
|
|||||||
$tenant = $request->user()?->tenant()->first();
|
$tenant = $request->user()?->tenant()->first();
|
||||||
$hasMenu = $tenant?->menues()
|
$hasMenu = $tenant?->menues()
|
||||||
->where('menues.code', $menuCode)
|
->where('menues.code', $menuCode)
|
||||||
|
->where(fn ($query) => $query
|
||||||
|
->where('menues.code', 'help.contact')
|
||||||
|
->orWhere('tenants_menues.is_enabled', true))
|
||||||
->exists() ?? false;
|
->exists() ?? false;
|
||||||
|
|
||||||
abort_unless($hasMenu, 404);
|
abort_unless($hasMenu, 404);
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenants_menues', function (Blueprint $table): void {
|
||||||
|
$table->boolean('is_enabled')->default(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenants_menues', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn('is_enabled');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
DB::table('menues')
|
||||||
|
->where('code', 'help.terms-and-conditions')
|
||||||
|
->update([
|
||||||
|
'content_type' => 'static',
|
||||||
|
'static_content_schema' => json_encode([
|
||||||
|
'html' => 'present|nullable|string',
|
||||||
|
], JSON_THROW_ON_ERROR),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
DB::table('menues')
|
||||||
|
->where('code', 'help.terms-and-conditions')
|
||||||
|
->update([
|
||||||
|
'content_type' => 'dynamic',
|
||||||
|
'static_content_schema' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -261,7 +261,10 @@ class MenuSeeder extends Seeder
|
|||||||
'code' => 'help.terms-and-conditions',
|
'code' => 'help.terms-and-conditions',
|
||||||
'label' => 'Términos y condiciones',
|
'label' => 'Términos y condiciones',
|
||||||
'parent_menu_code' => 'help',
|
'parent_menu_code' => 'help',
|
||||||
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
'content_type' => Menu::CONTENT_TYPE_STATIC,
|
||||||
|
'static_content_schema' => [
|
||||||
|
'html' => 'present|nullable|string',
|
||||||
|
],
|
||||||
'route' => '/ayuda/terminos-y-condiciones',
|
'route' => '/ayuda/terminos-y-condiciones',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user