Files
cacto 467a05542c CRUD зон/устройств/правил автоматизации + RBAC owner/viewer
Policies (ZonePolicy/DevicePolicy/AutomationRulePolicy): не multi-tenant
изоляция по user_id, а household-wide RBAC — все авторизованные видят одни
и те же данные, только owner может создавать/менять/удалять. user_id на
записи — это created_by, а не граница видимости.

Form Requests с authorize() через политики; DeviceRequest учитывает unique
external_id с ignore на update. AutomationRuleRequest: action_type остаётся
строкой (не enum), т.к. это открытый список из device_types.capabilities;
для действия set_level в форме есть отдельное поле "level" (Alpine.js
переключает его видимость), которое контроллер мапит в action_params —
без сырого JSON-редактора для MVP.

Контроллеры без show (index+create/edit достаточно), Blade-формы на базе
Breeze-компонентов. Навигация и дашборд (счётчики зон/устройств/активных
правил) обновлены. Добавлен DemoGrowboxSeeder (демо-зона с датчиком,
вентилятором и правилом) и viewer-пользователь в сидер.

Восстановлен трейт AuthorizesRequests в базовом Controller (Laravel 11+
убрал его по умолчанию) — нужен для $this->authorize().

Проверено: 33/33 теста (включая новые ZoneControllerTest,
AutomationRuleControllerTest — маппинг level→action_params, 403 для
viewer), полный CRUD-цикл вживую через браузер под owner (создание зоны,
правила с set_level, Alpine-переключение поля "Уровень"), доступ viewer
подтверждён как read-only (нет кнопок изменения, прямой заход на
/zones/create отдаёт 403).
2026-08-11 16:54:26 +05:00

65 lines
3.3 KiB
PHP

<x-app-layout>
<x-slot name="header">
<div class="flex justify-between items-center">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Устройства') }}
</h2>
@can('create', \App\Models\Device::class)
<x-primary-button onclick="window.location='{{ route('devices.create') }}'">
{{ __('Добавить устройство') }}
</x-primary-button>
@endcan
</div>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
@if (session('status'))
<div class="mb-4 text-sm text-green-600">{{ session('status') }}</div>
@endif
<table class="w-full text-left text-sm">
<thead>
<tr class="border-b">
<th class="py-2">{{ __('Название') }}</th>
<th class="py-2">{{ __('Зона') }}</th>
<th class="py-2">{{ __('Тип') }}</th>
<th class="py-2">{{ __('External ID') }}</th>
<th class="py-2">{{ __('Протокол') }}</th>
<th class="py-2"></th>
</tr>
</thead>
<tbody>
@forelse ($devices as $device)
<tr class="border-b">
<td class="py-2">{{ $device->name }}</td>
<td class="py-2">{{ $device->zone->name }}</td>
<td class="py-2">{{ $device->deviceType->code }}</td>
<td class="py-2 font-mono text-xs">{{ $device->external_id }}</td>
<td class="py-2">{{ $device->protocol }}</td>
<td class="py-2 text-right space-x-2">
@can('update', $device)
<a href="{{ route('devices.edit', $device) }}" class="text-indigo-600 hover:underline">{{ __('Изменить') }}</a>
@endcan
@can('delete', $device)
<form method="POST" action="{{ route('devices.destroy', $device) }}" class="inline" onsubmit="return confirm('{{ __('Удалить устройство?') }}')">
@csrf
@method('DELETE')
<button type="submit" class="text-red-600 hover:underline">{{ __('Удалить') }}</button>
</form>
@endcan
</td>
</tr>
@empty
<tr>
<td colspan="6" class="py-4 text-gray-500">{{ __('Устройств пока нет.') }}</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</div>
</x-app-layout>