diff --git a/app/Http/Controllers/V2/User/AdminUserRoleController.php b/app/Http/Controllers/V2/User/AdminUserRoleController.php new file mode 100644 index 000000000..02dce7a6a --- /dev/null +++ b/app/Http/Controllers/V2/User/AdminUserRoleController.php @@ -0,0 +1,45 @@ +authorize('create', User::class); + + $data = $request->all(); + $data = ['role' => $id]; + switch ($request->get('primary_role')) { + case 'admin-super': + case 'admin-ppc': + $data['role'] = 'admin'; + + break; + case 'admin-terrafund': + $data['role'] = 'terrafund_admin'; + + break; + case 'project-developer': + $data['role'] = 'user'; + + break; + } + + $user = User::create($data); + + if (! empty($request->get('primary_role')) && Auth::user()->hasRole('admin-super')) { + $user->syncRoles([$request->get('primary_role')]); + } else { + assignSpatieRole($user); + } + + return new UserResource($user); + } +} diff --git a/routes/api_v2.php b/routes/api_v2.php index fa90dd7df..04cb16ca8 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -181,6 +181,7 @@ use App\Http\Controllers\V2\User\AdminExportUsersController; use App\Http\Controllers\V2\User\AdminResetPasswordController; use App\Http\Controllers\V2\User\AdminUserController; +use App\Http\Controllers\V2\User\AdminUserRoleController; use App\Http\Controllers\V2\User\AdminUserMultiController; use App\Http\Controllers\V2\User\AdminVerifyUserController; use App\Http\Controllers\V2\User\CompleteActionController; @@ -318,6 +319,7 @@ Route::get('export', AdminExportUsersController::class); Route::put('reset-password/{user}', AdminResetPasswordController::class); Route::patch('verify/{user}', AdminVerifyUserController::class); + Route::post('register-user/{id}', AdminUserRoleController::class); }); Route::resource('users', AdminUserController::class);