~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/answers/interfaces/questiontarget.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-09 22:53:33 UTC
  • mfrom: (12959.4.23 anwers-api-0)
  • Revision ID: launchpad@pqm.canonical.com-20110509225333-lu5q3l2zce8erpbx
[r=benji][bug=780078] Export answer contact management over the API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from zope.interface import Interface
17
17
from zope.schema import (
18
18
    Choice,
 
19
    Int,
19
20
    List,
20
21
    Set,
21
22
    TextLine,
22
23
    )
23
24
 
 
25
from lazr.restful.declarations import (
 
26
    call_with,
 
27
    export_as_webservice_entry,
 
28
    export_read_operation,
 
29
    export_write_operation,
 
30
    operation_for_version,
 
31
    operation_parameters,
 
32
    operation_returns_collection_of,
 
33
    REQUEST_USER,
 
34
    )
 
35
from lazr.restful.fields import Reference
 
36
 
24
37
from canonical.launchpad import _
25
38
from lp.answers.interfaces.questioncollection import (
26
39
    ISearchableByQuestionOwner,
30
43
    QuestionStatus,
31
44
    QUESTION_STATUS_DEFAULT_SEARCH,
32
45
    )
 
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
34
49
 
35
50
 
36
51
class IQuestionTarget(ISearchableByQuestionOwner):
37
52
    """An object that can have a new question asked about it."""
38
53
 
 
54
    export_as_webservice_entry(as_of='devel')
 
55
 
39
56
    def newQuestion(owner, title, description, language=None,
40
57
                    datecreated=None):
41
58
        """Create a new question.
69
86
        :bug: An IBug.
70
87
        """
71
88
 
 
89
    @operation_parameters(
 
90
        question_id=Int(title=_('Question Number'), required=True))
 
91
    @export_read_operation()
 
92
    @operation_for_version('devel')
72
93
    def getQuestion(question_id):
73
94
        """Return the question by its id, if it is applicable to this target.
74
95
 
87
108
        :title: A phrase
88
109
        """
89
110
 
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.
 
120
 
 
121
        Users can add or remove themselves or one of the teams they
 
122
        administered.
 
123
 
 
124
        :param person: The `IPerson` that is or will be an answer contact.
 
125
        :param subscribed_by: The `IPerson` making the change.
 
126
        """
 
127
 
 
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.
92
137
 
93
 
        :person: An IPerson.
94
 
 
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
 
141
            an answer contact.
 
142
        :raises ValueError: When the person or team does no have a preferred
 
143
            language.
98
144
        """
99
145
 
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.
102
155
 
103
 
        :person: An IPerson.
104
 
 
105
 
        Returns True if the person was removed, False if the person wasn't an
106
 
        answer contact.
 
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
 
159
            answer contact.
107
160
        """
108
161
 
 
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.
111
169
 
124
182
        for the QuestionTarget.
125
183
        """
126
184
 
 
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
129
 
        answer contacts.
 
189
        """Return a list of languages spoken by at the answer contacts.
130
190
 
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.