From 6ec4a3589e327ded693ab0c741828fc5ec66b840 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sun, 21 Feb 2016 19:44:38 +0100 Subject: 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 --- scripts/notify.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'scripts') diff --git a/scripts/notify.py b/scripts/notify.py index 25102a2..5e5f377 100755 --- a/scripts/notify.py +++ b/scripts/notify.py @@ -115,6 +115,16 @@ def get_update_recipients(cur, pkgbase_id, uid): 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): cur.execute('SELECT DISTINCT Users.Email FROM PackageRequests ' + 'INNER JOIN PackageBases ' + @@ -243,6 +253,38 @@ def flag(cur, uid, pkgbase_id): 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): pkgbase = pkgbase_from_id(cur, pkgbase_id) to = [get_user_email(cur, uid)] @@ -364,6 +406,8 @@ if __name__ == '__main__': 'comment': comment, 'update': update, 'flag': flag, + 'adopt': adopt, + 'disown': disown, 'comaintainer-add': comaintainer_add, 'comaintainer-remove': comaintainer_remove, 'delete': delete, -- cgit v1.2.3-70-g09d2