diff --git a/app/classes/Transvision/API.php b/app/classes/Transvision/API.php index 0d78282a..398ee948 100644 --- a/app/classes/Transvision/API.php +++ b/app/classes/Transvision/API.php @@ -200,6 +200,10 @@ private function isValidServiceCall($service) switch ($service) { case 'entity': // ex: /api/v1/entity/mozilla_org/?id=mozilla_org/mozorg/home.lang:d9d4307d + // Use 'global' in API calls instead of the meta project ID + if (Project::isMetaRepository($this->parameters[2])) { + $this->parameters[2] = 'global'; + } if (! $this->verifyRepositoryExists($this->parameters[2])) { return false; } @@ -217,6 +221,10 @@ private function isValidServiceCall($service) return false; } + // Use 'global' in API calls instead of the meta project ID + if (Project::isMetaRepository($this->parameters[2])) { + $this->parameters[2] = 'global'; + } if (! $this->verifyRepositoryExists($this->parameters[2])) { return false; } @@ -259,6 +267,10 @@ private function isValidServiceCall($service) return false; } + // Use 'global' in API calls instead of the meta project ID + if (Project::isMetaRepository($this->parameters[3])) { + $this->parameters[3] = 'global'; + } if (! $this->verifyRepositoryExists($this->parameters[3], true)) { return false; } @@ -283,6 +295,10 @@ private function isValidServiceCall($service) return false; } + // Use 'global' in API calls instead of the meta project ID + if (Project::isMetaRepository($this->parameters[2])) { + $this->parameters[2] = 'global'; + } if (! $this->verifyRepositoryExists($this->parameters[2], true)) { return false; } diff --git a/app/classes/Transvision/Project.php b/app/classes/Transvision/Project.php index c5b0fc1f..d923b3da 100644 --- a/app/classes/Transvision/Project.php +++ b/app/classes/Transvision/Project.php @@ -41,6 +41,10 @@ class Project */ public static $repos_info = [ 'all_projects' => [ + /* + * Only one project should be set as meta, as it's used to track + * the repository ID that includes all other projects. + */ 'meta' => true, ], 'firefox_ios' => [ @@ -287,6 +291,20 @@ public static function isMetaRepository($repository) : false; } + /** + * Return meta repository + * + * @return string ID of the meta repository + */ + public static function getMetaRepository() + { + foreach (self::getRepositories() as $repository) { + if (self::isMetaRepository($repository)) { + return $repository; + } + } + } + /** * Return true if the locale is the reference locale for a repository * diff --git a/app/controllers/mainsearch.php b/app/controllers/mainsearch.php index 3ea67009..ae178ac0 100644 --- a/app/controllers/mainsearch.php +++ b/app/controllers/mainsearch.php @@ -16,10 +16,6 @@ }; $repo = $get_value('repo', 'gecko_strings'); - // Redirect "all_projects" to 'global' - if ($repo == 'all_projects') { - $repo = 'global'; - } $type = $get_value('search_type', 'strings'); $source = $get_value('sourcelocale', Project::getReferenceLocale($repo)); $target = $get_value('locale', 'fr'); diff --git a/app/inc/search_options.php b/app/inc/search_options.php index 676e2cc5..6bf91e71 100644 --- a/app/inc/search_options.php +++ b/app/inc/search_options.php @@ -14,14 +14,14 @@ /* Check for default_repository cookie if we don't have a GET value, - otherwise fall back to all_projects instead of gecko_strings, + otherwise fall back to meta repository instead of gecko_strings, which is the default for the search() class. */ if (! isset($_GET['repo'])) { if (isset($_COOKIE['default_repository']) && Project::isValidRepository($_COOKIE['default_repository'])) { $repo = $_COOKIE['default_repository']; } else { - $repo = 'all_projects'; + $repo = Project::getMetaRepository(); } } diff --git a/tests/functional/api.php b/tests/functional/api.php index 39ff2382..58112396 100644 --- a/tests/functional/api.php +++ b/tests/functional/api.php @@ -14,6 +14,8 @@ ['v1/locales/iDontExist/', 400, '{"error":"The repo queried (iDontExist) doesn\'t exist."}'], ['v1/repositories/', 200, '["gecko_strings","mozilla_org"]'], ['v1/repositories/fr/', 200, '["gecko_strings","mozilla_org"]'], + ['v1/suggestions/all_projects/en-US/fr/ar/?max_results=2', 200, '["Bookmark","Marque-page"]'], + ['v1/suggestions/global/en-US/fr/ar/?max_results=2', 200, '["Bookmark","Marque-page"]'], ['v1/suggestions/gecko_strings/en-US/fr/ar/?max_results=2', 200, '["Bookmark","Marque-page"]'], ['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"]'], ['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"]'], diff --git a/tests/units/Transvision/Project.php b/tests/units/Transvision/Project.php index 63565d1a..ec1268cc 100644 --- a/tests/units/Transvision/Project.php +++ b/tests/units/Transvision/Project.php @@ -22,7 +22,7 @@ public function testGetRepositories() ->isEqualTo($repos); } - public function testIsMetaRepository() + public function testMetaRepository() { $obj = new _Project(); $this @@ -31,6 +31,9 @@ public function testIsMetaRepository() $this ->boolean($obj->isMetaRepository('gecko_strings')) ->isEqualTo(false); + $this + ->string($obj->getMetaRepository()) + ->isEqualTo('all_projects'); } public function testIsReferenceLocale()