[2/2] serve.py: add support for 'list-voted'

Message ID CAAue4xxa26V0u+HyDVrOaNw3BHNGF6KzZWOWqZzqLsLx_pcj2w@mail.gmail.com
State New
Headers show
Series
  • add SSH command 'list-voted'
Related show

Commit Message

Simon Legner April 3, 2018, 7:19 p.m. UTC
This command lists voted packages.
---
 aurweb/git/serve.py     | 18 ++++++++++++++++++
 test/t1200-git-serve.sh | 22 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

Comments

Eli Schwartz April 3, 2018, 7:32 p.m. UTC | #1
On 04/03/2018 03:19 PM, Simon Legner wrote:
> This command lists voted packages.

Looks useful, thanks. Especially refactoring the boilerplate into a
helper function.

>          cmds = {
>              "adopt <name>": "Adopt a package base.",
>              "disown <name>": "Disown a package base.",
>              "flag <name> <comment>": "Flag a package base out-of-date.",
>              "help": "Show this help message and exit.",
>              "list-repos": "List all your repositories.",
> +            "list-voted": "List voted packages.",

But I think this should be "List packages you have voted for".

You will also need to update the documentation in doc/git-interface.txt
Lukas Fleischer April 5, 2018, 2:20 p.m. UTC | #2
On Tue, 03 Apr 2018 at 21:19:16, Simon Legner wrote:
> This command lists voted packages.
> ---
>  aurweb/git/serve.py     | 18 ++++++++++++++++++
>  test/t1200-git-serve.sh | 22 ++++++++++++++++++++++
>  2 files changed, 40 insertions(+)
> 
> [...]
> @@ -508,6 +521,9 @@ def serve(action, cmdargv, user, privileged, remote_addr):
> 
>          pkgbase = cmdargv[1]
>          pkgbase_unvote(pkgbase, user)
> +    elif action == 'list-voted':
> +        checkarg(cmdargv)
> +        list_voted(user)
> [...]

Thanks. I wonder whether, instead of doing this and adding similar
commands later, we should add a more generic command (`ls`, `list`,
`search`) to replicate the search API we already offer via the RPC
interface?

Regards,
Lukas

Patch

diff --git a/aurweb/git/serve.py b/aurweb/git/serve.py
index 01aea20..3b3967a 100755
--- a/aurweb/git/serve.py
+++ b/aurweb/git/serve.py
@@ -326,6 +326,19 @@  def pkgbase_unvote(pkgbase, user):
     conn.commit()


+def list_voted(user):
+    conn = aurweb.db.Connection()
+
+    userid = conn.fetch_userid(user)
+
+    cur = conn.execute("SELECT Name FROM PackageBases JOIN PackageVotes " +
+                       "ON ID = PackageBaseID " +
+                       "WHERE UsersID = ?", [userid])
+    for row in cur:
+        print(row[0])
+    conn.close()
+
+
 def pkgbase_set_keywords(pkgbase, keywords):
     pkgbase_id = pkgbase_from_name(pkgbase)
     if not pkgbase_id:
@@ -508,6 +521,9 @@  def serve(action, cmdargv, user, privileged, remote_addr):

         pkgbase = cmdargv[1]
         pkgbase_unvote(pkgbase, user)
+    elif action == 'list-voted':
+        checkarg(cmdargv)
+        list_voted(user)
     elif action == 'set-comaintainers':
         checkarg_atleast(cmdargv, 'repository name')

@@ -515,12 +531,14 @@  def serve(action, cmdargv, user, privileged, remote_addr):
         userlist = cmdargv[2:]
         pkgbase_set_comaintainers(pkgbase, userlist, user, privileged)
     elif action == 'help':
+        # commands in alphabetical order, git-* at the end
         cmds = {
             "adopt <name>": "Adopt a package base.",
             "disown <name>": "Disown a package base.",
             "flag <name> <comment>": "Flag a package base out-of-date.",
             "help": "Show this help message and exit.",
             "list-repos": "List all your repositories.",
+            "list-voted": "List voted packages.",
             "restore <name>": "Restore a deleted package base.",
             "set-comaintainers <name> [...]": "Set package base
co-maintainers.",
             "set-keywords <name> [...]": "Change package base keywords.",
diff --git a/test/t1200-git-serve.sh b/test/t1200-git-serve.sh
index 94a5ff6..51db399 100755
--- a/test/t1200-git-serve.sh
+++ b/test/t1200-git-serve.sh
@@ -466,6 +466,12 @@  test_expect_success "Vote for a package base." '
  EOF
  echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
  sqlite3 aur.db >actual &&
+ test_cmp expected actual &&
+ SSH_ORIGINAL_COMMAND="list-voted" AUR_USER=user AUR_PRIVILEGED=0 \
+ "$GIT_SERVE" 2>&1 >actual &&
+ cat >expected <<-EOF &&
+ foobar
+ EOF
  test_cmp expected actual
 '

@@ -484,6 +490,12 @@  test_expect_success "Vote for a package base twice." '
  EOF
  echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
  sqlite3 aur.db >actual &&
+ test_cmp expected actual &&
+ SSH_ORIGINAL_COMMAND="list-voted" AUR_USER=user AUR_PRIVILEGED=0 \
+ "$GIT_SERVE" 2>&1 >actual &&
+ cat >expected <<-EOF &&
+ foobar
+ EOF
  test_cmp expected actual
 '

@@ -500,6 +512,11 @@  test_expect_success "Remove vote from a package base." '
  EOF
  echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
  sqlite3 aur.db >actual &&
+ test_cmp expected actual &&
+ SSH_ORIGINAL_COMMAND="list-voted" AUR_USER=user AUR_PRIVILEGED=0 \
+ "$GIT_SERVE" 2>&1 >actual &&
+ cat >expected <<-EOF &&
+ EOF
  test_cmp expected actual
 '

@@ -518,6 +535,11 @@  test_expect_success "Try to remove the vote again." '
  EOF
  echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
  sqlite3 aur.db >actual &&
+ test_cmp expected actual &&
+ SSH_ORIGINAL_COMMAND="list-voted" AUR_USER=user AUR_PRIVILEGED=0 \
+ "$GIT_SERVE" 2>&1 >actual &&
+ cat >expected <<-EOF &&
+ EOF
  test_cmp expected actual
 '