Grafia: «Zambézia» com acento e encontrada com ou sem ele; «actividade» no menu
tests / ci (push) Waiting to run
tests / ci (push) Waiting to run
Mapa de erros 4.9. A província passa a chamar-se «Zambézia» (migração que só muda o nome; identificadores e ligações ficam iguais). As correspondências por nome já ignoravam acentos (demografia, referências de fundos, pesquisa pública de territórios); passam a ignorá-los também a pesquisa de territórios da gestão, o registo territorial e a correspondência cartográfica de textos guardados, para que «Zambezia» continue a encontrar a província. O menu passa a «A minha actividade» e «A minha conta e actividade», na grafia do resto do portal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
@@ -18,6 +18,7 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class InvestmentTerritoryController extends Controller
|
||||
@@ -78,8 +79,10 @@ class InvestmentTerritoryController extends Controller
|
||||
$query->where('parent_id', $data['parent_id'] ?? '00000000-0000-0000-0000-000000000000');
|
||||
}
|
||||
if (! empty($data['q'])) {
|
||||
$term = '%'.addcslashes($data['q'], '%_\\').'%';
|
||||
$query->where(fn ($q) => $q->whereRaw('name ILIKE ?', [$term])->orWhereRaw('code ILIKE ?', [$term])->orWhereRaw('source_code ILIKE ?', [$term]));
|
||||
// Accents are ignored, so «Zambezia» still finds «Zambézia».
|
||||
$term = '%'.addcslashes(Str::ascii($data['q']), '%_\\').'%';
|
||||
$query->where(fn ($q) => $q->whereRaw("translate(lower(name), 'áàâãäåéèêëíìîïóòôõöúùûüçýÿ', 'aaaaaaeeeeiiiiooooouuuucyy') ILIKE ?", [$term])
|
||||
->orWhereRaw('code ILIKE ?', [$term])->orWhereRaw('source_code ILIKE ?', [$term]));
|
||||
}
|
||||
|
||||
return response()->json($query->orderBy('name')->orderBy('id')->paginate(100, ['id', 'name', 'parent_id', 'location_type', 'source_code']));
|
||||
|
||||
@@ -72,7 +72,9 @@ class TerritorialRegistryController extends Controller
|
||||
}
|
||||
if (! empty($data['q'])) {
|
||||
$term = '%'.str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], $data['q']).'%';
|
||||
$plain = '%'.str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], Str::ascii($data['q'])).'%';
|
||||
$query->where(fn ($q) => $q->where('g.name', 'ilike', $term)->orWhere('g.code', 'ilike', $term)
|
||||
->orWhereRaw("translate(lower(g.name), 'áàâãäåéèêëíìîïóòôõöúùûüçýÿ', 'aaaaaaeeeeiiiiooooouuuucyy') ILIKE ?", [$plain])
|
||||
->orWhereExists(fn ($n) => $n->selectRaw('1')->from('geo_names')->whereColumn('geo_location_id', 'g.id')->where('name', 'ilike', $term)));
|
||||
}
|
||||
foreach (['parent_id', 'country_id', 'province_id', 'district_id', 'admin_post_id'] as $key) {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Mapa de erros: the province is shown as «Zambézia», the spelling used across the portal. Matching by name
|
||||
* already ignores accents (demography, funding references, public territory search); identifiers do not change.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('geo_locations')->where('location_type', 'province')->where('name', 'Zambezia')->update(['name' => 'Zambézia']);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::table('geo_locations')->where('location_type', 'province')->where('name', 'Zambézia')->update(['name' => 'Zambezia']);
|
||||
}
|
||||
};
|
||||
@@ -67,8 +67,14 @@ export function ProvinceSelect({
|
||||
'Não foi possível consultar a correspondência cartográfica.',
|
||||
);
|
||||
const data = await response.json();
|
||||
// Saved text keeps its spelling; «Zambezia» and «Zambézia» are the same province.
|
||||
const plain = (text: string) =>
|
||||
text
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLocaleLowerCase('pt');
|
||||
const matches = (data.data as Option[]).filter(
|
||||
(option) => option.name === value,
|
||||
(option) => plain(option.name) === plain(value),
|
||||
);
|
||||
if (controller.signal.aborted) return;
|
||||
if (matches.length === 1 && !data.next_page_url)
|
||||
|
||||
@@ -151,7 +151,7 @@ const menuTranslations = [
|
||||
'Manifestaciones de interés y favoritos',
|
||||
],
|
||||
['Notificações', 'Notifications', 'Notifications', 'Notificaciones'],
|
||||
['A minha atividade', 'My activity', 'Mes activités', 'Mi actividad'],
|
||||
['A minha actividade', 'My activity', 'Mes activités', 'Mi actividad'],
|
||||
[
|
||||
'As minhas parcerias',
|
||||
'My partnerships',
|
||||
@@ -186,7 +186,7 @@ const translations: Record<string, Record<string, string>> = {
|
||||
'Siga a Revista Tempo para actualizações exclusivas.':
|
||||
'Follow Revista Tempo for exclusive updates.',
|
||||
'Número de registo': 'Registration number',
|
||||
'A minha conta e atividade': 'My account and activity',
|
||||
'A minha conta e actividade': 'My account and activity',
|
||||
'Área de trabalho': 'Workspace',
|
||||
},
|
||||
fr: {
|
||||
@@ -211,7 +211,7 @@ const translations: Record<string, Record<string, string>> = {
|
||||
'Siga a Revista Tempo para actualizações exclusivas.':
|
||||
'Suivez Revista Tempo pour des actualités exclusives.',
|
||||
'Número de registo': 'Numéro d’enregistrement',
|
||||
'A minha conta e atividade': 'Mon compte et mes activités',
|
||||
'A minha conta e actividade': 'Mon compte et mes activités',
|
||||
'Área de trabalho': 'Espace de travail',
|
||||
},
|
||||
es: {
|
||||
@@ -236,7 +236,7 @@ const translations: Record<string, Record<string, string>> = {
|
||||
'Siga a Revista Tempo para actualizações exclusivas.':
|
||||
'Siga Revista Tempo para recibir novedades exclusivas.',
|
||||
'Número de registo': 'Número de registro',
|
||||
'A minha conta e atividade': 'Mi cuenta y actividad',
|
||||
'A minha conta e actividade': 'Mi cuenta y actividad',
|
||||
'Área de trabalho': 'Área de trabajo',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -791,7 +791,7 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
? [
|
||||
{
|
||||
id: 'personal-activity',
|
||||
label: 'A minha atividade',
|
||||
label: 'A minha actividade',
|
||||
children: [
|
||||
link(
|
||||
'my-partnerships',
|
||||
|
||||
@@ -375,6 +375,22 @@ class InvestmentTerritoryTest extends TestCase
|
||||
$this->assertDatabaseHas('sectors', ['name' => 'Mineração']);
|
||||
}
|
||||
|
||||
public function test_zambezia_is_spelled_with_its_accent_and_found_with_or_without_it(): void
|
||||
{
|
||||
// Mapa de erros: «Zambézia» as written across the portal; searches typed without the accent still find it.
|
||||
$id = (string) Str::uuid();
|
||||
DB::table('geo_locations')->insert(['id' => $id, 'code' => $id, 'name' => 'Zambezia', 'location_type' => 'province', 'parent_id' => null]);
|
||||
(include database_path('migrations/2026_12_05_090000_zambezia_accented_province_name.php'))->up();
|
||||
$this->assertSame('Zambézia', DB::table('geo_locations')->where('id', $id)->value('name'));
|
||||
$user = User::factory()->create();
|
||||
config(['portal.managers' => [$user->email]]);
|
||||
$this->actingAsWithMfa($user);
|
||||
$this->actingAs($user);
|
||||
foreach (['Zambezia', 'zambézia', 'ZAMBEZ'] as $typed) {
|
||||
$this->getJson('/management/territory-options?type=province&q='.urlencode($typed))->assertOk()->assertJsonPath('data.0.id', $id);
|
||||
}
|
||||
}
|
||||
|
||||
private function location(string $type, ?string $parent = null): string
|
||||
{
|
||||
$id = (string) Str::uuid();
|
||||
|
||||
@@ -49,7 +49,7 @@ final class PortfolioOpportunityAcceptanceTest extends TestCase
|
||||
public function test_province_does_not_promote_unsited_opportunities_or_fiches_from_another_province(): void
|
||||
{
|
||||
$geography = app(InvestmentGeography::class);
|
||||
$zambezia = $geography->publicReferences()->where('location_type', 'province')->where('name', 'Zambezia')->value('id');
|
||||
$zambezia = $geography->publicReferences()->where('location_type', 'province')->whereIn('name', ['Zambézia', 'Zambezia'])->value('id');
|
||||
$maputo = $geography->publicReferences()->where('location_type', 'province')->where('name', 'Maputo Província')->value('id');
|
||||
$mocuba = InvestmentPortfolioController::visible()->where('title', 'Construção da Cidadela Parlamentar de Mocuba')->firstOrFail();
|
||||
foreach ([[$zambezia, true], [$maputo, false]] as [$province, $expected]) {
|
||||
|
||||
Reference in New Issue
Block a user