Skip to content

Commit

Permalink
enables option for language tagging #1178 (#1220)
Browse files Browse the repository at this point in the history
* enables option for language tagging #1178

* update settings tests

* adding routes back
  • Loading branch information
dgershman authored Nov 4, 2024
1 parent 79962f7 commit 67a13cf
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/app/Http/Controllers/Api/V1/Admin/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers\Api\V1\Admin;

use App\Http\Controllers\Controller;
use App\Services\SettingsService;

class SettingsController extends Controller
{
protected SettingsService $settingsService;

public function __construct(SettingsService $settingsService)
{
$this->settingsService = $settingsService;
}

public function index()
{
return response()->json(['languageSelections'=>$this->settingsService->languageSelections()]);
}
}
7 changes: 6 additions & 1 deletion src/app/Services/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SettingsService
'jft_option' => ['description' => '/miscellaneous/playback-for-readings' , 'default' => false, 'overridable' => true, 'hidden' => false],
'language' => ['description' => '/general/language-options' , 'default' => 'en-US', 'overridable' => true, 'hidden' => false],
'language_selections' => ['description' => '/general/language-options', 'default' => null, 'overridable' => true, 'hidden' => false],
'language_selections_tagging' => ['description' => '/general/language-options', 'default' => null, 'overridable' => true, 'hidden' => false],
'location_lookup_bias' => ['description' => '/general/location-lookup-bias' , 'default' => 'country:us', 'overridable' => true, 'hidden' => false],
'meeting_result_sort' => ['description' => '/meeting-search/sorting-results' , 'default' => MeetingResultSort::TODAY, 'overridable' => true, 'hidden' => false],
'meeting_search_radius' => ['description' => '/meeting-search/meeting-search-radius' , 'default' => -50, 'overridable' => true, 'hidden' => false],
Expand Down Expand Up @@ -332,7 +333,11 @@ public function availableLanguages(): array

public function languageSelections(): array
{
return explode(",", $this->get('language_selections'));
if ($this->has('language_selections_tagging') && $this->get('language_selections_tagging') !== "") {
return explode(",", $this->get('language_selections_tagging'));
} else {
return explode(",", $this->get('language_selections'));
}
}

public function getNumberForWord($name)
Expand Down
6 changes: 6 additions & 0 deletions src/docs/docs/general/language-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ static $language_selections = "en-US,pig-latin";

This example will make option 1, English and option 2, pig latin.

You can also tag volunteers ahead of time before enabling the option by using this setting. Either option will work, except this one will not enable the voice prompt menu.

```php
static $language_selections_tagging = "en-US,pig-latin";
```

### Mixing languages and voices

Voices can be configured for every language option. For example for Spanish:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<option value="0">Unassigned</option>
<option value="1">Enabled</option>
</select>
@if ($settings->has('language_selections'))
@if ($settings->has('language_selections_tagging') || $settings->has('language_selections'))
Languages: <select multiple class="form-control form-control-sm" name="volunteer_language" id="volunteer_language">
@foreach ($settings->languageSelections() as $key => $available_language) {
<option value="<?php echo $available_language; ?>"><?php echo $available_language; ?></option>
Expand Down
1 change: 1 addition & 0 deletions src/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Route::resource('reports/metrics', 'MetricController')->only(['index']);
Route::resource('rootServer/servicebodies', 'RootServerServiceBodiesController')->only(['index']);
Route::resource('events/status', 'EventStatusController')->only(['index', 'store']);
Route::resource('settings', 'SettingsController')->only(['index']);
});

if (getenv('ENVIRONMENT') == "test") {
Expand Down
50 changes: 50 additions & 0 deletions src/tests/Feature/SettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use App\Constants\AuthMechanism;
use App\Services\SettingsService;

beforeAll(function () {
putenv("ENVIRONMENT=test");
});

beforeEach(function () {
@session_start();
$_SERVER['REQUEST_URI'] = "/";
$_REQUEST = null;
$_SESSION = null;
});

test('check language selections when not set', function () {
$_SESSION['auth_mechanism'] = AuthMechanism::V2;
$response = $this->call('GET', '/api/v1/settings');
$response
->assertStatus(200)
->assertHeader("Content-Type", "application/json")
->assertJson(["languageSelections"=>[""]]);
});

test('check language selections when set', function () {
$_SESSION['auth_mechanism'] = AuthMechanism::V2;
$settingsService = new SettingsService();
$settingsService->set('language_selections', "en-US,fr-CA");
app()->instance(SettingsService::class, $settingsService);

$response = $this->call('GET', '/api/v1/settings');
$response
->assertStatus(200)
->assertHeader("Content-Type", "application/json")
->assertJson(["languageSelections"=>["en-US", "fr-CA"]]);
});

test('check language selections tagged when set', function () {
$_SESSION['auth_mechanism'] = AuthMechanism::V2;
$settingsService = new SettingsService();
$settingsService->set('language_selections_tagging', "en-US,fr-CA");
app()->instance(SettingsService::class, $settingsService);

$response = $this->call('GET', '/api/v1/settings');
$response
->assertStatus(200)
->assertHeader("Content-Type", "application/json")
->assertJson(["languageSelections"=>["en-US", "fr-CA"]]);
});

0 comments on commit 67a13cf

Please sign in to comment.