feat: 재고 상태 전이 플래그 적용 및 실패 메시지 정비
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../core/constants/app_sections.dart';
|
||||
import '../../../../core/network/failure.dart';
|
||||
import '../../../../core/permissions/permission_manager.dart';
|
||||
import '../../../../core/permissions/permission_resources.dart';
|
||||
import '../../../masters/group/domain/entities/group.dart';
|
||||
import '../../../masters/group/domain/repositories/group_repository.dart';
|
||||
import '../../../masters/group_permission/application/permission_synchronizer.dart';
|
||||
import '../../../masters/group_permission/domain/repositories/group_permission_repository.dart';
|
||||
|
||||
/// Superport 로그인 화면. 간단한 유효성 검증 후 대시보드로 이동한다.
|
||||
class LoginPage extends StatefulWidget {
|
||||
@@ -58,6 +67,24 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
try {
|
||||
await _synchronizePermissions();
|
||||
} catch (error) {
|
||||
if (!mounted) return;
|
||||
final failure = Failure.from(error);
|
||||
final description = failure.describe();
|
||||
final message = description.isEmpty
|
||||
? '권한 정보를 불러오지 못했습니다. 잠시 후 다시 시도하세요.'
|
||||
: description;
|
||||
setState(() {
|
||||
errorMessage = message;
|
||||
isLoading = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
setState(() => isLoading = false);
|
||||
context.go(dashboardRoutePath);
|
||||
}
|
||||
|
||||
@@ -222,6 +249,13 @@ class _LoginPageState extends State<LoginPage> {
|
||||
],
|
||||
),
|
||||
),
|
||||
if (kDebugMode) ...[
|
||||
const SizedBox(height: 12),
|
||||
ShadButton.ghost(
|
||||
onPressed: isLoading ? null : _handleTestLogin,
|
||||
child: const Text('테스트 로그인'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -250,4 +284,73 @@ class _LoginPageState extends State<LoginPage> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 디버그 모드에서 모든 권한을 부여하고 즉시 대시보드로 이동한다.
|
||||
void _handleTestLogin() {
|
||||
final manager = PermissionScope.of(context);
|
||||
manager.clearServerPermissions();
|
||||
|
||||
final allActions = PermissionAction.values.toSet();
|
||||
final overrides = <String, Set<PermissionAction>>{};
|
||||
final dashboardResource = PermissionResources.normalize(dashboardRoutePath);
|
||||
if (dashboardResource.isNotEmpty) {
|
||||
overrides[dashboardResource] = allActions;
|
||||
}
|
||||
for (final page in allAppPages) {
|
||||
final resource = PermissionResources.normalize(page.path);
|
||||
if (resource.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
overrides[resource] = allActions;
|
||||
}
|
||||
manager.updateOverrides(overrides);
|
||||
|
||||
setState(() {
|
||||
errorMessage = null;
|
||||
isLoading = false;
|
||||
});
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
context.go(dashboardRoutePath);
|
||||
}
|
||||
|
||||
Future<void> _synchronizePermissions() async {
|
||||
final manager = PermissionScope.of(context);
|
||||
manager.clearServerPermissions();
|
||||
|
||||
final groupRepository = GetIt.I<GroupRepository>();
|
||||
final defaultGroups = await groupRepository.list(
|
||||
page: 1,
|
||||
pageSize: 1,
|
||||
isDefault: true,
|
||||
);
|
||||
Group? targetGroup = _firstGroupWithId(defaultGroups.items);
|
||||
|
||||
if (targetGroup == null) {
|
||||
final fallbackGroups = await groupRepository.list(page: 1, pageSize: 1);
|
||||
targetGroup = _firstGroupWithId(fallbackGroups.items);
|
||||
}
|
||||
|
||||
if (targetGroup?.id == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final permissionRepository = GetIt.I<GroupPermissionRepository>();
|
||||
final synchronizer = PermissionSynchronizer(
|
||||
repository: permissionRepository,
|
||||
manager: manager,
|
||||
);
|
||||
final groupId = targetGroup!.id!;
|
||||
await synchronizer.syncForGroup(groupId);
|
||||
}
|
||||
|
||||
Group? _firstGroupWithId(List<Group> groups) {
|
||||
for (final group in groups) {
|
||||
if (group.id != null) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user