mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Send notifications when changing ownership
Add a new option that makes it possible to subscribe to package ownership changes (adoption/disownment). Fixes FS#15412. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
c23914fc1d
commit
6ec4a3589e
5 changed files with 65 additions and 3 deletions
|
@ -115,6 +115,16 @@ def get_update_recipients(cur, pkgbase_id, uid):
|
||||||
return [row[0] for row in cur.fetchall()]
|
return [row[0] for row in cur.fetchall()]
|
||||||
|
|
||||||
|
|
||||||
|
def get_ownership_recipients(cur, pkgbase_id, uid):
|
||||||
|
cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
|
||||||
|
'INNER JOIN PackageNotifications ' +
|
||||||
|
'ON PackageNotifications.UserID = Users.ID WHERE ' +
|
||||||
|
'Users.OwnershipNotify = 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, reqid):
|
def get_request_recipients(cur, reqid):
|
||||||
cur.execute('SELECT DISTINCT Users.Email FROM PackageRequests ' +
|
cur.execute('SELECT DISTINCT Users.Email FROM PackageRequests ' +
|
||||||
'INNER JOIN PackageBases ' +
|
'INNER JOIN PackageBases ' +
|
||||||
|
@ -243,6 +253,38 @@ def flag(cur, uid, pkgbase_id):
|
||||||
send_notification(to, subject, body, refs)
|
send_notification(to, subject, body, refs)
|
||||||
|
|
||||||
|
|
||||||
|
def adopt(cur, pkgbase_id, uid):
|
||||||
|
user = username_from_id(cur, uid)
|
||||||
|
pkgbase = pkgbase_from_id(cur, pkgbase_id)
|
||||||
|
to = get_ownership_recipients(cur, pkgbase_id, uid)
|
||||||
|
|
||||||
|
user_uri = aur_location + '/account/' + user + '/'
|
||||||
|
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
|
||||||
|
|
||||||
|
subject = 'AUR Ownership Notification for %s' % (pkgbase)
|
||||||
|
body = 'The package %s [1] was adopted by %s [2].' % (pkgbase, user)
|
||||||
|
refs = '[1] ' + pkgbase_uri + '\n'
|
||||||
|
refs += '[2] ' + user_uri
|
||||||
|
|
||||||
|
send_notification(to, subject, body, refs)
|
||||||
|
|
||||||
|
|
||||||
|
def disown(cur, pkgbase_id, uid):
|
||||||
|
user = username_from_id(cur, uid)
|
||||||
|
pkgbase = pkgbase_from_id(cur, pkgbase_id)
|
||||||
|
to = get_ownership_recipients(cur, pkgbase_id, uid)
|
||||||
|
|
||||||
|
user_uri = aur_location + '/account/' + user + '/'
|
||||||
|
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
|
||||||
|
|
||||||
|
subject = 'AUR Ownership Notification for %s' % (pkgbase)
|
||||||
|
body = 'The package %s [1] was disowned by %s [2].' % (pkgbase, user)
|
||||||
|
refs = '[1] ' + pkgbase_uri + '\n'
|
||||||
|
refs += '[2] ' + user_uri
|
||||||
|
|
||||||
|
send_notification(to, subject, body, refs)
|
||||||
|
|
||||||
|
|
||||||
def comaintainer_add(cur, pkgbase_id, uid):
|
def comaintainer_add(cur, pkgbase_id, uid):
|
||||||
pkgbase = pkgbase_from_id(cur, pkgbase_id)
|
pkgbase = pkgbase_from_id(cur, pkgbase_id)
|
||||||
to = [get_user_email(cur, uid)]
|
to = [get_user_email(cur, uid)]
|
||||||
|
@ -364,6 +406,8 @@ if __name__ == '__main__':
|
||||||
'comment': comment,
|
'comment': comment,
|
||||||
'update': update,
|
'update': update,
|
||||||
'flag': flag,
|
'flag': flag,
|
||||||
|
'adopt': adopt,
|
||||||
|
'disown': disown,
|
||||||
'comaintainer-add': comaintainer_add,
|
'comaintainer-add': comaintainer_add,
|
||||||
'comaintainer-remove': comaintainer_remove,
|
'comaintainer-remove': comaintainer_remove,
|
||||||
'delete': delete,
|
'delete': delete,
|
||||||
|
|
5
upgrading/4.3.0.txt
Normal file
5
upgrading/4.3.0.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
1. Add a column to store ownership notification settings:
|
||||||
|
|
||||||
|
----
|
||||||
|
ALTER TABLE Users ADD COLUMN OwnershipNotify TINYINT(1) NOT NULL DEFAULT 1;
|
||||||
|
----
|
|
@ -58,13 +58,14 @@ function html_format_pgp_fingerprint($fingerprint) {
|
||||||
* @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 $CN Whether to notify of new comments
|
||||||
* @param string $UN Whether to notify of package updates
|
* @param string $UN Whether to notify of package updates
|
||||||
|
* @param string $ON Whether to notify of ownership changes
|
||||||
* @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="",$CN="",$UN="",$UID=0,$N="") {
|
$L="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") {
|
||||||
global $SUPPORTED_LANGS;
|
global $SUPPORTED_LANGS;
|
||||||
|
|
||||||
include("account_edit_form.php");
|
include("account_edit_form.php");
|
||||||
|
@ -92,13 +93,14 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$H="",$P="",$C="",$R=""
|
||||||
* @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 $CN Whether to notify of new comments
|
||||||
* @param string $UN Whether to notify of package updates
|
* @param string $UN Whether to notify of package updates
|
||||||
|
* @param string $ON Whether to notify of ownership changes
|
||||||
* @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="",$CN="",$UN="",$UID=0,$N="") {
|
$R="",$L="",$I="",$K="",$PK="",$J="",$CN="",$UN="",$ON="",$UID=0,$N="") {
|
||||||
global $SUPPORTED_LANGS;
|
global $SUPPORTED_LANGS;
|
||||||
|
|
||||||
$error = '';
|
$error = '';
|
||||||
|
@ -347,6 +349,7 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$H="",$P="",$C=""
|
||||||
$q.= ", InactivityTS = " . $inactivity_ts;
|
$q.= ", InactivityTS = " . $inactivity_ts;
|
||||||
$q.= ", CommentNotify = " . ($CN ? "1" : "0");
|
$q.= ", CommentNotify = " . ($CN ? "1" : "0");
|
||||||
$q.= ", UpdateNotify = " . ($UN ? "1" : "0");
|
$q.= ", UpdateNotify = " . ($UN ? "1" : "0");
|
||||||
|
$q.= ", OwnershipNotify = " . ($ON ? "1" : "0");
|
||||||
$q.= " WHERE ID = ".intval($UID);
|
$q.= " WHERE ID = ".intval($UID);
|
||||||
$result = $dbh->exec($q);
|
$result = $dbh->exec($q);
|
||||||
|
|
||||||
|
|
|
@ -661,6 +661,9 @@ function pkgbase_adopt ($base_ids, $action=true, $via) {
|
||||||
$q.= "SET MaintainerUID = $uid ";
|
$q.= "SET MaintainerUID = $uid ";
|
||||||
$q.= "WHERE ID IN (" . implode(",", $base_ids) . ") ";
|
$q.= "WHERE ID IN (" . implode(",", $base_ids) . ") ";
|
||||||
$dbh->exec($q);
|
$dbh->exec($q);
|
||||||
|
|
||||||
|
/* Add the new maintainer to the notification list. */
|
||||||
|
pkgbase_notify($base_ids);
|
||||||
} else {
|
} else {
|
||||||
/* Update the co-maintainer list when disowning a package. */
|
/* Update the co-maintainer list when disowning a package. */
|
||||||
if (has_credential(CRED_PKGBASE_DISOWN)) {
|
if (has_credential(CRED_PKGBASE_DISOWN)) {
|
||||||
|
@ -692,8 +695,11 @@ function pkgbase_adopt ($base_ids, $action=true, $via) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($base_ids as $base_id) {
|
||||||
|
notify(array($action ? 'adopt' : 'disown', $base_id, $uid));
|
||||||
|
}
|
||||||
|
|
||||||
if ($action) {
|
if ($action) {
|
||||||
pkgbase_notify($base_ids);
|
|
||||||
return array(true, __("The selected packages have been adopted."));
|
return array(true, __("The selected packages have been adopted."));
|
||||||
} else {
|
} else {
|
||||||
return array(true, __("The selected packages have been disowned."));
|
return array(true, __("The selected packages have been disowned."));
|
||||||
|
|
|
@ -143,6 +143,10 @@
|
||||||
<label for="id_updatenotify"><?= __("Notify of package updates") ?>:</label>
|
<label for="id_updatenotify"><?= __("Notify of package updates") ?>:</label>
|
||||||
<input type="checkbox" name="UN" id="id_updatenotify" <?= $UN ? 'checked="checked"' : '' ?> />
|
<input type="checkbox" name="UN" id="id_updatenotify" <?= $UN ? 'checked="checked"' : '' ?> />
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="id_ownershipnotify"><?= __("Notify of ownership changes") ?>:</label>
|
||||||
|
<input type="checkbox" name="ON" id="id_ownershipnotify" <?= $ON ? 'checked="checked"' : '' ?> />
|
||||||
|
</p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|
Loading…
Add table
Reference in a new issue