Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Arch Linux
aurweb
Commits
708ade4d
Verified
Commit
708ade4d
authored
Feb 11, 2022
by
Kevin Morris
Browse files
fix: allow co-maintainers to [un]pin comments on a package
Closes
#279
Signed-off-by:
Kevin Morris
<
kevr@0cost.org
>
parent
35e7486e
Pipeline
#15835
passed with stages
in 3 minutes and 10 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
aurweb/models/package_comment.py
View file @
708ade4d
...
...
@@ -52,3 +52,11 @@ class PackageComment(Base):
if
self
.
RenderedComment
is
None
:
self
.
RenderedComment
=
str
()
def
maintainers
(
self
):
return
list
(
filter
(
lambda
e
:
e
is
not
None
,
[
self
.
PackageBase
.
Maintainer
]
+
[
c
.
User
for
c
in
self
.
PackageBase
.
comaintainers
]
))
aurweb/pkgbase/util.py
View file @
708ade4d
...
...
@@ -25,9 +25,11 @@ def make_context(request: Request, pkgbase: PackageBase) -> Dict[str, Any]:
context
[
"git_clone_uri_anon"
]
=
config
.
get
(
"options"
,
"git_clone_uri_anon"
)
context
[
"git_clone_uri_priv"
]
=
config
.
get
(
"options"
,
"git_clone_uri_priv"
)
context
[
"pkgbase"
]
=
pkgbase
context
[
"comaintainers"
]
=
pkgbase
.
comaintainers
.
order_by
(
PackageComaintainer
.
Priority
.
asc
()
).
all
()
context
[
"comaintainers"
]
=
[
c
.
User
for
c
in
pkgbase
.
comaintainers
.
order_by
(
PackageComaintainer
.
Priority
.
asc
()
).
all
()
]
context
[
"packages_count"
]
=
pkgbase
.
packages
.
count
()
context
[
"keywords"
]
=
pkgbase
.
keywords
context
[
"comments"
]
=
pkgbase
.
comments
.
order_by
(
...
...
aurweb/routers/pkgbase.py
View file @
708ade4d
...
...
@@ -318,7 +318,7 @@ async def pkgbase_comment_pin(request: Request, name: str, id: int,
comment
=
get_pkgbase_comment
(
pkgbase
,
id
)
has_cred
=
request
.
user
.
has_credential
(
creds
.
COMMENT_PIN
,
approved
=
[
pkgbase
.
M
aintainer
]
)
approved
=
comment
.
m
aintainer
s
()
)
if
not
has_cred
:
_
=
l10n
.
get_translator_for_request
(
request
)
raise
HTTPException
(
...
...
@@ -353,7 +353,7 @@ async def pkgbase_comment_unpin(request: Request, name: str, id: int,
comment
=
get_pkgbase_comment
(
pkgbase
,
id
)
has_cred
=
request
.
user
.
has_credential
(
creds
.
COMMENT_PIN
,
approved
=
[
pkgbase
.
M
aintainer
]
)
approved
=
comment
.
m
aintainer
s
()
)
if
not
has_cred
:
_
=
l10n
.
get_translator_for_request
(
request
)
raise
HTTPException
(
...
...
templates/partials/comment_actions.html
View file @
708ade4d
...
...
@@ -47,13 +47,13 @@
{% endif %}
{% if request.user.has_credential(creds.COMMENT_PIN, approved=
[
comment.
PackageBase.M
aintainer
]
) %}
{% if request.user.has_credential(creds.COMMENT_PIN, approved=comment.
m
aintainer
s()
) %}
{% if comment.PinnedTS %}
<form
class=
"pin-comment-form"
method=
"post"
action=
"/pkgbase/{{ comment.PackageBase.Name }}/comments/{{ comment.ID }}/unpin"
>
<fieldset
style=
"display:inline;"
>
<fieldset
style=
"display:
inline;"
>
<input
type=
"hidden"
name=
"next"
value=
"{{ request.url.path }}"
/>
<input
type=
"image"
class=
"pin-comment"
...
...
templates/partials/packages/details.html
View file @
708ade4d
...
...
@@ -114,7 +114,7 @@
</a>
{% set len = comaintainers | length %}
{% if comaintainers %}
({% for co in comaintainers %}
<a
href=
"{{ co
.User
| account_url }}"
>
{{ co
.User
}}
</a>
{% if loop.index
<
len
%},
{%
endif
%}{%
endfor
%})
({% for co in comaintainers %}
<a
href=
"{{ co | account_url }}"
>
{{ co }}
</a>
{% if loop.index
<
len
%},
{%
endif
%}{%
endfor
%})
{%
endif
%}
{%
else
%}
{{
pkgbase.Maintainer.Username
|
default
("
None
"
|
tr
)
}}
...
...
test/test_pkgbase_routes.py
View file @
708ade4d
...
...
@@ -534,6 +534,35 @@ def test_pkgbase_comment_undelete_not_found(client: TestClient,
assert
resp
.
status_code
==
int
(
HTTPStatus
.
NOT_FOUND
)
def
test_pkgbase_comment_pin_as_co
(
client
:
TestClient
,
package
:
Package
,
comment
:
PackageComment
):
comaint
=
create_user
(
"comaint1"
)
with
db
.
begin
():
db
.
create
(
PackageComaintainer
,
PackageBase
=
package
.
PackageBase
,
User
=
comaint
,
Priority
=
1
)
# Pin the comment.
pkgbasename
=
package
.
PackageBase
.
Name
endpoint
=
f
"/pkgbase/
{
pkgbasename
}
/comments/
{
comment
.
ID
}
/pin"
cookies
=
{
"AURSID"
:
comaint
.
login
(
Request
(),
"testPassword"
)}
with
client
as
request
:
resp
=
request
.
post
(
endpoint
,
cookies
=
cookies
)
assert
resp
.
status_code
==
int
(
HTTPStatus
.
SEE_OTHER
)
# Assert that PinnedTS got set.
assert
comment
.
PinnedTS
>
0
# Unpin the comment we just pinned.
endpoint
=
f
"/pkgbase/
{
pkgbasename
}
/comments/
{
comment
.
ID
}
/unpin"
with
client
as
request
:
resp
=
request
.
post
(
endpoint
,
cookies
=
cookies
)
assert
resp
.
status_code
==
int
(
HTTPStatus
.
SEE_OTHER
)
# Let's assert that PinnedTS was unset.
assert
comment
.
PinnedTS
==
0
def
test_pkgbase_comment_pin
(
client
:
TestClient
,
maintainer
:
User
,
package
:
Package
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment