summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-02-21 19:44:38 +0100
committerLukas Fleischer <lfleischer@archlinux.org>2016-02-21 20:01:13 +0100
commit6ec4a3589e327ded693ab0c741828fc5ec66b840 (patch)
treebe01ad41fa61a44a43010f3fbd5249c606bd70df /scripts
parentc23914fc1df309a6b1d85ec5387cfbef2161e655 (diff)
downloadaur-6ec4a3589e327ded693ab0c741828fc5ec66b840.tar.gz
aur-6ec4a3589e327ded693ab0c741828fc5ec66b840.tar.xz
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>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/notify.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/notify.py b/scripts/notify.py
index 25102a26..5e5f3772 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,