mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: add "Submitter" field to /rpc info request
Signed-off-by: moson-mo <mo-son@mailbox.org>
This commit is contained in:
parent
ff92e95f7a
commit
d5e102e3f4
2 changed files with 42 additions and 17 deletions
|
@ -154,6 +154,7 @@ class RPC:
|
||||||
"PackageBase": package.PackageBaseName,
|
"PackageBase": package.PackageBaseName,
|
||||||
# Maintainer should be set following this update if one exists.
|
# Maintainer should be set following this update if one exists.
|
||||||
"Maintainer": package.Maintainer,
|
"Maintainer": package.Maintainer,
|
||||||
|
"Submitter": package.Submitter,
|
||||||
"Version": package.Version,
|
"Version": package.Version,
|
||||||
"Description": package.Description,
|
"Description": package.Description,
|
||||||
"URL": package.URL,
|
"URL": package.URL,
|
||||||
|
@ -192,7 +193,15 @@ class RPC:
|
||||||
|
|
||||||
def entities(self, query: orm.Query) -> orm.Query:
|
def entities(self, query: orm.Query) -> orm.Query:
|
||||||
"""Select specific RPC columns on `query`."""
|
"""Select specific RPC columns on `query`."""
|
||||||
return query.with_entities(
|
Submitter = orm.aliased(models.User)
|
||||||
|
|
||||||
|
query = (
|
||||||
|
query.join(
|
||||||
|
Submitter,
|
||||||
|
Submitter.ID == models.PackageBase.SubmitterUID,
|
||||||
|
isouter=True,
|
||||||
|
)
|
||||||
|
.with_entities(
|
||||||
models.Package.ID,
|
models.Package.ID,
|
||||||
models.Package.Name,
|
models.Package.Name,
|
||||||
models.Package.Version,
|
models.Package.Version,
|
||||||
|
@ -207,7 +216,12 @@ class RPC:
|
||||||
models.PackageBase.SubmittedTS,
|
models.PackageBase.SubmittedTS,
|
||||||
models.PackageBase.ModifiedTS,
|
models.PackageBase.ModifiedTS,
|
||||||
models.User.Username.label("Maintainer"),
|
models.User.Username.label("Maintainer"),
|
||||||
).group_by(models.Package.ID)
|
Submitter.Username.label("Submitter"),
|
||||||
|
)
|
||||||
|
.group_by(models.Package.ID)
|
||||||
|
)
|
||||||
|
|
||||||
|
return query
|
||||||
|
|
||||||
def subquery(self, ids: set[int]):
|
def subquery(self, ids: set[int]):
|
||||||
Package = models.Package
|
Package = models.Package
|
||||||
|
@ -367,7 +381,13 @@ class RPC:
|
||||||
if len(results) > max_results:
|
if len(results) > max_results:
|
||||||
raise RPCError("Too many package 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(
|
def _handle_msearch_type(
|
||||||
self, args: list[str] = [], **kwargs
|
self, args: list[str] = [], **kwargs
|
||||||
|
|
|
@ -345,6 +345,7 @@ def test_rpc_documentation_missing():
|
||||||
def test_rpc_singular_info(
|
def test_rpc_singular_info(
|
||||||
client: TestClient,
|
client: TestClient,
|
||||||
user: User,
|
user: User,
|
||||||
|
user2: User,
|
||||||
packages: list[Package],
|
packages: list[Package],
|
||||||
depends: list[PackageDependency],
|
depends: list[PackageDependency],
|
||||||
relations: list[PackageRelation],
|
relations: list[PackageRelation],
|
||||||
|
@ -365,6 +366,7 @@ def test_rpc_singular_info(
|
||||||
"Popularity": float(pkg.PackageBase.Popularity),
|
"Popularity": float(pkg.PackageBase.Popularity),
|
||||||
"OutOfDate": None,
|
"OutOfDate": None,
|
||||||
"Maintainer": user.Username,
|
"Maintainer": user.Username,
|
||||||
|
"Submitter": user2.Username,
|
||||||
"URLPath": f"/cgit/aur.git/snapshot/{pkg.Name}.tar.gz",
|
"URLPath": f"/cgit/aur.git/snapshot/{pkg.Name}.tar.gz",
|
||||||
"Depends": ["chungus-depends"],
|
"Depends": ["chungus-depends"],
|
||||||
"OptDepends": ["chungus-optdepends=50"],
|
"OptDepends": ["chungus-optdepends=50"],
|
||||||
|
@ -498,6 +500,7 @@ def test_rpc_mixedargs(client: TestClient, packages: list[Package]):
|
||||||
def test_rpc_no_dependencies_omits_key(
|
def test_rpc_no_dependencies_omits_key(
|
||||||
client: TestClient,
|
client: TestClient,
|
||||||
user: User,
|
user: User,
|
||||||
|
user2: User,
|
||||||
packages: list[Package],
|
packages: list[Package],
|
||||||
depends: list[PackageDependency],
|
depends: list[PackageDependency],
|
||||||
relations: list[PackageRelation],
|
relations: list[PackageRelation],
|
||||||
|
@ -520,6 +523,7 @@ def test_rpc_no_dependencies_omits_key(
|
||||||
"Popularity": int(pkg.PackageBase.Popularity),
|
"Popularity": int(pkg.PackageBase.Popularity),
|
||||||
"OutOfDate": None,
|
"OutOfDate": None,
|
||||||
"Maintainer": user.Username,
|
"Maintainer": user.Username,
|
||||||
|
"Submitter": user2.Username,
|
||||||
"URLPath": "/cgit/aur.git/snapshot/chungy-chungus.tar.gz",
|
"URLPath": "/cgit/aur.git/snapshot/chungy-chungus.tar.gz",
|
||||||
"Depends": ["chungy-depends"],
|
"Depends": ["chungy-depends"],
|
||||||
"Conflicts": ["chungy-conflicts"],
|
"Conflicts": ["chungy-conflicts"],
|
||||||
|
@ -799,6 +803,7 @@ def test_rpc_search(client: TestClient, packages: list[Package]):
|
||||||
|
|
||||||
result = data.get("results")[0]
|
result = data.get("results")[0]
|
||||||
assert result.get("Name") == packages[0].Name
|
assert result.get("Name") == packages[0].Name
|
||||||
|
assert result.get("Submitter") is None
|
||||||
|
|
||||||
# Test the If-None-Match headers.
|
# Test the If-None-Match headers.
|
||||||
etag = response.headers.get("ETag").strip('"')
|
etag = response.headers.get("ETag").strip('"')
|
||||||
|
|
Loading…
Add table
Reference in a new issue