QA hardening: security RLS fixes, Flutter 3.47.5 upgrade, UI/validation fixes

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>
This commit is contained in:
2026-09-26 11:52:16 +08:00
parent e49b52949c
commit 3cb980b629
125 changed files with 3420 additions and 2853 deletions
+15 -11
View File
@@ -7,8 +7,8 @@ import 'package:supabase_flutter/supabase_flutter.dart';
import '../brick/cache_helpers.dart';
import '../models/app_settings.dart';
import '../models/duty_schedule.dart';
import '../models/swap_request.dart';
import '../models/duty_schedule.model.dart';
import '../models/swap_request.model.dart';
import 'profile_provider.dart';
import 'supabase_provider.dart';
import 'stream_recovery.dart';
@@ -65,12 +65,12 @@ final dutySchedulesProvider = StreamProvider<List<DutySchedule>>((ref) {
stream: client
.from('duty_schedules')
.stream(primaryKey: ['id'])
.order('start_time'),
.order('start_time', ascending: true),
onPollData: () async {
final data = await client
.from('duty_schedules')
.select()
.order('start_time');
.order('start_time', ascending: true);
return data.map(DutySchedule.fromMap).toList();
},
fromMap: DutySchedule.fromMap,
@@ -89,13 +89,16 @@ final dutySchedulesProvider = StreamProvider<List<DutySchedule>>((ref) {
// Immediate poll so any changes that happened while this provider was
// not alive (e.g. a swap was accepted on another device) are reflected
// right away — before the 3-second periodic timer fires.
// right away — before the periodic timer fires.
wrapper.pollNow();
// Periodic safety-net: keep polling every 3 s so that ownership changes
// Periodic safety-net: keep polling so that ownership changes
// (swap accepted → user_id updated on duty_schedules) are always picked
// up even if Supabase Realtime misses the event.
final dutyRefreshTimer = Timer.periodic(const Duration(seconds: 3), (_) {
// ponytail: was 3 s, i.e. every client re-downloaded the whole table ~20x a
// minute. Realtime is the primary path; 60 s bounds how stale a missed swap
// can get. Tighten only if swaps need faster convergence.
final dutyRefreshTimer = Timer.periodic(const Duration(seconds: 60), (_) {
wrapper.pollNow();
});
ref.onDispose(dutyRefreshTimer.cancel);
@@ -135,7 +138,7 @@ final dutySchedulesForUserProvider =
.eq('user_id', userId)
/* exclude past schedules by ensuring the shift has not ended */
.gte('end_time', nowIso)
.order('start_time')
.order('start_time', ascending: true)
as List<dynamic>;
return rows
.map((r) => DutySchedule.fromMap(r as Map<String, dynamic>))
@@ -201,13 +204,14 @@ final swapRequestsProvider = StreamProvider<List<SwapRequest>>((ref) {
// Immediate poll: fetch fresh data right away so any status changes that
// happened while this provider was not alive are reflected instantly,
// before the 3-second periodic timer fires for the first time.
// before the periodic timer fires for the first time.
wrapper.pollNow();
// Periodic safety-net: keep polling every 3 s to catch any status changes
// Periodic safety-net: keep polling to catch any status changes
// that Supabase Realtime may have missed (e.g. when the swap_requests table
// is not yet in the supabase_realtime publication).
final refreshTimer = Timer.periodic(const Duration(seconds: 3), (_) {
// ponytail: was 3 s (see dutySchedulesProvider); 60 s safety net.
final refreshTimer = Timer.periodic(const Duration(seconds: 60), (_) {
wrapper.pollNow();
});
ref.onDispose(refreshTimer.cancel);