Merge ~ines-almeida/launchpad:update-queued-webhook-table-permissions into launchpad:master

Proposed by Ines Almeida
Status: Merged
Approved by: Ines Almeida
Approved revision: 75f47e2defc8cfc26a20113eb2ceb63cc16f5c19
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ines-almeida/launchpad:update-queued-webhook-table-permissions
Merge into: launchpad:master
Diff against target: 114 lines (+85/-0)
2 files modified
database/schema/security.cfg (+2/-0)
lib/lp/soyuz/tests/test_packagecopyjob.py (+83/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Guruprasad Approve
Review via email: mp+445444@code.launchpad.net

Commit message

Update 'queued' database permissions for webhook and webhookjob table

Add unit test to verify the change

Description of the change

We recently deployed the change that triggers webhooks on bugs creation/change.
Publishing a package with which bugs were fixed within the changelog, changes the status of those bugs to 'FIX RELEASED' which in turn will try to trigger webhooks if they are set up.
This was causing problems because the `queued` user didn'thave permissions to access the `webhook` and `webhookjob` tables.

This MP adds those permissions to the needed user.

The added unit test failed before the database permissions update, and passes after the change is applied.

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM 👍

review: Approve
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/database/schema/security.cfg b/database/schema/security.cfg
2index 4cb79a4..c48a956 100644
3--- a/database/schema/security.cfg
4+++ b/database/schema/security.cfg
5@@ -1678,6 +1678,8 @@ public.teammembership = SELECT
6 public.teamparticipation = SELECT, INSERT
7 public.validpersoncache = SELECT
8 public.validpersonorteamcache = SELECT
9+public.webhook = SELECT
10+public.webhookjob = SELECT, INSERT
11 public.xref = SELECT, INSERT
12 type=user
13
14diff --git a/lib/lp/soyuz/tests/test_packagecopyjob.py b/lib/lp/soyuz/tests/test_packagecopyjob.py
15index 645683b..f4d2e53 100644
16--- a/lib/lp/soyuz/tests/test_packagecopyjob.py
17+++ b/lib/lp/soyuz/tests/test_packagecopyjob.py
18@@ -18,6 +18,7 @@ from zope.component import getUtility
19 from zope.security.interfaces import Unauthorized
20 from zope.security.proxy import removeSecurityProxy
21
22+from lp.bugs.interfaces.bugtarget import BUG_WEBHOOKS_FEATURE_FLAG
23 from lp.bugs.interfaces.bugtask import BugTaskStatus
24 from lp.registry.interfaces.pocket import PackagePublishingPocket
25 from lp.registry.interfaces.series import SeriesStatus
26@@ -1660,6 +1661,88 @@ class PlainPackageCopyJobTests(TestCaseWithFactory, LocalTestHelper):
27 self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask281.status)
28 self.assertEqual(BugTaskStatus.NEW, bugtask280.status)
29
30+ def test_copying_closes_bugs_with_webhooks(self):
31+ # Copying a package into a primary archive closes any bugs mentioned
32+ # in its recent changelog, including triggering their webhooks.
33+
34+ # Set bug webhooks feature flag on for the purpose of this test
35+ self.useFixture(
36+ FeatureFixture(
37+ {
38+ BUG_WEBHOOKS_FEATURE_FLAG: "on",
39+ }
40+ )
41+ )
42+
43+ target_archive = self.factory.makeArchive(
44+ self.distroseries.distribution, purpose=ArchivePurpose.PRIMARY
45+ )
46+ source_archive = self.factory.makeArchive(
47+ self.distroseries.distribution
48+ )
49+ bug = self.factory.makeBug()
50+ webhook = self.factory.makeWebhook(
51+ target=bug.default_bugtask.target,
52+ event_types=["bug:comment:0.1", "bug:0.1"],
53+ )
54+
55+ # Publish a package in the source archive and give it a changelog
56+ # entry that closes a bug.
57+ source_pub = self.factory.makeSourcePackagePublishingHistory(
58+ distroseries=self.distroseries,
59+ sourcepackagename="libc",
60+ version="2.8-2",
61+ status=PackagePublishingStatus.PUBLISHED,
62+ archive=source_archive,
63+ )
64+ spr = removeSecurityProxy(source_pub).sourcepackagerelease
65+ changelog = dedent(
66+ """\
67+ libc (2.8-2) unstable; urgency=low
68+
69+ * closes: %s
70+
71+ -- Foo Bar <foo@example.com> Tue, 01 Jan 1970 01:50:41 +0000
72+
73+ libc (2.8-1) unstable; urgency=low
74+
75+ * Initial release.
76+
77+ -- Foo Bar <foo@example.com> Tue, 01 Jan 1970 01:50:41 +0000
78+ """
79+ % bug.id
80+ ).encode("UTF-8")
81+ spr.changelog = self.factory.makeLibraryFileAlias(content=changelog)
82+ spr.changelog_entry = "dummy"
83+ self.layer.txn.commit() # Librarian.
84+
85+ # Now put the same named package in the target archive at the
86+ # oldest version in the changelog.
87+ self.publisher.getPubSource(
88+ distroseries=self.distroseries,
89+ sourcename="libc",
90+ version="2.8-1",
91+ status=PackagePublishingStatus.PUBLISHED,
92+ archive=target_archive,
93+ )
94+
95+ sp = self.distroseries.getSourcePackage(spr.sourcepackagename)
96+ bugtask = self.factory.makeBugTask(target=sp, bug=bug, publish=False)
97+
98+ # Run the copy job.
99+ requester = self.factory.makePerson()
100+ with person_logged_in(target_archive.owner):
101+ target_archive.newComponentUploader(requester, "main")
102+ job = self.createCopyJobForSPPH(
103+ source_pub, source_archive, target_archive, requester=requester
104+ )
105+ self.runJob(job)
106+ self.assertEqual(JobStatus.COMPLETED, job.status)
107+
108+ # The bug is fixed, and a webhook delivery is scheduled.
109+ self.assertEqual(BugTaskStatus.FIXRELEASED, bugtask.status)
110+ self.assertEqual(1, webhook.deliveries.count())
111+
112 def test_copying_unembargoes_files(self):
113 # The unembargo flag causes the job to unrestrict files.
114 self.distroseries.status = SeriesStatus.CURRENT

Subscribers

People subscribed via source and target branches

to status/vote changes: