mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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:
parent
fb0f252b39
commit
990f4d182b
3 changed files with 36 additions and 7 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
from sqlalchemy import and_
|
||||||
|
|
||||||
import aurweb.config as config
|
import aurweb.config as config
|
||||||
|
|
||||||
from aurweb import db, models
|
from aurweb import db, models
|
||||||
|
@ -155,11 +157,21 @@ def run_info(returned_data, package_name, snapshot_uri):
|
||||||
return returned_data
|
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):
|
def RPC(**function_args):
|
||||||
# Get arguments.
|
# Get arguments.
|
||||||
#
|
#
|
||||||
# We'll use 'v' in the future when we add v6.
|
# 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")
|
type = function_args.get("type")
|
||||||
args = function_args.get("argument_list")
|
args = function_args.get("argument_list")
|
||||||
returned_data = function_args.get("returned_data")
|
returned_data = function_args.get("returned_data")
|
||||||
|
@ -170,7 +182,8 @@ def RPC(**function_args):
|
||||||
# Set request type to run.
|
# Set request type to run.
|
||||||
type_actions = {
|
type_actions = {
|
||||||
"info": run_info,
|
"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
|
# This if statement should always be executed, as we checked if the
|
||||||
|
|
|
@ -68,7 +68,9 @@ def setup():
|
||||||
Passwd="testPassword",
|
Passwd="testPassword",
|
||||||
AccountType=account_type)
|
AccountType=account_type)
|
||||||
|
|
||||||
pkgbase1 = create(PackageBase, Name="big-chungus", Maintainer=user1)
|
pkgbase1 = create(PackageBase, Name="big-chungus",
|
||||||
|
Maintainer=user1,
|
||||||
|
Packager=user1)
|
||||||
|
|
||||||
pkgname1 = create(Package,
|
pkgname1 = create(Package,
|
||||||
PackageBase=pkgbase1,
|
PackageBase=pkgbase1,
|
||||||
|
@ -76,7 +78,9 @@ def setup():
|
||||||
Description="Bunny bunny around bunny",
|
Description="Bunny bunny around bunny",
|
||||||
URL="https://example.com/")
|
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,
|
pkgname2 = create(Package,
|
||||||
PackageBase=pkgbase2,
|
PackageBase=pkgbase2,
|
||||||
|
@ -84,7 +88,9 @@ def setup():
|
||||||
Description="Wubby wubby on wobba wuubu",
|
Description="Wubby wubby on wobba wuubu",
|
||||||
URL="https://example.com/")
|
URL="https://example.com/")
|
||||||
|
|
||||||
pkgbase3 = create(PackageBase, Name="gluggly-chungus", Maintainer=user1)
|
pkgbase3 = create(PackageBase, Name="gluggly-chungus",
|
||||||
|
Maintainer=user1,
|
||||||
|
Packager=user1)
|
||||||
|
|
||||||
create(Package,
|
create(Package,
|
||||||
PackageBase=pkgbase3,
|
PackageBase=pkgbase3,
|
||||||
|
@ -92,7 +98,7 @@ def setup():
|
||||||
Description="glurrba glurrba gur globba",
|
Description="glurrba glurrba gur globba",
|
||||||
URL="https://example.com/")
|
URL="https://example.com/")
|
||||||
|
|
||||||
pkgbase4 = create(PackageBase, Name="woogly-chungus", Maintainer=None)
|
pkgbase4 = create(PackageBase, Name="woogly-chungus")
|
||||||
|
|
||||||
create(Package,
|
create(Package,
|
||||||
PackageBase=pkgbase4,
|
PackageBase=pkgbase4,
|
||||||
|
@ -412,3 +418,13 @@ def test_rpc_no_maintainer():
|
||||||
|
|
||||||
# Validate data.
|
# Validate data.
|
||||||
assert response_data["results"][0]["Maintainer"] is None
|
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) {
|
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) {
|
fetch(url).then(function(response) {
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then(function(data) {
|
}).then(function(data) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue