Merge lp:~salgado/offspring/lexbuilder-without-current-job-is-public into lp:offspring

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 114
Proposed branch: lp:~salgado/offspring/lexbuilder-without-current-job-is-public
Merge into: lp:offspring
Prerequisite: lp:~salgado/offspring/sidebars
Diff against target: 66 lines (+28/-3)
2 files modified
lib/offspring/web/queuemanager/models.py (+14/-3)
lib/offspring/web/queuemanager/tests/test_models.py (+14/-0)
To merge this branch: bzr merge lp:~salgado/offspring/lexbuilder-without-current-job-is-public
Reviewer Review Type Date Requested Status
Kevin McDermott Approve
Review via email: mp+85870@code.launchpad.net

Description of the change

Make sure Lexbuilders with no current_job are considered public

To post a comment you must log in.
113. By Guilherme Salgado

merge sidebars branch

Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Looks good

+ builder = factory.make_lexbuilder()
+ builder.current_job = None
+ builder.save()

this could be tidied up with kwargs on the make_lexbuilder to pass in current_job ?

review: Approve
Revision history for this message
Guilherme Salgado (salgado) wrote :

On 12/01/12 09:21, Kevin McDermott wrote:
> Review: Approve
>
> Looks good
>
> + builder = factory.make_lexbuilder()
> + builder.current_job = None
> + builder.save()
>
> this could be tidied up with kwargs on the make_lexbuilder to pass in current_job ?

make_lexbuilder() already takes a current_job argument but when it's
None it creates an arbitrary one. A bunch of tests rely on that so I
think it's easier to just keep this one as is, maybe with a comment like

# Must manually set current_job to None because the above call will
# create an arbitrary BuildResult and assign it to the newly created
# builder's current_job.
builder.current_job = None

Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Oh aye, fine with me :-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/offspring/web/queuemanager/models.py'
2--- lib/offspring/web/queuemanager/models.py 2012-01-11 18:22:25 +0000
3+++ lib/offspring/web/queuemanager/models.py 2012-01-11 18:22:25 +0000
4@@ -171,11 +171,18 @@
5 return privacy_attr
6
7 def _get_access_controlled_object(self):
8+ """Return the object associated to this one that is access controlled.
9+
10+ In some cases the relationship between this model and the one which is
11+ access controlled is NULLable (e.g. Lexbuilder.current_job), and if
12+ that's the case and there's no access-controlled object linked to this
13+ one, we return None.
14+ """
15 if getattr(self, 'access_relation', None) is None:
16 return self
17 names = self.access_relation.split('__')
18 obj = self
19- while len(names):
20+ while len(names) and obj is not None:
21 name = names.pop(0)
22 obj = getattr(obj, name)
23 return obj
24@@ -183,11 +190,15 @@
25 @property
26 def is_private(self):
27 obj = self._get_access_controlled_object()
28+ if obj is None:
29+ return False
30 return getattr(obj, self._privacy_attr_name)
31
32 def is_visible_to(self, user):
33- is_visible_to = getattr(self._get_access_controlled_object(),
34- self._is_visible_method_name)
35+ obj = self._get_access_controlled_object()
36+ if obj is None:
37+ return True
38+ is_visible_to = getattr(obj, self._is_visible_method_name)
39 return is_visible_to(user)
40
41
42
43=== modified file 'lib/offspring/web/queuemanager/tests/test_models.py'
44--- lib/offspring/web/queuemanager/tests/test_models.py 2012-01-11 18:22:25 +0000
45+++ lib/offspring/web/queuemanager/tests/test_models.py 2012-01-11 18:22:25 +0000
46@@ -309,6 +309,20 @@
47 return factory.make_lexbuilder(
48 current_job=factory.make_build_result(project=project))
49
50+ def test_lexbuilder_without_current_job(self):
51+ """
52+ A Lexbuilder with no current_job is not considered private and thus
53+ is visible to anyone.
54+ """
55+ builder = factory.make_lexbuilder()
56+ builder.current_job = None
57+ builder.save()
58+ user = factory.make_user()
59+ self.assertEqual(False, builder.is_private)
60+ self.assertEqual(True, builder.is_visible_to(user))
61+ self.assertEqual(
62+ [builder], list(self.model.all_objects.accessible_by_user(user)))
63+
64
65 class BuildResultTests(
66 TestCase, ReleaseOrLexbuilderOrBuildResultOrBuildRequestTestsMixin):

Subscribers

People subscribed via source and target branches