mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
git-serve: Add support for (un-)voting
Add support for voting for packages and removing votes from the SSH interface. The syntax is `vote <pkgbase>` resp. `unvote <pkgbase>`. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
fc2ecff949
commit
7ee2fddcca
2 changed files with 75 additions and 0 deletions
|
@ -48,6 +48,18 @@ class InvalidCommentException(AurwebException):
|
||||||
super(InvalidCommentException, self).__init__(msg)
|
super(InvalidCommentException, self).__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
|
class AlreadyVotedException(AurwebException):
|
||||||
|
def __init__(self, comment):
|
||||||
|
msg = 'already voted for package base: {:s}'.format(comment)
|
||||||
|
super(AlreadyVotedException, self).__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
|
class NotVotedException(AurwebException):
|
||||||
|
def __init__(self, comment):
|
||||||
|
msg = 'missing vote for package base: {:s}'.format(comment)
|
||||||
|
super(NotVotedException, self).__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
class InvalidArgumentsException(AurwebException):
|
class InvalidArgumentsException(AurwebException):
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
super(InvalidArgumentsException, self).__init__(msg)
|
super(InvalidArgumentsException, self).__init__(msg)
|
||||||
|
|
|
@ -318,6 +318,57 @@ def pkgbase_unflag(pkgbase, user):
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def pkgbase_vote(pkgbase, user):
|
||||||
|
pkgbase_id = pkgbase_from_name(pkgbase)
|
||||||
|
if not pkgbase_id:
|
||||||
|
raise aurweb.exceptions.InvalidPackageBaseException(pkgbase)
|
||||||
|
|
||||||
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
|
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
|
||||||
|
userid = cur.fetchone()[0]
|
||||||
|
if userid == 0:
|
||||||
|
raise aurweb.exceptions.InvalidUserException(user)
|
||||||
|
|
||||||
|
cur = conn.execute("SELECT COUNT(*) FROM PackageVotes " +
|
||||||
|
"WHERE UsersID = ? AND PackageBaseID = ?",
|
||||||
|
[userid, pkgbase_id])
|
||||||
|
if cur.fetchone()[0] > 0:
|
||||||
|
raise aurweb.exceptions.AlreadyVotedException(pkgbase)
|
||||||
|
|
||||||
|
now = int(time.time())
|
||||||
|
conn.execute("INSERT INTO PackageVotes (UsersID, PackageBaseID, VoteTS) " +
|
||||||
|
"VALUES (?, ?, ?)", [userid, pkgbase_id, now])
|
||||||
|
conn.execute("UPDATE PackageBases SET NumVotes = NumVotes + 1 " +
|
||||||
|
"WHERE ID = ?", [pkgbase_id])
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def pkgbase_unvote(pkgbase, user):
|
||||||
|
pkgbase_id = pkgbase_from_name(pkgbase)
|
||||||
|
if not pkgbase_id:
|
||||||
|
raise aurweb.exceptions.InvalidPackageBaseException(pkgbase)
|
||||||
|
|
||||||
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
|
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
|
||||||
|
userid = cur.fetchone()[0]
|
||||||
|
if userid == 0:
|
||||||
|
raise aurweb.exceptions.InvalidUserException(user)
|
||||||
|
|
||||||
|
cur = conn.execute("SELECT COUNT(*) FROM PackageVotes " +
|
||||||
|
"WHERE UsersID = ? AND PackageBaseID = ?",
|
||||||
|
[userid, pkgbase_id])
|
||||||
|
if cur.fetchone()[0] == 0:
|
||||||
|
raise aurweb.exceptions.NotVotedException(pkgbase)
|
||||||
|
|
||||||
|
conn.execute("DELETE FROM PackageVotes WHERE UsersID = ? AND " +
|
||||||
|
"PackageBaseID = ?", [userid, pkgbase_id])
|
||||||
|
conn.execute("UPDATE PackageBases SET NumVotes = NumVotes - 1 " +
|
||||||
|
"WHERE ID = ?", [pkgbase_id])
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
def pkgbase_set_keywords(pkgbase, keywords):
|
def pkgbase_set_keywords(pkgbase, keywords):
|
||||||
pkgbase_id = pkgbase_from_name(pkgbase)
|
pkgbase_id = pkgbase_from_name(pkgbase)
|
||||||
if not pkgbase_id:
|
if not pkgbase_id:
|
||||||
|
@ -467,6 +518,16 @@ def serve(action, cmdargv, user, privileged, remote_addr):
|
||||||
|
|
||||||
pkgbase = cmdargv[1]
|
pkgbase = cmdargv[1]
|
||||||
pkgbase_unflag(pkgbase, user)
|
pkgbase_unflag(pkgbase, user)
|
||||||
|
elif action == 'vote':
|
||||||
|
checkarg(cmdargv, 'repository name')
|
||||||
|
|
||||||
|
pkgbase = cmdargv[1]
|
||||||
|
pkgbase_vote(pkgbase, user)
|
||||||
|
elif action == 'unvote':
|
||||||
|
checkarg(cmdargv, 'repository name')
|
||||||
|
|
||||||
|
pkgbase = cmdargv[1]
|
||||||
|
pkgbase_unvote(pkgbase, user)
|
||||||
elif action == 'set-comaintainers':
|
elif action == 'set-comaintainers':
|
||||||
checkarg_atleast(cmdargv, 'repository name')
|
checkarg_atleast(cmdargv, 'repository name')
|
||||||
|
|
||||||
|
@ -485,6 +546,8 @@ def serve(action, cmdargv, user, privileged, remote_addr):
|
||||||
"set-keywords <name> [...]": "Change package base keywords.",
|
"set-keywords <name> [...]": "Change package base keywords.",
|
||||||
"setup-repo <name>": "Create a repository (deprecated).",
|
"setup-repo <name>": "Create a repository (deprecated).",
|
||||||
"unflag <name>": "Remove out-of-date flag from a package base.",
|
"unflag <name>": "Remove out-of-date flag from a package base.",
|
||||||
|
"unvote <name>": "Remove vote from a package base.",
|
||||||
|
"vote <name>": "Vote for a package base.",
|
||||||
"git-receive-pack": "Internal command used with Git.",
|
"git-receive-pack": "Internal command used with Git.",
|
||||||
"git-upload-pack": "Internal command used with Git.",
|
"git-upload-pack": "Internal command used with Git.",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue