11532.10.8
by Curtis Hovey
Do not reassign the translation queue entry's importer if the user already has an entry in the queue. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
__metaclass__ = type |
|
5 |
||
6 |
__all__ = [ |
|
7 |
'product_modified', |
|
8 |
]
|
|
9 |
||
10 |
from zope.component import getUtility |
|
11 |
from zope.security.proxy import removeSecurityProxy |
|
12 |
||
13 |
from lp.translations.interfaces.translationimportqueue import ( |
|
14 |
ITranslationImportQueue, |
|
15 |
)
|
|
16 |
||
17 |
||
18 |
def product_modified(product, event): |
|
19 |
"""Update translations objects when the product changes."""
|
|
20 |
old_owner = event.object_before_modification.owner |
|
21 |
if old_owner != product.owner: |
|
22 |
import_queue = getUtility(ITranslationImportQueue) |
|
23 |
# The change in ownership may cause permission issues for
|
|
24 |
# entries in the translation import queue *if* the old owner has
|
|
25 |
# less permission now. This issue can be avoided by updating the
|
|
26 |
# entries's importer to the new owner. This can only be done if the
|
|
27 |
# new owner does not already have an entry in the queue.
|
|
28 |
# See bug 635438 for more details.
|
|
29 |
old_owner_entries = [] |
|
30 |
new_owner_entries = [] |
|
31 |
for entry in import_queue.getAllEntries(target=product): |
|
32 |
if entry.importer == old_owner: |
|
33 |
old_owner_entries.append(entry) |
|
34 |
elif entry.importer == product.owner: |
|
35 |
new_owner_entries.append(entry) |
|
36 |
else: |
|
11532.10.12
by Curtis Hovey
Reverted Product._owner. Updated _setOwner to notif ObjectModifiedEvent. Fixed comments. |
37 |
# The entry is not affected by the ownership change.
|
11532.10.8
by Curtis Hovey
Do not reassign the translation queue entry's importer if the user already has an entry in the queue. |
38 |
pass
|
39 |
if len(old_owner_entries) > 0 and len(new_owner_entries) == 0: |
|
40 |
# The new owner does not have any conflicting entries in the
|
|
41 |
# queue. Change the old owner's entries to the new owner to
|
|
11532.10.12
by Curtis Hovey
Reverted Product._owner. Updated _setOwner to notif ObjectModifiedEvent. Fixed comments. |
42 |
# ensure there is no permissions issues during processing.
|
11532.10.8
by Curtis Hovey
Do not reassign the translation queue entry's importer if the user already has an entry in the queue. |
43 |
for entry in old_owner_entries: |
44 |
removeSecurityProxy(entry).importer = product.owner |