Add global comment notification setting

Add a configuration option to the account edit page that allows for
globally enabling/disabling package base comment notifications.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2015-11-10 19:49:13 +01:00
parent 3412de21d3
commit aa5e58db81
7 changed files with 46 additions and 11 deletions

View file

@ -38,6 +38,7 @@ CREATE TABLE Users (
LastLoginIPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0, LastLoginIPAddress INTEGER UNSIGNED NOT NULL DEFAULT 0,
InactivityTS BIGINT UNSIGNED NOT NULL DEFAULT 0, InactivityTS BIGINT UNSIGNED NOT NULL DEFAULT 0,
RegistrationTS TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, RegistrationTS TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
CommentNotify TINYINT(1) NOT NULL DEFAULT 1,
PRIMARY KEY (ID), PRIMARY KEY (ID),
UNIQUE (Username), UNIQUE (Username),
UNIQUE (Email), UNIQUE (Email),

View file

@ -95,6 +95,16 @@ def get_recipients(cur, pkgbase_id, uid):
return [row[0] for row in cur.fetchall()] return [row[0] for row in cur.fetchall()]
def get_comment_recipients(cur, pkgbase_id, uid):
cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
'INNER JOIN PackageNotifications ' +
'ON PackageNotifications.UserID = Users.ID WHERE ' +
'Users.CommentNotify = 1 AND ' +
'PackageNotifications.UserID != %s AND ' +
'PackageNotifications.PackageBaseID = %s', [uid, pkgbase_id])
return [row[0] for row in cur.fetchall()]
def get_request_recipients(cur, pkgbase_id, uid): def get_request_recipients(cur, pkgbase_id, uid):
cur.execute('SELECT DISTINCT Users.Email FROM Users ' + cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
'INNER JOIN PackageBases ' + 'INNER JOIN PackageBases ' +
@ -159,7 +169,7 @@ def welcome(cur, uid):
def comment(cur, uid, pkgbase_id, comment_id): def comment(cur, uid, pkgbase_id, comment_id):
user = username_from_id(cur, uid) user = username_from_id(cur, uid)
pkgbase = pkgbase_from_id(cur, pkgbase_id) pkgbase = pkgbase_from_id(cur, pkgbase_id)
to = get_recipients(cur, pkgbase_id, uid) to = get_comment_recipients(cur, pkgbase_id, uid)
text = get_comment(cur, comment_id) text = get_comment(cur, comment_id)
user_uri = aur_location + '/account/' + user + '/' user_uri = aur_location + '/account/' + user + '/'

View file

@ -47,3 +47,10 @@ ALTER TABLE PackageBases MODIFY COLUMN FlaggerComment TEXT NOT NULL DEFAULT '';
---- ----
ALTER TABLE CommentNotify RENAME TO PackageNotifications; ALTER TABLE CommentNotify RENAME TO PackageNotifications;
---- ----
8. Add new columns to store notification settings:
----
ALTER TABLE Users
ADD COLUMN CommentNotify TINYINT(1) NOT NULL DEFAULT 1;
----

View file

@ -35,7 +35,8 @@ if ($action == "UpdateAccount") {
in_request("E"), in_request("H"), in_request("P"), in_request("E"), in_request("H"), in_request("P"),
in_request("C"), in_request("R"), in_request("L"), in_request("C"), in_request("R"), in_request("L"),
in_request("I"), in_request("K"), in_request("PK"), in_request("I"), in_request("K"), in_request("PK"),
in_request("J"), in_request("ID"), $row["Username"]); in_request("J"), in_request("CN"), in_request("ID"),
$row["Username"]);
} }
} }
@ -81,7 +82,8 @@ if (isset($_COOKIE["AURSID"])) {
$row["AccountTypeID"], $row["Suspended"], $row["Email"], $row["AccountTypeID"], $row["Suspended"], $row["Email"],
$row["HideEmail"], "", "", $row["RealName"], $row["HideEmail"], "", "", $row["RealName"],
$row["LangPreference"], $row["IRCNick"], $row["PGPKey"], $PK, $row["LangPreference"], $row["IRCNick"], $row["PGPKey"], $PK,
$row["InactivityTS"] ? 1 : 0, $row["ID"], $row["Username"]); $row["InactivityTS"] ? 1 : 0, $row["CommentNotify"],
$row["ID"], $row["Username"]);
} else { } else {
print __("You do not have permission to edit this account."); print __("You do not have permission to edit this account.");
} }
@ -114,10 +116,14 @@ if (isset($_COOKIE["AURSID"])) {
print $update_account_message; print $update_account_message;
if (!$success) { if (!$success) {
display_account_form("UpdateAccount", in_request("U"), in_request("T"), display_account_form("UpdateAccount", in_request("U"),
in_request("S"), in_request("E"), in_request("H"), in_request("P"), in_request("T"), in_request("S"),
in_request("C"), in_request("R"), in_request("L"), in_request("I"), in_request("E"), in_request("H"),
in_request("K"), in_request("PK"), in_request("J"), in_request("ID"), in_request("P"), in_request("C"),
in_request("R"), in_request("L"),
in_request("I"), in_request("K"),
in_request("PK"), in_request("J"),
in_request("CN"), in_request("ID"),
$row["Username"]); $row["Username"]);
} }

View file

@ -23,7 +23,7 @@ if (in_request("Action") == "NewAccount") {
"new", "NewAccount", in_request("U"), 1, 0, "new", "NewAccount", in_request("U"), 1, 0,
in_request("E"), in_request("H"), '', '', in_request("R"), in_request("E"), in_request("H"), '', '', in_request("R"),
in_request("L"), in_request("I"), in_request("K"), in_request("L"), in_request("I"), in_request("K"),
in_request("PK")); in_request("PK"), 0, in_request("CN"));
print $message; print $message;
@ -31,7 +31,7 @@ if (in_request("Action") == "NewAccount") {
display_account_form("NewAccount", in_request("U"), 1, 0, display_account_form("NewAccount", in_request("U"), 1, 0,
in_request("E"), in_request("H"), '', '', in_request("R"), in_request("E"), in_request("H"), '', '', in_request("R"),
in_request("L"), in_request("I"), in_request("K"), in_request("L"), in_request("I"), in_request("K"),
in_request("PK")); in_request("PK"), 0, in_request("CN"));
} }
} else { } else {
print '<p>' . __("Use this form to create an account.") . '</p>'; print '<p>' . __("Use this form to create an account.") . '</p>';

View file

@ -56,13 +56,14 @@ function html_format_pgp_fingerprint($fingerprint) {
* @param string $K The PGP key fingerprint of the displayed user * @param string $K The PGP key fingerprint of the displayed user
* @param string $PK The list of SSH public keys * @param string $PK The list of SSH public keys
* @param string $J The inactivity status of the displayed user * @param string $J The inactivity status of the displayed user
* @param string $CN Whether to notify of new comments
* @param string $UID The user ID of the displayed user * @param string $UID The user ID of the displayed user
* @param string $N The username as present in the database * @param string $N The username as present in the database
* *
* @return void * @return void
*/ */
function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="", function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R="",
$L="",$I="",$K="",$PK="",$J="",$UID=0,$N="") { $L="",$I="",$K="",$PK="",$J="",$CN="",$UID=0,$N="") {
global $SUPPORTED_LANGS; global $SUPPORTED_LANGS;
include("account_edit_form.php"); include("account_edit_form.php");
@ -88,13 +89,14 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R=""
* @param string $K The PGP fingerprint of the user * @param string $K The PGP fingerprint of the user
* @param string $PK The list of public SSH keys * @param string $PK The list of public SSH keys
* @param string $J The inactivity status of the user * @param string $J The inactivity status of the user
* @param string $CN Whether to notify of new comments
* @param string $UID The user ID of the modified account * @param string $UID The user ID of the modified account
* @param string $N The username as present in the database * @param string $N The username as present in the database
* *
* @return array Boolean indicating success and message to be printed * @return array Boolean indicating success and message to be printed
*/ */
function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="", function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",
$R="",$L="",$I="",$K="",$PK="",$J="",$UID=0,$N="") { $R="",$L="",$I="",$K="",$PK="",$J="",$CN="",$UID=0,$N="") {
global $SUPPORTED_LANGS; global $SUPPORTED_LANGS;
$error = ''; $error = '';
@ -341,6 +343,7 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C=""
$q.= ", IRCNick = " . $dbh->quote($I); $q.= ", IRCNick = " . $dbh->quote($I);
$q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K)); $q.= ", PGPKey = " . $dbh->quote(str_replace(" ", "", $K));
$q.= ", InactivityTS = " . $inactivity_ts; $q.= ", InactivityTS = " . $inactivity_ts;
$q.= ", CommentNotify = " . ($CN ? "1" : "0");
$q.= " WHERE ID = ".intval($UID); $q.= " WHERE ID = ".intval($UID);
$result = $dbh->exec($q); $result = $dbh->exec($q);

View file

@ -133,6 +133,14 @@
</p> </p>
</fieldset> </fieldset>
<fieldset>
<legend><?= __("Notification settings") ?>:</legend>
<p>
<label for="id_commentnotify"><?= __("Notify of new comments") ?>:</label>
<input type="checkbox" name="CN" id="id_commentnotify" <?= $CN ? 'checked="checked"' : '' ?> />
</p>
</fieldset>
<fieldset> <fieldset>
<p> <p>
<label></label> <label></label>