Fix FLEXIAPI-415 Add endpoints to activate/deactivate phone countries

This commit is contained in:
Timothée Jaussoin 2025-12-09 16:13:20 +01:00
parent 25ddd330c1
commit d179d0f6df
4 changed files with 57 additions and 4 deletions

View file

@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\Api\Admin;
use App\Http\Controllers\Controller;
use App\PhoneCountry;
class PhoneCountryController extends Controller
{
public function activate(string $code)
{
$phoneCountry = PhoneCountry::where('code', $code)->firstOrFail();
return PhoneCountry::where('country_code', $phoneCountry->country_code)->update(['activated' => true]);
}
public function deactivate(string $code)
{
$phoneCountry = PhoneCountry::where('code', $code)->firstOrFail();
return PhoneCountry::where('country_code', $phoneCountry->country_code)->update(['activated' => false]);
}
}

View file

@ -77,6 +77,15 @@ Return the list of Phone Countries and their current status.
If a country is deactivated all the new submitted phones submitted on the platform will be blocked.
### `POST /phone_countries/{code}/activate`
<span class="badge badge-error">Super Admin</span>
Activate a Phone Country
### `POST /phone_countries/{code}/deactivate`
<span class="badge badge-error">Super Admin</span>
Deactivate a Phone Country
@include('api.documentation.statistics')

View file

@ -39,6 +39,7 @@ use App\Http\Controllers\Api\Admin\Account\TypeController;
use App\Http\Controllers\Api\Admin\AccountController as AdminAccountController;
use App\Http\Controllers\Api\Admin\ExternalAccountController;
use App\Http\Controllers\Api\Admin\MessageController;
use App\Http\Controllers\Api\Admin\PhoneCountryController as AdminPhoneCountryController;
use App\Http\Controllers\Api\Admin\Space\CardDavServerController;
use App\Http\Controllers\Api\Admin\Space\ContactsListController;
use App\Http\Controllers\Api\Admin\Space\EmailServerController;
@ -122,6 +123,9 @@ Route::group(['middleware' => ['auth.jwt', 'auth.digest_or_key', 'auth.check_blo
});
Route::apiResource('spaces/{domain}/carddavs', CardDavServerController::class);
Route::post('phone_countries/{code}/activate', [AdminPhoneCountryController::class, 'activate']);
Route::post('phone_countries/{code}/deactivate', [AdminPhoneCountryController::class, 'deactivate']);
});
// Account creation token

View file

@ -34,6 +34,8 @@ class ApiPhoneCountryTest extends TestCase
{
$account = Account::factory()->withConsumedAccountCreationToken()->create();
$account->generateUserApiKey();
$superAdmin = Account::factory()->superAdmin()->create();
$superAdmin->generateUserApiKey();
$frenchPhoneNumber = '+33612121212';
$dutchPhoneNumber = '+31612121212';
@ -50,18 +52,24 @@ class ApiPhoneCountryTest extends TestCase
]);
$this->keyAuthenticated($account)
->json($this->method, $this->routeChangePhone.'/request', [
->json($this->method, $this->routeChangePhone . '/request', [
'phone' => $frenchPhoneNumber
])
->assertStatus(200);
$this->keyAuthenticated($account)
->json($this->method, $this->routeChangePhone.'/request', [
->json($this->method, $this->routeChangePhone . '/request', [
'phone' => $dutchPhoneNumber
])
->assertJsonValidationErrors(['phone']);
PhoneCountry::where('code', 'NL')->update(['activated' => true]);
$this->keyAuthenticated($account)
->post($this->route . '/NL/activate')
->assertStatus(403);
$this->keyAuthenticated($superAdmin)
->post($this->route . '/NL/activate')
->assertStatus(200);
$this->get($this->route)
->assertStatus(200)
@ -71,9 +79,20 @@ class ApiPhoneCountryTest extends TestCase
]);
$this->keyAuthenticated($account)
->json($this->method, $this->routeChangePhone.'/request', [
->json($this->method, $this->routeChangePhone . '/request', [
'phone' => $dutchPhoneNumber
])
->assertStatus(200);
$this->keyAuthenticated($superAdmin)
->post($this->route . '/NL/deactivate')
->assertStatus(200);
$this->get($this->route)
->assertStatus(200)
->assertJsonFragment([
'code' => 'NL',
'activated' => false
]);
}
}