Verified Commit 990f4d18 authored by Kevin Morris's avatar Kevin Morris
Browse files

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



This feature of RPC is required to take advantage of
javascript typeahead.
Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent fb0f252b
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
......
......@@ -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"]
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment