3cb980b629
Security — enforce write authorization server-side (was UI/RPC-only): - it_service_requests RLS: block cross-office read/edit + self-approve (QA-015) - pass_slips RLS: owner can complete but not self-approve (QA-046) - swap_requests RLS: scope select/update to participants + admin (QA-047) - storage: tighten it_service_attachments + task_attachments write/delete (QA-027) - admin_user_management edge function: allow programmers to manage users (QA-016) Fixes: - workforce generator "uncovered shifts" false alarms (QA-043/044) - network-map VLAN + New-location dialog validation, disabled-until-valid (QA-048) - de-flake time-of-day-dependent dashboard metrics test (QA-045) Toolchain: - upgrade to Flutter 3.47.5 / Dart 3.13.4; font_awesome_flutter 11.0.0, flutter_quill 11.6.0, pdfrx 2.6.5; clear resulting deprecations (QA-002) analyze clean; 139 tests pass; web build succeeds. Report + evidence in docs/qa/. Note: also carries the in-progress Brick model cleanup already present in the working tree. QA-001 (AI keys public in the build) is deferred by owner decision. Co-Authored-By: claude-flow <ruv@ruv.net>
105 lines
3.3 KiB
Dart
105 lines
3.3 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../models/network/network_site.dart';
|
|
import '../../models/network/network_location.dart';
|
|
import '../supabase_provider.dart';
|
|
|
|
final networkSitesProvider = FutureProvider<List<NetworkSite>>((ref) async {
|
|
final client = ref.watch(supabaseClientProvider);
|
|
final rows = await client.from('network_sites').select().order('name', ascending: true);
|
|
return (rows as List)
|
|
.map((r) => NetworkSite.fromMap(r as Map<String, dynamic>))
|
|
.toList();
|
|
});
|
|
|
|
final networkLocationsProvider = FutureProvider<List<NetworkLocation>>((ref) async {
|
|
final client = ref.watch(supabaseClientProvider);
|
|
final rows = await client.from('network_locations').select().order('name', ascending: true);
|
|
return (rows as List)
|
|
.map((r) => NetworkLocation.fromMap(r as Map<String, dynamic>))
|
|
.toList();
|
|
});
|
|
|
|
final selectedSiteIdProvider = StateProvider<String?>((ref) => null);
|
|
|
|
class NetworkSitesController {
|
|
NetworkSitesController(this.ref);
|
|
final Ref ref;
|
|
|
|
Future<NetworkSite> createSite({
|
|
required String name,
|
|
String? address,
|
|
String? notes,
|
|
String? createdBy,
|
|
}) async {
|
|
final client = ref.read(supabaseClientProvider);
|
|
final inserted = await client
|
|
.from('network_sites')
|
|
.insert({
|
|
'name': name,
|
|
'address': ?address,
|
|
'notes': ?notes,
|
|
'created_by': ?createdBy,
|
|
})
|
|
.select()
|
|
.single();
|
|
ref.invalidate(networkSitesProvider);
|
|
return NetworkSite.fromMap(inserted);
|
|
}
|
|
|
|
Future<void> updateSite(NetworkSite site) async {
|
|
final client = ref.read(supabaseClientProvider);
|
|
await client.from('network_sites').update(site.toUpdateMap()).eq('id', site.id);
|
|
ref.invalidate(networkSitesProvider);
|
|
}
|
|
|
|
Future<void> deleteSite(String id) async {
|
|
final client = ref.read(supabaseClientProvider);
|
|
await client.from('network_sites').delete().eq('id', id);
|
|
ref.invalidate(networkSitesProvider);
|
|
}
|
|
|
|
Future<NetworkLocation> createLocation({
|
|
required String siteId,
|
|
String? parentId,
|
|
required String name,
|
|
required NetworkLocationKind kind,
|
|
String? positionLabel,
|
|
String? notes,
|
|
}) async {
|
|
final client = ref.read(supabaseClientProvider);
|
|
final inserted = await client
|
|
.from('network_locations')
|
|
.insert({
|
|
'site_id': siteId,
|
|
'parent_id': ?parentId,
|
|
'name': name,
|
|
'kind': kind.wire,
|
|
'position_label': ?positionLabel,
|
|
'notes': ?notes,
|
|
})
|
|
.select()
|
|
.single();
|
|
ref.invalidate(networkLocationsProvider);
|
|
return NetworkLocation.fromMap(inserted);
|
|
}
|
|
|
|
/// Returns an existing root location for the site, or creates a "Main"
|
|
/// location of kind=other if none exist. Used by the device assignment flow
|
|
/// so admins can pick a site without having to think about location hierarchy.
|
|
Future<NetworkLocation> ensureDefaultLocation(String siteId) async {
|
|
final locations = await ref.read(networkLocationsProvider.future);
|
|
for (final l in locations) {
|
|
if (l.siteId == siteId) return l;
|
|
}
|
|
return createLocation(
|
|
siteId: siteId,
|
|
name: 'Main',
|
|
kind: NetworkLocationKind.other,
|
|
);
|
|
}
|
|
}
|
|
|
|
final networkSitesControllerProvider =
|
|
Provider<NetworkSitesController>((ref) => NetworkSitesController(ref));
|