diff --git a/aurweb/rpc.py b/aurweb/rpc.py index 1ddde749..faa8ca60 100644 --- a/aurweb/rpc.py +++ b/aurweb/rpc.py @@ -1,3 +1,5 @@ +from sqlalchemy import and_ + import aurweb.config as config from aurweb import db, models @@ -155,11 +157,21 @@ def run_info(returned_data, package_name, snapshot_uri): return returned_data +def run_suggest_pkgbase(returned_data, arg, snapshot_uri): + results = db.query(models.PackageBase).filter( + and_(models.PackageBase.PackagerUID.isnot(None), + models.PackageBase.Name.like(f"%{arg}%")) + ).order_by(models.PackageBase.Name.asc()).limit(20) + return [result.Name for result in results] + + def RPC(**function_args): # Get arguments. # # We'll use 'v' in the future when we add v6. - # v = function_args.get("v") + # v = function_args.gea name used for an individual person, place, or + # organization, spelled with initial capital letters, e.g., Larry, + # Mexico, and Boston Red Sox.t("v") type = function_args.get("type") args = function_args.get("argument_list") returned_data = function_args.get("returned_data") @@ -170,7 +182,8 @@ def RPC(**function_args): # Set request type to run. type_actions = { "info": run_info, - "multiinfo": run_info + "multiinfo": run_info, + "suggest-pkgbase": run_suggest_pkgbase } # This if statement should always be executed, as we checked if the diff --git a/test/test_rpc.py b/test/test_rpc.py index 21817b45..601536a4 100644 --- a/test/test_rpc.py +++ b/test/test_rpc.py @@ -68,7 +68,9 @@ def setup(): Passwd="testPassword", AccountType=account_type) - pkgbase1 = create(PackageBase, Name="big-chungus", Maintainer=user1) + pkgbase1 = create(PackageBase, Name="big-chungus", + Maintainer=user1, + Packager=user1) pkgname1 = create(Package, PackageBase=pkgbase1, @@ -76,7 +78,9 @@ def setup(): Description="Bunny bunny around bunny", URL="https://example.com/") - pkgbase2 = create(PackageBase, Name="chungy-chungus", Maintainer=user1) + pkgbase2 = create(PackageBase, Name="chungy-chungus", + Maintainer=user1, + Packager=user1) pkgname2 = create(Package, PackageBase=pkgbase2, @@ -84,7 +88,9 @@ def setup(): Description="Wubby wubby on wobba wuubu", URL="https://example.com/") - pkgbase3 = create(PackageBase, Name="gluggly-chungus", Maintainer=user1) + pkgbase3 = create(PackageBase, Name="gluggly-chungus", + Maintainer=user1, + Packager=user1) create(Package, PackageBase=pkgbase3, @@ -92,7 +98,7 @@ def setup(): Description="glurrba glurrba gur globba", URL="https://example.com/") - pkgbase4 = create(PackageBase, Name="woogly-chungus", Maintainer=None) + pkgbase4 = create(PackageBase, Name="woogly-chungus") create(Package, PackageBase=pkgbase4, @@ -412,3 +418,13 @@ def test_rpc_no_maintainer(): # Validate data. assert response_data["results"][0]["Maintainer"] is None + + +def test_rpc_suggest_pkgbase(): + response = make_request("/rpc?v=5&type=suggest-pkgbase&arg=big") + data = response.json() + assert data == ["big-chungus"] + + response = make_request("/rpc?v=5&type=suggest-pkgbase&arg=chungy") + data = response.json() + assert data == ["chungy-chungus"] diff --git a/web/html/js/typeahead.js b/web/html/js/typeahead.js index 1b7252d7..bfd3d156 100644 --- a/web/html/js/typeahead.js +++ b/web/html/js/typeahead.js @@ -67,7 +67,7 @@ const typeahead = (function() { } function fetchData(letter) { - const url = '/rpc?type=' + suggest_type + '&arg=' + letter; + const url = '/rpc?v=5&type=' + suggest_type + '&arg=' + letter; fetch(url).then(function(response) { return response.json(); }).then(function(data) {