feat(rpc): add 'suggest-pkgbase' type

This feature of RPC is required to take advantage of
javascript typeahead.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-10-18 18:43:50 -07:00
parent fb0f252b39
commit 990f4d182b
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
3 changed files with 36 additions and 7 deletions

View file

@ -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

View file

@ -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"]

View file

@ -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) {