Verified Commit 0583f30a authored by Mario Oenning's avatar Mario Oenning
Browse files

feat(rpc): add "by" parameter - groups

Adding "by" parameter to search by "groups"

Signed-off-by: Mario Oenning's avatarmoson-mo <>
parent 50287cb0
......@@ -3,7 +3,7 @@ from typing import Set
from sqlalchemy import and_, case, or_, orm
from aurweb import db, models
from aurweb.models import Package, PackageBase, User
from aurweb.models import Group, Package, PackageBase, User
from aurweb.models.dependency_type import (
......@@ -11,6 +11,7 @@ from aurweb.models.dependency_type import (
from aurweb.models.package_comaintainer import PackageComaintainer
from aurweb.models.package_group import PackageGroup
from aurweb.models.package_keyword import PackageKeyword
from aurweb.models.package_notification import PackageNotification
from aurweb.models.package_vote import PackageVote
......@@ -290,6 +291,7 @@ class RPCSearch(PackageSearch):
"provides": self._search_by_provides,
"conflicts": self._search_by_conflicts,
"replaces": self._search_by_replaces,
"groups": self._search_by_groups,
......@@ -320,6 +322,14 @@ class RPCSearch(PackageSearch):
return self.query
def _join_groups(self) -> orm.Query:
"""Join Package with PackageGroup and Group.
:returns: PackageGroup/Group-joined orm.Query
self.query = self.query.join(PackageGroup).join(Group)
return self.query
def _search_by_depends(self, keywords: str) -> "RPCSearch":
self.query = self._join_depends(DEPENDS_ID).filter(
models.PackageDependency.DepName == keywords
......@@ -362,6 +372,11 @@ class RPCSearch(PackageSearch):
return self
def _search_by_groups(self, keywords: str) -> orm.Query:
self.query = self.query.filter(Group.Name == keywords)
return self
def search_by(self, by: str, keywords: str) -> "RPCSearch":
"""Override inherited search_by. In this override, we reduce the
scope of what we handle within this function. We do not set `by`
......@@ -86,6 +86,7 @@ class RPC:
# A mapping of by aliases.
......@@ -13,10 +13,12 @@ from aurweb import asgi, config, db, rpc, scripts, time
from aurweb.aur_redis import redis_connection
from aurweb.models.account_type import USER_ID
from aurweb.models.dependency_type import DEPENDS_ID
from import Group
from aurweb.models.license import License
from aurweb.models.package import Package
from aurweb.models.package_base import PackageBase
from aurweb.models.package_dependency import PackageDependency
from aurweb.models.package_group import PackageGroup
from aurweb.models.package_keyword import PackageKeyword
from aurweb.models.package_license import PackageLicense
from aurweb.models.package_relation import PackageRelation
......@@ -139,11 +141,14 @@ def packages(user: User, user2: User, user3: User) -> list[Package]:
# Setup a few more related records on the first package:
# a license, some keywords and some votes.
# a license, group, some keywords and some votes.
with db.begin():
lic = db.create(License, Name="GPL")
db.create(PackageLicense, Package=output[0], License=lic)
grp = db.create(Group, Name="testgroup")
db.create(PackageGroup, Package=output[0], Group=grp)
for keyword in ["big-chungus", "smol-chungus", "sizeable-chungus"]:
PackageKeyword, PackageBase=output[0].PackageBase, Keyword=keyword
......@@ -326,6 +331,7 @@ def test_rpc_singular_info(
"Replaces": ["chungus-replaces<=200"],
"License": [pkg.package_licenses.first().License.Name],
"Keywords": ["big-chungus", "sizeable-chungus", "smol-chungus"],
"Groups": ["testgroup"],
"resultcount": 1,
......@@ -888,6 +894,23 @@ def test_rpc_search_replaces(
assert result.get("Name") == packages[0].Name
def test_rpc_search_groups(
client: TestClient, packages: list[Package], depends: list[PackageDependency]
params = {
"v": 5,
"type": "search",
"by": "groups",
"arg": "testgroup",
with client as request:
response = request.get("/rpc", params=params)
data = response.json()
assert data.get("resultcount") == 1
result = data.get("results")[0]
assert result.get("Name") == packages[0].Name
def test_rpc_incorrect_by(client: TestClient):
params = {"v": 5, "type": "search", "by": "fake", "arg": "big"}
with client as request:
Supports Markdown
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