diff --git a/flexiapi/app/Http/Controllers/Api/Admin/PhoneCountryController.php b/flexiapi/app/Http/Controllers/Api/Admin/PhoneCountryController.php new file mode 100644 index 0000000..ab76a46 --- /dev/null +++ b/flexiapi/app/Http/Controllers/Api/Admin/PhoneCountryController.php @@ -0,0 +1,21 @@ +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]); + } +} diff --git a/flexiapi/resources/views/api/documentation_markdown.blade.php b/flexiapi/resources/views/api/documentation_markdown.blade.php index 5b5f5a0..3a2ca99 100644 --- a/flexiapi/resources/views/api/documentation_markdown.blade.php +++ b/flexiapi/resources/views/api/documentation_markdown.blade.php @@ -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` +Super Admin + +Activate a Phone Country + +### `POST /phone_countries/{code}/deactivate` +Super Admin + +Deactivate a Phone Country @include('api.documentation.statistics') diff --git a/flexiapi/routes/api.php b/flexiapi/routes/api.php index 84cb289..8427df4 100644 --- a/flexiapi/routes/api.php +++ b/flexiapi/routes/api.php @@ -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 diff --git a/flexiapi/tests/Feature/ApiPhoneCountryTest.php b/flexiapi/tests/Feature/ApiPhoneCountryTest.php index f433608..d934f38 100644 --- a/flexiapi/tests/Feature/ApiPhoneCountryTest.php +++ b/flexiapi/tests/Feature/ApiPhoneCountryTest.php @@ -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 + ]); } }