Skip to content

Commit f154bdb

Browse files
authored
Fix API calls for all_projects (#1023)
1 parent c549e71 commit f154bdb

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

app/classes/Transvision/API.php

+16
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ private function isValidServiceCall($service)
200200
switch ($service) {
201201
case 'entity':
202202
// ex: /api/v1/entity/mozilla_org/?id=mozilla_org/mozorg/home.lang:d9d4307d
203+
// Use 'global' in API calls instead of the meta project ID
204+
if (Project::isMetaRepository($this->parameters[2])) {
205+
$this->parameters[2] = 'global';
206+
}
203207
if (! $this->verifyRepositoryExists($this->parameters[2])) {
204208
return false;
205209
}
@@ -217,6 +221,10 @@ private function isValidServiceCall($service)
217221
return false;
218222
}
219223

224+
// Use 'global' in API calls instead of the meta project ID
225+
if (Project::isMetaRepository($this->parameters[2])) {
226+
$this->parameters[2] = 'global';
227+
}
220228
if (! $this->verifyRepositoryExists($this->parameters[2])) {
221229
return false;
222230
}
@@ -259,6 +267,10 @@ private function isValidServiceCall($service)
259267
return false;
260268
}
261269

270+
// Use 'global' in API calls instead of the meta project ID
271+
if (Project::isMetaRepository($this->parameters[3])) {
272+
$this->parameters[3] = 'global';
273+
}
262274
if (! $this->verifyRepositoryExists($this->parameters[3], true)) {
263275
return false;
264276
}
@@ -283,6 +295,10 @@ private function isValidServiceCall($service)
283295
return false;
284296
}
285297

298+
// Use 'global' in API calls instead of the meta project ID
299+
if (Project::isMetaRepository($this->parameters[2])) {
300+
$this->parameters[2] = 'global';
301+
}
286302
if (! $this->verifyRepositoryExists($this->parameters[2], true)) {
287303
return false;
288304
}

app/classes/Transvision/Project.php

+18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class Project
4141
*/
4242
public static $repos_info = [
4343
'all_projects' => [
44+
/*
45+
* Only one project should be set as meta, as it's used to track
46+
* the repository ID that includes all other projects.
47+
*/
4448
'meta' => true,
4549
],
4650
'firefox_ios' => [
@@ -287,6 +291,20 @@ public static function isMetaRepository($repository)
287291
: false;
288292
}
289293

294+
/**
295+
* Return meta repository
296+
*
297+
* @return string ID of the meta repository
298+
*/
299+
public static function getMetaRepository()
300+
{
301+
foreach (self::getRepositories() as $repository) {
302+
if (self::isMetaRepository($repository)) {
303+
return $repository;
304+
}
305+
}
306+
}
307+
290308
/**
291309
* Return true if the locale is the reference locale for a repository
292310
*

app/controllers/mainsearch.php

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
};
1717

1818
$repo = $get_value('repo', 'gecko_strings');
19-
// Redirect "all_projects" to 'global'
20-
if ($repo == 'all_projects') {
21-
$repo = 'global';
22-
}
2319
$type = $get_value('search_type', 'strings');
2420
$source = $get_value('sourcelocale', Project::getReferenceLocale($repo));
2521
$target = $get_value('locale', 'fr');

app/inc/search_options.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
/*
1616
Check for default_repository cookie if we don't have a GET value,
17-
otherwise fall back to all_projects instead of gecko_strings,
17+
otherwise fall back to meta repository instead of gecko_strings,
1818
which is the default for the search() class.
1919
*/
2020
if (! isset($_GET['repo'])) {
2121
if (isset($_COOKIE['default_repository']) && Project::isValidRepository($_COOKIE['default_repository'])) {
2222
$repo = $_COOKIE['default_repository'];
2323
} else {
24-
$repo = 'all_projects';
24+
$repo = Project::getMetaRepository();
2525
}
2626
}
2727

tests/functional/api.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
['v1/locales/iDontExist/', 400, '{"error":"The repo queried (iDontExist) doesn\'t exist."}'],
1515
['v1/repositories/', 200, '["gecko_strings","mozilla_org"]'],
1616
['v1/repositories/fr/', 200, '["gecko_strings","mozilla_org"]'],
17+
['v1/suggestions/all_projects/en-US/fr/ar/?max_results=2', 200, '["Bookmark","Marque-page"]'],
18+
['v1/suggestions/global/en-US/fr/ar/?max_results=2', 200, '["Bookmark","Marque-page"]'],
1719
['v1/suggestions/gecko_strings/en-US/fr/ar/?max_results=2', 200, '["Bookmark","Marque-page"]'],
1820
['v1/suggestions/gecko_strings/en-US/fr/ar/?max_results=10', 200, '["Bookmark","Bookmarks","New Bookmarks","Bookmark This Page","Marque-page","Marque-pages","Marquer cette page","Nouveaux marque-pages"]'],
1921
['v1/suggestions/gecko_strings/en-US/fr/ar/?max_results=0', 200, '["Bookmark","Bookmarks","New Bookmarks","Bookmark This Page","Marque-page","Marque-pages","Marquer cette page","Nouveaux marque-pages"]'],

tests/units/Transvision/Project.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testGetRepositories()
2222
->isEqualTo($repos);
2323
}
2424

25-
public function testIsMetaRepository()
25+
public function testMetaRepository()
2626
{
2727
$obj = new _Project();
2828
$this
@@ -31,6 +31,9 @@ public function testIsMetaRepository()
3131
$this
3232
->boolean($obj->isMetaRepository('gecko_strings'))
3333
->isEqualTo(false);
34+
$this
35+
->string($obj->getMetaRepository())
36+
->isEqualTo('all_projects');
3437
}
3538

3639
public function testIsReferenceLocale()

0 commit comments

Comments
 (0)