44
31
QUESTION_STATUS_DEFAULT_SEARCH,
46
from lp.registry.interfaces.person import IPerson
47
33
from lp.services.fields import PublicPersonChoice
48
from lp.services.worlddata.interfaces.language import ILanguage
51
class IQuestionTargetPublic(ISearchableByQuestionOwner):
52
"""Methods that anonymous in user can access."""
54
@operation_parameters(
55
question_id=Int(title=_('Question Number'), required=True))
56
@export_read_operation()
57
@operation_for_version('devel')
36
class IQuestionTarget(ISearchableByQuestionOwner):
37
"""An object that can have a new question asked about it."""
39
def newQuestion(owner, title, description, language=None,
41
"""Create a new question.
43
A new question is created with status OPEN.
45
The owner and all of the target answer contacts will be subscribed
50
:description: A string.
51
:language: An ILanguage. If that parameter is omitted, the question
52
is assumed to be created in English.
53
:datecreated: A datetime object that will be used for the datecreated
54
attribute. Defaults to canonical.database.constants.UTC_NOW.
57
def createQuestionFromBug(bug):
58
"""Create and return a Question from a Bug.
60
The bug's title and description are used as the question title and
61
description. The bug owner is the question owner. The question
62
is automatically linked to the bug.
64
Note that bug messages are copied to the question, but attachments
65
are not. The question is the same age as the bug, though its
66
datelastresponse attribute is current to signify the question is
58
72
def getQuestion(question_id):
59
73
"""Return the question by its id, if it is applicable to this target.
63
77
If there is no such question number for this target, return None
66
@operation_parameters(
67
phrase=TextLine(title=_('A phrase'), required=True))
68
@operation_returns_collection_of(Interface)
69
@export_read_operation()
70
@operation_for_version('devel')
71
def findSimilarQuestions(phrase):
72
"""Return questions similar to phrase.
80
def findSimilarQuestions(title):
81
"""Return questions similar to title.
74
Return a list of question similar to the provided phrase. These
75
questions will be found using a fuzzy search. The list is
83
Return a list of question similar to the title provided. These
84
questions should be found using a fuzzy search. The list should be
76
85
ordered from the most similar question to the least similar question.
78
:param phrase: A phrase such as the summary of a question.
81
@operation_parameters(
82
language=Reference(ILanguage))
83
@operation_returns_collection_of(IPerson)
84
@export_read_operation()
85
@operation_for_version('devel')
90
def addAnswerContact(person):
91
"""Add a new answer contact.
95
Returns True if the person was added, False if the person already was
96
an answer contact. A person must have at least one preferred
97
language to be an answer contact.
100
def removeAnswerContact(person):
101
"""Remove an answer contact.
105
Returns True if the person was removed, False if the person wasn't an
86
109
def getAnswerContactsForLanguage(language):
87
110
"""Return the list of Persons that provide support for a language.
128
149
value_type=PublicPersonChoice(vocabulary="ValidPersonOrTeam"))
131
class IQuestionTargetView(Interface):
132
"""Methods that logged in user can access."""
134
def newQuestion(owner, title, description, language=None,
136
"""Create a new question.
138
A new question is created with status OPEN.
140
The owner and all of the target answer contacts will be subscribed
145
:description: A string.
146
:language: An ILanguage. If that parameter is omitted, the question
147
is assumed to be created in English.
148
:datecreated: A datetime object that will be used for the datecreated
149
attribute. Defaults to canonical.database.constants.UTC_NOW.
152
def createQuestionFromBug(bug):
153
"""Create and return a Question from a Bug.
155
The bug's title and description are used as the question title and
156
description. The bug owner is the question owner. The question
157
is automatically linked to the bug.
159
Note that bug messages are copied to the question, but attachments
160
are not. The question is the same age as the bug, though its
161
datelastresponse attribute is current to signify the question is
167
@operation_parameters(
168
person=PublicPersonChoice(
169
title=_('The user or an administered team'), required=True,
170
vocabulary='ValidPersonOrTeam'))
171
@call_with(subscribed_by=REQUEST_USER)
172
@export_read_operation()
173
@operation_for_version('devel')
174
def canUserAlterAnswerContact(person, subscribed_by):
175
"""Can the user add or remove the answer contact.
177
Users can add or remove themselves or one of the teams they
180
:param person: The `IPerson` that is or will be an answer contact.
181
:param subscribed_by: The `IPerson` making the change.
184
@operation_parameters(
185
person=PublicPersonChoice(
186
title=_('The user of an administered team'), required=True,
187
vocabulary='ValidPersonOrTeam'))
188
@call_with(subscribed_by=REQUEST_USER)
189
@export_write_operation()
190
@operation_for_version('devel')
191
def addAnswerContact(person, subscribed_by):
192
"""Add a new answer contact.
194
:param person: An `IPerson`.
195
:param subscribed_by: The user making the change.
196
:return: True if the person was added, False if the person already is
198
:raises AddAnswerContactError: When the person or team does no have a
202
@operation_parameters(
203
person=PublicPersonChoice(
204
title=_('The user of an administered team'), required=True,
205
vocabulary='ValidPersonOrTeam'))
206
@call_with(subscribed_by=REQUEST_USER)
207
@export_write_operation()
208
@operation_for_version('devel')
209
def removeAnswerContact(person, subscribed_by):
210
"""Remove an answer contact.
212
:param person: An `IPerson`.
213
:param subscribed_by: The user making the change.
214
:return: True if the person was removed, False if the person wasn't an
219
class IQuestionTarget(IQuestionTargetPublic, IQuestionTargetView):
220
"""An object that can have a new question asked about it."""
221
export_as_webservice_entry(as_of='devel')
224
152
# These schemas are only used by browser/questiontarget.py and should really
225
153
# live there. See Bug #66950.
226
154
class ISearchQuestionsForm(Interface):