16
16
from zope.interface import Interface
17
17
from zope.schema import (
25
from lazr.restful.declarations import (
27
export_as_webservice_entry,
28
export_read_operation,
29
export_write_operation,
30
operation_for_version,
32
operation_returns_collection_of,
35
from lazr.restful.fields import Reference
24
37
from canonical.launchpad import _
25
38
from lp.answers.interfaces.questioncollection import (
26
39
ISearchableByQuestionOwner,
31
44
QUESTION_STATUS_DEFAULT_SEARCH,
46
from lp.registry.interfaces.person import IPerson
33
47
from lp.services.fields import PublicPersonChoice
48
from lp.services.worlddata.interfaces.language import ILanguage
36
51
class IQuestionTarget(ISearchableByQuestionOwner):
37
52
"""An object that can have a new question asked about it."""
54
export_as_webservice_entry(as_of='devel')
39
56
def newQuestion(owner, title, description, language=None,
41
58
"""Create a new question.
90
def addAnswerContact(person):
111
@operation_parameters(
112
person=PublicPersonChoice(
113
title=_('The user or an administered team'), required=True,
114
vocabulary='ValidPersonOrTeam'))
115
@call_with(subscribed_by=REQUEST_USER)
116
@export_read_operation()
117
@operation_for_version('devel')
118
def canUserAlterAnswerContact(person, subscribed_by):
119
"""Can the user add or remove the answer contact.
121
Users can add or remove themselves or one of the teams they
124
:param person: The `IPerson` that is or will be an answer contact.
125
:param subscribed_by: The `IPerson` making the change.
128
@operation_parameters(
129
person=PublicPersonChoice(
130
title=_('The user of an administered team'), required=True,
131
vocabulary='ValidPersonOrTeam'))
132
@call_with(subscribed_by=REQUEST_USER)
133
@export_write_operation()
134
@operation_for_version('devel')
135
def addAnswerContact(person, subscribed_by):
91
136
"""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.
138
:param person: An `IPerson`.
139
:param subscribed_by: The user making the change.
140
:return: True if the person was added, False if the person already is
142
:raises ValueError: When the person or team does no have a preferred
100
def removeAnswerContact(person):
146
@operation_parameters(
147
person=PublicPersonChoice(
148
title=_('The user of an administered team'), required=True,
149
vocabulary='ValidPersonOrTeam'))
150
@call_with(subscribed_by=REQUEST_USER)
151
@export_write_operation()
152
@operation_for_version('devel')
153
def removeAnswerContact(person, subscribed_by):
101
154
"""Remove an answer contact.
105
Returns True if the person was removed, False if the person wasn't an
156
:param person: An `IPerson`.
157
:param subscribed_by: The user making the change.
158
:return: True if the person was removed, False if the person wasn't an
162
@operation_parameters(
163
language=Reference(ILanguage))
164
@operation_returns_collection_of(IPerson)
165
@export_read_operation()
166
@operation_for_version('devel')
109
167
def getAnswerContactsForLanguage(language):
110
168
"""Return the list of Persons that provide support for a language.
124
182
for the QuestionTarget.
185
@operation_returns_collection_of(ILanguage)
186
@export_read_operation()
187
@operation_for_version('devel')
127
188
def getSupportedLanguages():
128
"""Return the set of languages spoken by at least one of this object's
189
"""Return a list of languages spoken by at the answer contacts.
131
191
An answer contact is considered to speak a given language if that
132
192
language is listed as one of his preferred languages.