Merge lp:~adeuring/launchpad/bug-39674-flip-lfa-restricted-flag into lp:launchpad/db-devel
Status: | Merged |
---|---|
Approved by: | Deryck Hodge |
Approved revision: | no longer in the source branch. |
Merged at revision: | 9616 |
Proposed branch: | lp:~adeuring/launchpad/bug-39674-flip-lfa-restricted-flag |
Merge into: | lp:launchpad/db-devel |
Diff against target: |
185 lines (+68/-9) 5 files modified
database/schema/security.cfg (+1/-0) lib/canonical/launchpad/tests/test_libraryfilealias_with_parent.py (+3/-3) lib/lp/bugs/doc/bugattachments.txt (+42/-1) lib/lp/bugs/interfaces/bug.py (+8/-2) lib/lp/bugs/model/bug.py (+14/-3) |
To merge this branch: | bzr merge lp:~adeuring/launchpad/bug-39674-flip-lfa-restricted-flag |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Deryck Hodge (community) | code | Approve | |
Review via email: mp+31558@code.launchpad.net |
Description of the change
This branch is another sequel to fix bug 39674: "Attachments of private bugreports are public".
When an attachment is adde to a private bug, the "restricted" flag of the related Librarian file is set. Similary, the "restricted" flag is changed when Bug.setPrivate() is called.
I removed the method IBug.linkAttach
Bug.linkAttachm
test: ./bin/test -t bugattachments.txt
= Launchpad lint =
Checking for conflicts and issues in changed files.
Linting changed files:
lib/lp/
lib/lp/
lib/lp/
./lib/lp/
375: E301 expected 1 blank line, found 2
1064: E301 expected 1 blank line, found 2
Seems that the linter is confused by comments...
This branch is based on lp:~adeuring/launchpad/bug-39674-use-proxied-lfa which is reviewed but which is still in EC2. The diff against that branch:
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -521,72 +521,25 @@
True
-Linking existing LibraryFileAliases as attachments
-------
-
-It's possible to link an existing LibraryFileAliases to a bug as an
-attachment by calling the bug's linkAttachment() method.
-
- >>> from canonical.
- ... ILibraryFileAli
-
- >>> file_content = "Hello, world"
- >>> content_type = "text/plain"
- >>> file_alias = getUtility(
- ... name='foobar', size=len(
- ... file=StringIO(
- >>> transaction.
-
- >>> bug = factory.makeBug()
- >>> bug.linkAttachment(
- ... owner=bug.owner, file_alias=
- ... comment="Some attachment")
- <BugAttachment ...>
-
- >>> bug.attachments
- 1
- >>> attachment = bug.attachments[0]
- >>> print attachment.title
- foobar
-
-The attachment will have a type of BugAttachmentTy
-we didn't specify that it was a patch.
-
- >>> print attachment.
- Unspecified
-
-We can specify that the attachment is a patch and give it a more
-meaningful description.
-
- >>> file_alias = getUtility(
- ... name='anotherfo
- ... file=StringIO(
- >>> transaction.
-
- >>> bug.linkAttachment(
- ... owner=bug.owner, file_alias=
- ... comment="Some attachment", is_patch=True,
- ... description="An attachment of some sort")
- <BugAttachment ...>
-
- >>> bug.attachments
- 2
- >>> attachment = bug.attachments[1]
- >>> print attachment.title
- An attachment of some sort
-
- >>> print attachment.
- Patch
-
-
Attachments without library files
------
It can happen that the LibraryFileContent record of a bug attachment is
deleted, for example. because an admin deleted a privacy sensitive file.
These attachments are not included in Bug.attachments. Our test bug has
-at present two attachments.
+two attachments.
+ >>> bug = factory.makeBug()
+ >>> file_content = "Hello, world"
+ >>> bug.addAttachment(
+ ... owner=bug.owner, data="Hello, world", filename="foobar",
+ ... comment="Some attachment")
+ <BugAttachment ...>
+ >>> bug.addAttachment(
+ ... owner=bug.owner, data="whatever", filename=
+ ... comment="Some attachment",
+ ... description="An attachment of some sort")
+ <BugAttachment ...>
>>> [attachment.title for attachment in bug.attachments]
[u'foobar', u'An attachment of some sort']
@@ -599,6 +552,42 @@
[u'foobar']
+Adding bug attachments to private bugs
+------
+
+If an attachment is added to a private bug, the "restricted" flag of
+its Librarian file is set.
+
+ >>> private_bug_owner = factory.
+ >>> login_person(
+ >>> private_bug = factory.
+ >>> private_attachment = private_
+ ... owner=private_
+ ... comment="Some attachment")
+ >>> private_
+ True
+
+But the "restricted" flag of Librarian files elonging to bug attachments
+of public bugs is not set.
+
+ >>> attachment.
+ False
+
+If a private bug becomes public, the restricted flag of the related
+Librarian files are no longer set.
+
+ >>> changed = private_
+ >>> private_
+ False
+
+Similary, if a public bug becomes private, the "restricted" flag of
+its Librarian files are set.
+
+ >>> changed = bug.setPrivate(
+ >>> attachment.
+ True
+
+
Miscellaneous
-------------
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -135,6 +135,7 @@
except NotFoundError:
return None
+
class IBugBecameQuest
"""A bug became a question."""
@@ -522,18 +523,6 @@
:is_patch: A boolean.
"""
- def linkAttachment(
- description=None):
- """Link an `ILibraryFileAlias` to this bug.
-
- :owner: An IPerson.
- :file_alias: The `ILibraryFileAlias` to link to this bug.
- :description: A brief description of the attachment.
- :comment: An IMessage or string.
- :filename: A string.
- :is_patch: A boolean.
- """
-
def linkCVE(cve, user):
"""Ensure that this CVE is linked to this bug."""
@@ -716,7 +705,7 @@
This may also cause the security contact to be subscribed
if one is registered and if the bug is not private.
-
+
Return True if a change is made, False otherwise.
"""
@@ -825,6 +814,7 @@
Returns True or False.
"""
+
class InvalidDuplicat
"""A bug cannot be set as the duplicate of another."""
webservice
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -694,7 +694,8 @@
if recipients is not None:
for subscriber in dupe_subscribers:
- recipients.
+ recipients.
+ subscriber, dupe_details[
return sorted(
@@ -959,13 +960,26 @@
filealias = getUtility(
- file=StringIO(
+ file=StringIO(
+ restricted=
return self.linkAttach
owner, filealias, comment, is_patch, description)
def linkAttachment(
+ """Link an `ILibraryFileAlias` to this bug.
+
+ :owner: An IPerson.
+ :file_alias: The `ILibraryFileAlias` to link to this bug.
+ :description: A brief description of the attachment.
+ :comment: An IMessage or string.
+ :is_patch: A boolean.
+
+ This method should only be called by addAttachment(), otherwise
+ we may get inconsistent settings of bug.private and
+ file_alias.
+ """
if is_patch:
else:
@@ -1388,6 +1402,9 @@
+ for attachment in self.attachments:
+ attachment.
+
# Correct the heat for the bug immediately, so that we don't have
# to wait for the next calculation job for the adjusted heat.
@@ -1941,4 +1958,3 @@
def asDict(self):
"""Return the FileBugData instance as a dict."""
return self.__
-
Looks good. As noted on IRC, there is one typo that I spotted:
"Librarian files elonging [...]" in bugattachment.txt.
I also suggested that we make it more obvious that linkAttachment is only used for addAttachment by renaming it to the pseudo-private form, _linkAttachment.
With these minor edits, consider this r=me.
Cheers,
deryck