Merge lp:~henninge/launchpad/access-to-translationgroup-table into lp:launchpad/db-devel

Proposed by Henning Eggers
Status: Merged
Approved by: Henning Eggers
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~henninge/launchpad/access-to-translationgroup-table
Merge into: lp:launchpad/db-devel
Diff against target: 145 lines (+78/-9)
2 files modified
database/schema/security.cfg (+3/-0)
lib/lp/translations/tests/test_translationimportqueue.py (+75/-9)
To merge this branch: bzr merge lp:~henninge/launchpad/access-to-translationgroup-table
Reviewer Review Type Date Requested Status
Muharem Hrnjadovic (community) code Approve
Julian Edwards (community) Needs Fixing
Guilherme Salgado release-critical Pending
Review via email: mp+15643@code.launchpad.net

Commit message

Add permissions to queued user to fix translations uploads.

To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :

Added database permission to fix this:
http://launchpadlibrarian.net/36423030/bDF1qc8NVJ5FX6mGghGbd19C93f.txt

Julian Edwards on the launchpad ML (typo removed):
> It's basically because process-accepted script (which runs with the "queued"
> database user) did not have permission to access translationgroup. Is this
> a new table in 3.1.11?
>
> Stub hacked SELECT permissions into the live database for now but I'd be keen
> to discuss a solution with you on how we can avoid this in the future. It
> probably involves you being aware of soyuz upload tests when making changes to
> translation import code.

Revision history for this message
Julian Edwards (julian-edwards) wrote :

As discussed on IRC we should really have a test that uploads some translations so it doesn't happen again.

review: Needs Fixing
Revision history for this message
Henning Eggers (henninge) wrote :

== Test ==

bin/test -vvt lp.translations.tests.test_translationimportqueue

Revision history for this message
Henning Eggers (henninge) wrote :

After a not-so-successful high-level approach (calling addOrUpdateEntryFromTarball), I went for low-level testing on canSetStatus. It actually produced more problems with access to pofile and potemplate tables, so I included these, too.

Revision history for this message
Muharem Hrnjadovic (al-maisan) wrote :

Looks good!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/security.cfg'
2--- database/schema/security.cfg 2009-12-02 13:08:18 +0000
3+++ database/schema/security.cfg 2009-12-11 09:16:17 +0000
4@@ -1216,6 +1216,9 @@
5 public.libraryfilecontent = SELECT, INSERT
6
7 # rosetta auto imports
8+public.pofile = SELECT
9+public.potemplate = SELECT
10+public.translationgroup = SELECT
11 public.translationimportqueueentry = SELECT, INSERT, UPDATE
12
13 # Closing bugs.
14
15=== modified file 'lib/lp/translations/tests/test_translationimportqueue.py'
16--- lib/lp/translations/tests/test_translationimportqueue.py 2009-11-19 11:24:43 +0000
17+++ lib/lp/translations/tests/test_translationimportqueue.py 2009-12-11 09:16:17 +0000
18@@ -5,6 +5,7 @@
19
20 __metaclass__ = type
21
22+import transaction
23 import unittest
24
25 from zope.component import getUtility
26@@ -17,25 +18,27 @@
27 from canonical.testing import LaunchpadZopelessLayer
28
29
30-class TestTranslationImportQueueEntryStatus(TestCaseWithFactory):
31- """Test handling of the status of a queue entry."""
32+class TestCanSetStatusBase(TestCaseWithFactory):
33+ """Base for tests that check that canSetStatus works ."""
34
35 layer = LaunchpadZopelessLayer
36+ dbuser = None
37+ entry = None
38
39 def setUp(self):
40 """Set up context to test in."""
41- super(TestTranslationImportQueueEntryStatus, self).setUp()
42+ super(TestCanSetStatusBase, self).setUp()
43
44 self.queue = getUtility(ITranslationImportQueue)
45 self.rosetta_experts = (
46 getUtility(ILaunchpadCelebrities).rosetta_experts)
47 self.productseries = self.factory.makeProductSeries()
48 self.uploaderperson = self.factory.makePerson()
49- self.potemplate = self.factory.makePOTemplate(
50- productseries=self.productseries)
51- self.entry = self.queue.addOrUpdateEntry(
52- 'demo.pot', '#demo', False, self.uploaderperson,
53- productseries=self.productseries, potemplate=self.potemplate)
54+
55+ def _switch_dbuser(self):
56+ if self.dbuser != None:
57+ transaction.commit()
58+ self.layer.switchDbUser(self.dbuser)
59
60 def _assertCanSetStatus(self, user, entry, expected_list):
61 # Helper to check for all statuses.
62@@ -49,6 +52,7 @@
63 RosettaImportStatus.IMPORTED,
64 RosettaImportStatus.NEEDS_REVIEW,
65 ]
66+ self._switch_dbuser()
67 # Do *not* use assertContentEqual here, as the order matters.
68 self.assertEqual(expected_list,
69 [entry.canSetStatus(status, user)
70@@ -71,6 +75,7 @@
71 # If the entry has no import target set, even Rosetta experts
72 # cannot set it to approved.
73 self.entry.potemplate = None
74+ self.entry.pofile = None
75 self._assertCanSetStatus(self.rosetta_experts, self.entry,
76 # A B D F I NR
77 [False, True, True, True, True, True])
78@@ -115,5 +120,66 @@
79 [False, False, False, False, False, False])
80
81
82+class TestCanSetStatusPOTemplate(TestCanSetStatusBase):
83+ """Test canStatus applied to an entry with a POTemplate."""
84+
85+ def setUp(self):
86+ """Create the entry to test on."""
87+ super(TestCanSetStatusPOTemplate, self).setUp()
88+
89+ self.potemplate = self.factory.makePOTemplate(
90+ productseries=self.productseries)
91+ self.entry = self.queue.addOrUpdateEntry(
92+ 'demo.pot', '#demo', False, self.uploaderperson,
93+ productseries=self.productseries, potemplate=self.potemplate)
94+
95+
96+class TestCanSetStatusPOFile(TestCanSetStatusBase):
97+ """Test canStatus applied to an entry with a POFile."""
98+
99+ def setUp(self):
100+ """Create the entry to test on."""
101+ super(TestCanSetStatusPOFile, self).setUp()
102+
103+ self.potemplate = self.factory.makePOTemplate(
104+ productseries=self.productseries)
105+ self.pofile = self.factory.makePOFile('eo', potemplate=self.potemplate)
106+ self.entry = self.queue.addOrUpdateEntry(
107+ 'demo.po', '#demo', False, self.uploaderperson,
108+ productseries=self.productseries, pofile=self.pofile)
109+
110+
111+class TestCanSetStatusPOTemplateWithQueuedUser(TestCanSetStatusPOTemplate):
112+ """Test handling of the status of a queue entry with 'queued' db user.
113+
114+ The archive uploader needs to set (and therefore check) the status of a
115+ queue entry. It connects as a different database user and therefore we
116+ need to make sure that setStatus stays within this user's permissions.
117+ This is the version for POTemplate entries.
118+ """
119+
120+ dbuser = 'queued'
121+
122+
123+class TestCanSetStatusPOFileWithQueuedUser(TestCanSetStatusPOFile):
124+ """Test handling of the status of a queue entry with 'queued' db user.
125+
126+ The archive uploader needs to set (and therefore check) the status of a
127+ queue entry. It connects as a different database user and therefore we
128+ need to make sure that setStatus stays within this user's permissions.
129+ This is the version for POFile entries.
130+ """
131+
132+ dbuser = 'queued'
133+
134+
135 def test_suite():
136- return unittest.TestLoader().loadTestsFromName(__name__)
137+ """Add only specific test cases and leave out the base case."""
138+ suite = unittest.TestSuite()
139+ suite.addTest(unittest.makeSuite(TestCanSetStatusPOTemplate))
140+ suite.addTest(unittest.makeSuite(TestCanSetStatusPOFile))
141+ suite.addTest(
142+ unittest.makeSuite(TestCanSetStatusPOTemplateWithQueuedUser))
143+ suite.addTest(unittest.makeSuite(TestCanSetStatusPOFileWithQueuedUser))
144+ return suite
145+

Subscribers

People subscribed via source and target branches

to status/vote changes: