Merge lp:~jcsackett/launchpad/no-questions-on-disabled into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 16356
Proposed branch: lp:~jcsackett/launchpad/no-questions-on-disabled
Merge into: lp:launchpad
Diff against target: 108 lines (+44/-1)
3 files modified
lib/lp/answers/browser/question.py (+13/-1)
lib/lp/answers/browser/tests/test_question.py (+18/-0)
lib/lp/answers/templates/question-add-search.pt (+13/-0)
To merge this branch: bzr merge lp:~jcsackett/launchpad/no-questions-on-disabled
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+138360@code.launchpad.net

Commit message

Updates addquestion UI to indicate when questions is not enabled.

Description of the change

Summary
=======
We don't want questions to be asked on private products, because there is no
concept of a private question and answers cannot be enabled for private
projects. The addquestion UI is not aware of service usage, and can still be
accessed via simply hacking together the +addquestion url.

We should do the same thing +filebug does, and indicate that answers is not
enabled, and if the user has the permission to do, let them go change that.

As LAUNCHPAD is not an option for private projects, this will still not allow
a user to create a leak.

Preimp
======
Spoke with Rick Harding.

Implementation
==============
The addquestion view gets a new method that checks if answes is enabled. If
its not, the ui is altered to display a message similar to the one shown by
+filebug if malone is not enabled.

Tests
=====
bin/test -vvct test_context_uses_answers

QA
==
Go to +addquestion on a product with answers disabled. You should see the
message indicating you cannot ask a question.

LoC
===
Part of private projects.

Lint
====

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/answers/browser/tests/test_question.py
  lib/lp/answers/templates/question-add-search.pt
  lib/lp/answers/browser/question.py

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/answers/browser/question.py'
2--- lib/lp/answers/browser/question.py 2012-11-26 08:40:20 +0000
3+++ lib/lp/answers/browser/question.py 2012-12-06 02:19:20 +0000
4@@ -85,11 +85,15 @@
5 safe_action,
6 )
7 from lp.app.browser.stringformatter import FormattersAPI
8+from lp.app.enums import ServiceUsage
9 from lp.app.errors import (
10 NotFoundError,
11 UnexpectedFormData,
12 )
13-from lp.app.interfaces.launchpad import ILaunchpadCelebrities
14+from lp.app.interfaces.launchpad import (
15+ ILaunchpadCelebrities,
16+ IServiceUsage,
17+ )
18 from lp.app.widgets.itemswidgets import LaunchpadRadioWidget
19 from lp.app.widgets.launchpadtarget import LaunchpadTargetWidget
20 from lp.app.widgets.project import ProjectScopeWidget
21@@ -641,6 +645,14 @@
22 """Return True if similar FAQs or questions were found."""
23 return self.similar_questions or self.similar_faqs
24
25+ @property
26+ def context_uses_answers(self):
27+ """Return True if the context uses launchpad as an answer forum."""
28+ if IServiceUsage.providedBy(self.context):
29+ return self.context.answers_usage == ServiceUsage.LAUNCHPAD
30+ else:
31+ return False
32+
33 @action(_('Continue'))
34 def continue_action(self, action, data):
35 """Search for questions and FAQs similar to the entered summary."""
36
37=== modified file 'lib/lp/answers/browser/tests/test_question.py'
38--- lib/lp/answers/browser/tests/test_question.py 2012-01-01 02:58:52 +0000
39+++ lib/lp/answers/browser/tests/test_question.py 2012-12-06 02:19:20 +0000
40@@ -7,12 +7,16 @@
41
42 __all__ = []
43
44+from zope.security.proxy import removeSecurityProxy
45 from lp.answers.browser.question import QuestionTargetWidget
46 from lp.answers.interfaces.question import IQuestion
47 from lp.answers.publisher import AnswersLayer
48+from lp.app.enums import ServiceUsage
49 from lp.services.webapp.servers import LaunchpadTestRequest
50 from lp.testing import (
51 login_person,
52+ logout,
53+ person_logged_in,
54 TestCaseWithFactory,
55 )
56 from lp.testing.layers import DatabaseFunctionalLayer
57@@ -55,6 +59,20 @@
58 self.assertEqual(
59 'The summary cannot exceed 250 characters.', view.errors[0])
60
61+ def test_context_uses_answers(self):
62+ # If a target doesn't use answers, it doesn't provide the form.
63+ #logout()
64+ owner = removeSecurityProxy(self.question_target).owner
65+ with person_logged_in(owner):
66+ self.question_target.answers_usage = ServiceUsage.NOT_APPLICABLE
67+ login_person(self.user)
68+ view = create_initialized_view(
69+ self.question_target, name='+addquestion', layer=AnswersLayer,
70+ principal=self.user)
71+ self.assertFalse(view.context_uses_answers)
72+ contents = view.render()
73+ msg = "<strong>does not use</strong> Launchpad as its answer forum"
74+ self.assertIn(msg, contents)
75
76 class QuestionEditViewTestCase(TestCaseWithFactory):
77 """Verify the behavior of the QuestionEditView."""
78
79=== modified file 'lib/lp/answers/templates/question-add-search.pt'
80--- lib/lp/answers/templates/question-add-search.pt 2009-08-19 16:48:37 +0000
81+++ lib/lp/answers/templates/question-add-search.pt 2012-12-06 02:19:20 +0000
82@@ -13,6 +13,7 @@
83 <body>
84
85 <metal:main fill-slot="main">
86+ <tal:answers_enabled condition="view/context_uses_answers">
87 <metal:form use-macro="context/@@launchpad_form/form">
88
89 <div metal:fill-slot="extra_info">
90@@ -38,6 +39,18 @@
91 </div>
92
93 </metal:form>
94+ </tal:answers_enabled>
95+
96+ <tal:answers_disabled condition="not: view/context_uses_answers">
97+ <div class="highlight-message">
98+ <a tal:replace="structure context/fmt:link">Alsa Utils</a>
99+ <strong>does not use</strong> Launchpad as its answer forum.
100+ <a tal:attributes="href context/menu:overview/configure_answers/fmt:url"
101+ tal:condition="context/required:launchpad.Edit">
102+ Change this <span class="sprite edit action-icon">Edit</span>
103+ </a>
104+ </div>
105+ </tal:answers_disabled>
106 </metal:main>
107
108 </body>