Verified Commit d5e102e3 authored by Mario Oenning's avatar Mario Oenning
Browse files

feat: add "Submitter" field to /rpc info request



Signed-off-by: Mario Oenning's avatarmoson-mo <mo-son@mailbox.org>
parent ff92e95f
Pipeline #39810 passed with stages
in 2 minutes and 12 seconds
......@@ -154,6 +154,7 @@ class RPC:
"PackageBase": package.PackageBaseName,
# Maintainer should be set following this update if one exists.
"Maintainer": package.Maintainer,
"Submitter": package.Submitter,
"Version": package.Version,
"Description": package.Description,
"URL": package.URL,
......@@ -192,22 +193,35 @@ class RPC:
def entities(self, query: orm.Query) -> orm.Query:
"""Select specific RPC columns on `query`."""
return query.with_entities(
models.Package.ID,
models.Package.Name,
models.Package.Version,
models.Package.Description,
models.Package.URL,
models.Package.PackageBaseID,
models.PackageBase.Name.label("PackageBaseName"),
models.PackageBase.NumVotes,
models.PackageBase.Popularity,
models.PackageBase.PopularityUpdated,
models.PackageBase.OutOfDateTS,
models.PackageBase.SubmittedTS,
models.PackageBase.ModifiedTS,
models.User.Username.label("Maintainer"),
).group_by(models.Package.ID)
Submitter = orm.aliased(models.User)
query = (
query.join(
Submitter,
Submitter.ID == models.PackageBase.SubmitterUID,
isouter=True,
)
.with_entities(
models.Package.ID,
models.Package.Name,
models.Package.Version,
models.Package.Description,
models.Package.URL,
models.Package.PackageBaseID,
models.PackageBase.Name.label("PackageBaseName"),
models.PackageBase.NumVotes,
models.PackageBase.Popularity,
models.PackageBase.PopularityUpdated,
models.PackageBase.OutOfDateTS,
models.PackageBase.SubmittedTS,
models.PackageBase.ModifiedTS,
models.User.Username.label("Maintainer"),
Submitter.Username.label("Submitter"),
)
.group_by(models.Package.ID)
)
return query
def subquery(self, ids: set[int]):
Package = models.Package
......@@ -367,7 +381,13 @@ class RPC:
if len(results) > max_results:
raise RPCError("Too many package results.")
return self._assemble_json_data(results, self.get_json_data)
data = self._assemble_json_data(results, self.get_json_data)
# remove Submitter for search results
for pkg in data:
pkg.pop("Submitter")
return data
def _handle_msearch_type(
self, args: list[str] = [], **kwargs
......
......@@ -345,6 +345,7 @@ def test_rpc_documentation_missing():
def test_rpc_singular_info(
client: TestClient,
user: User,
user2: User,
packages: list[Package],
depends: list[PackageDependency],
relations: list[PackageRelation],
......@@ -365,6 +366,7 @@ def test_rpc_singular_info(
"Popularity": float(pkg.PackageBase.Popularity),
"OutOfDate": None,
"Maintainer": user.Username,
"Submitter": user2.Username,
"URLPath": f"/cgit/aur.git/snapshot/{pkg.Name}.tar.gz",
"Depends": ["chungus-depends"],
"OptDepends": ["chungus-optdepends=50"],
......@@ -498,6 +500,7 @@ def test_rpc_mixedargs(client: TestClient, packages: list[Package]):
def test_rpc_no_dependencies_omits_key(
client: TestClient,
user: User,
user2: User,
packages: list[Package],
depends: list[PackageDependency],
relations: list[PackageRelation],
......@@ -520,6 +523,7 @@ def test_rpc_no_dependencies_omits_key(
"Popularity": int(pkg.PackageBase.Popularity),
"OutOfDate": None,
"Maintainer": user.Username,
"Submitter": user2.Username,
"URLPath": "/cgit/aur.git/snapshot/chungy-chungus.tar.gz",
"Depends": ["chungy-depends"],
"Conflicts": ["chungy-conflicts"],
......@@ -799,6 +803,7 @@ def test_rpc_search(client: TestClient, packages: list[Package]):
result = data.get("results")[0]
assert result.get("Name") == packages[0].Name
assert result.get("Submitter") is None
# Test the If-None-Match headers.
etag = response.headers.get("ETag").strip('"')
......
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