diff --git a/app/Services/MenuBootstrapService.php b/app/Services/MenuBootstrapService.php new file mode 100644 index 0000000..f987bc0 --- /dev/null +++ b/app/Services/MenuBootstrapService.php @@ -0,0 +1,153 @@ + $tenantId, + 'parent_id' => null, + 'name' => '대시보드', + 'url' => '/dashboard', + 'is_active' => 1, + 'sort_order' => 1, + 'hidden' => 0, + 'is_external' => 0, + 'icon' => 'dashboard', + ]); + $menuIds[] = $dashboard->id; + + // 2. 기초정보관리 (최상위) + $baseInfo = Menu::create([ + 'tenant_id' => $tenantId, + 'parent_id' => null, + 'name' => '기초정보관리', + 'url' => '', + 'is_active' => 1, + 'sort_order' => 2, + 'hidden' => 0, + 'is_external' => 0, + 'icon' => 'folder', + ]); + $menuIds[] = $baseInfo->id; + + // 2-1. 제품 관리 (기초정보관리 하위) + $product = Menu::create([ + 'tenant_id' => $tenantId, + 'parent_id' => $baseInfo->id, + 'name' => '제품 관리', + 'url' => '/base/product/lists', + 'is_active' => 1, + 'sort_order' => 1, + 'hidden' => 0, + 'is_external' => 0, + 'icon' => 'inventory', + ]); + $menuIds[] = $product->id; + + // 2-2. 거래처 관리 (기초정보관리 하위) + $client = Menu::create([ + 'tenant_id' => $tenantId, + 'parent_id' => $baseInfo->id, + 'name' => '거래처 관리', + 'url' => '/base/client/lists', + 'is_active' => 1, + 'sort_order' => 2, + 'hidden' => 0, + 'is_external' => 0, + 'icon' => 'business', + ]); + $menuIds[] = $client->id; + + // 2-3. 모델 및 BOM관리 (기초정보관리 하위) + $bom = Menu::create([ + 'tenant_id' => $tenantId, + 'parent_id' => $baseInfo->id, + 'name' => '모델 및 BOM관리', + 'url' => '/base/bom/lists', + 'is_active' => 1, + 'sort_order' => 3, + 'hidden' => 0, + 'is_external' => 0, + 'icon' => 'assignment', + ]); + $menuIds[] = $bom->id; + + // 3. 시스템 관리 (최상위) + $system = Menu::create([ + 'tenant_id' => $tenantId, + 'parent_id' => null, + 'name' => '시스템 관리', + 'url' => '', + 'is_active' => 1, + 'sort_order' => 3, + 'hidden' => 0, + 'is_external' => 0, + 'icon' => 'settings', + ]); + $menuIds[] = $system->id; + + // 3-1. 사용자 관리 (시스템 관리 하위) + $user = Menu::create([ + 'tenant_id' => $tenantId, + 'parent_id' => $system->id, + 'name' => '사용자 관리', + 'url' => '/system/user/lists', + 'is_active' => 1, + 'sort_order' => 1, + 'hidden' => 0, + 'is_external' => 0, + 'icon' => 'people', + ]); + $menuIds[] = $user->id; + + // 3-2. 권한 관리 (시스템 관리 하위) + $permission = Menu::create([ + 'tenant_id' => $tenantId, + 'parent_id' => $system->id, + 'name' => '권한 관리', + 'url' => '/system/permission/lists', + 'is_active' => 1, + 'sort_order' => 2, + 'hidden' => 0, + 'is_external' => 0, + 'icon' => 'lock', + ]); + $menuIds[] = $permission->id; + + // 3-3. 부서 관리 (시스템 관리 하위) + $department = Menu::create([ + 'tenant_id' => $tenantId, + 'parent_id' => $system->id, + 'name' => '부서 관리', + 'url' => '/system/department/lists', + 'is_active' => 1, + 'sort_order' => 3, + 'hidden' => 0, + 'is_external' => 0, + 'icon' => 'corporate_fare', + ]); + $menuIds[] = $department->id; + + return $menuIds; + }); + } +} \ No newline at end of file diff --git a/app/Services/RegisterService.php b/app/Services/RegisterService.php index 9e22a4a..969cd87 100644 --- a/app/Services/RegisterService.php +++ b/app/Services/RegisterService.php @@ -3,11 +3,13 @@ namespace App\Services; use App\Helpers\TenantCodeGenerator; +use App\Models\Commons\Menu; use App\Models\Members\User; use App\Models\Tenants\Tenant; use App\Models\Tenants\TenantUserProfile; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; +use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Role; use Spatie\Permission\PermissionRegistrar; @@ -48,7 +50,10 @@ public static function register(array $params): array ], ]); - // 3. Create User with hashed password and options + // 3. Create default menus for tenant + $menuIds = MenuBootstrapService::createDefaultMenus($tenant->id); + + // 4. Create User with hashed password and options $user = User::create([ 'user_id' => $params['user_id'], 'name' => $params['name'], @@ -60,7 +65,7 @@ public static function register(array $params): array ], ]); - // 4. Create TenantUserProfile (tenant-user mapping) + // 5. Create TenantUserProfile (tenant-user mapping) TenantUserProfile::create([ 'user_id' => $user->id, 'tenant_id' => $tenant->id, @@ -68,11 +73,11 @@ public static function register(array $params): array 'is_active' => 1, // 활성화 ]); - // 5. Set tenant context for permissions + // 6. Set tenant context for permissions app()->bind('tenant_id', fn () => $tenant->id); app(PermissionRegistrar::class)->setPermissionsTeamId($tenant->id); - // 6. Create 'system_manager' role (without menu permissions for now) + // 7. Create 'system_manager' role $role = Role::create([ 'tenant_id' => $tenant->id, 'guard_name' => 'api', @@ -80,10 +85,28 @@ public static function register(array $params): array 'description' => '시스템 관리자', ]); - // 7. Assign system_manager role to user + // 8. Create permissions for each menu and assign to role + $permissions = []; + foreach ($menuIds as $menuId) { + $permName = "menu.{$menuId}"; + + // Use firstOrCreate to avoid duplicate permission errors + $perm = Permission::firstOrCreate([ + 'tenant_id' => $tenant->id, + 'guard_name' => 'api', + 'name' => $permName, + ]); + + $permissions[] = $perm; + } + + // 9. Assign all menu permissions to system_manager role + $role->syncPermissions($permissions); + + // 10. Assign system_manager role to user $user->assignRole($role); - // 8. Return user and tenant data + // 11. Return user and tenant data return [ 'user' => [ 'id' => $user->id, diff --git a/lang/ko/message.php b/lang/ko/message.php index d985bb1..7755c66 100644 --- a/lang/ko/message.php +++ b/lang/ko/message.php @@ -23,7 +23,7 @@ 'login_success' => '로그인 성공', 'logout_success' => '로그아웃 되었습니다.', 'signup_success' => '회원가입이 완료되었습니다.', - 'registered' => '회원가입이 완료되었습니다.', + 'registered' => '회원가입 처리', // 테넌트/컨텍스트 'tenant_switched' => '활성 테넌트가 전환되었습니다.',