~launchpad-pqm/launchpad/devel

8687.15.17 by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4983.1.1 by Curtis Hovey
Added lint exceptions to __init__.py and interface/*.py.
4
# pylint: disable-msg=E0211,E0213
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
5
6
"""Milestone interfaces."""
7
8
__metaclass__ = type
9
10
__all__ = [
6837.3.4 by Edwin Grubbs
Export IProduct.milestones as active_milestones. Change IMilestoneGetter to ICanGetMilestonesDirectly.
11
    'ICanGetMilestonesDirectly',
4606.1.4 by Abel Deuring
implemented bjornt's comments
12
    'IHasMilestones',
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
13
    'IMilestone',
14
    'IMilestoneSet',
10326.1.1 by Henning Eggers
Mechanically renamed IProject* to IProjectGroup*.
15
    'IProjectGroupMilestone',
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
16
    ]
17
12177.7.2 by j.c.sackett
ec2 fixes and import fix.
18
from lazr.lifecycle.snapshot import doNotSnapshot
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
19
from lazr.restful.declarations import (
20
    call_with,
21
    export_as_webservice_entry,
22
    export_destructor_operation,
23
    export_factory_operation,
24
    export_operation_as,
25
    export_read_operation,
26
    exported,
12599.4.11 by Leonard Richardson
Completed cleanup.
27
    operation_for_version,
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
28
    operation_parameters,
29
    operation_returns_entry,
30
    rename_parameters_as,
31
    REQUEST_USER,
32
    )
33
from lazr.restful.fields import (
34
    CollectionField,
35
    Reference,
36
    )
37
from zope.interface import (
38
    Attribute,
39
    Interface,
40
    )
41
from zope.schema import (
42
    Bool,
43
    Choice,
44
    Int,
45
    TextLine,
46
    )
1176 by Canonical.com Patch Queue Manager
Initial support for adding milestones to products. TODO: property
47
14600.1.12 by Curtis Hovey
Move i18n to lp.
48
from lp import _
12442.2.2 by j.c.sackett
Moved validators to app, which makes more sense.
49
from lp.app.validators.name import name_validator
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
50
from lp.bugs.interfaces.bugtarget import (
51
    IHasBugs,
52
    IHasOfficialBugTags,
53
    )
54
from lp.bugs.interfaces.bugtask import IBugTask
7675.1025.1 by Gary Poster
structural subscriptions are moved from registry to bugs. moved tests pass.
55
from lp.bugs.interfaces.structuralsubscription import (
56
    IStructuralSubscriptionTarget,
57
    )
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
58
from lp.registry.interfaces.productrelease import IProductRelease
11318.5.1 by j.c.sackett
Migrated canonical.launchpad.fields to lp.services.fields
59
from lp.services.fields import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
60
    ContentNameField,
61
    FormattableDate,
62
    NoneableDescription,
63
    NoneableTextLine,
64
    )
14612.2.1 by William Grant
format-imports on lib/. So many imports.
65
from lp.services.webservice.apihelpers import patch_plain_parameter_type
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
66
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
67
68
class MilestoneNameField(ContentNameField):
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
69
    """A field that can get the milestone from different contexts."""
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
70
71
    @property
72
    def _content_iface(self):
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
73
        """The interface this field manages."""
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
74
        return IMilestone
4785.3.5 by Jeroen Vermeulen
Removed whitespace at ends of lines.
75
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
76
    def _getByName(self, name):
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
77
        """Return the named milestone from the context."""
6837.2.1 by Edwin Grubbs
Exported IMilestone.series_target to API
78
        # IProductSeries and IDistroSeries are imported here to
79
        # avoid an import loop.
7675.110.3 by Curtis Hovey
Ran the migration script to move registry code to lp.registry.
80
        from lp.registry.interfaces.productseries import (
6837.2.1 by Edwin Grubbs
Exported IMilestone.series_target to API
81
            IProductSeries)
7675.110.3 by Curtis Hovey
Ran the migration script to move registry code to lp.registry.
82
        from lp.registry.interfaces.distroseries import IDistroSeries
3472.2.1 by Mark Shuttleworth
Hang milestones mostly off series.
83
        if IMilestone.providedBy(self.context):
84
            milestone = self.context.target.getMilestone(name)
85
        elif IProductSeries.providedBy(self.context):
86
            milestone = self.context.product.getMilestone(name)
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
87
        elif IDistroSeries.providedBy(self.context):
3472.2.1 by Mark Shuttleworth
Hang milestones mostly off series.
88
            milestone = self.context.distribution.getMilestone(name)
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
89
        else:
9974.1.2 by Curtis Hovey
move structuralsubscriptions to lp.registry.
90
            raise AssertionError(
6837.1.2 by Edwin Grubbs
Exported attributes in IMilestone, IProduct, and IBranch.
91
                'Editing a milestone in an unexpected context: %r'
92
                % self.context)
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
93
        if milestone is not None:
5606.1.3 by Joey Stanford
fixed needs-reply items from barry.
94
            self.errormessage = _(
95
                "The name %%s is already used by a milestone in %s."
96
                % milestone.target.displayname)
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
97
        return milestone
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
98
99
10094.4.3 by Gavin Panella
Create new IHasOfficialBugTags interface.
100
class IMilestone(IHasBugs, IStructuralSubscriptionTarget,
101
                 IHasOfficialBugTags):
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
102
    """A milestone, or a targeting point for bugs and other
103
    release-management items that need coordination.
2269 by Canonical.com Patch Queue Manager
[r=lifeless] add distribution milestones and make them rock
104
    """
6327.12.5 by Francis J. Lacoste
Made IProject, IProduct, IProductSeries, IProductRelease, IMilestone available on the web service.
105
    export_as_webservice_entry()
106
1688 by Canonical.com Patch Queue Manager
Fix bug 220, make assigning milestones to bug tasks work again.
107
    id = Int(title=_("Id"))
6327.12.5 by Francis J. Lacoste
Made IProject, IProduct, IProductSeries, IProductRelease, IMilestone available on the web service.
108
    name = exported(
109
        MilestoneNameField(
110
            title=_("Name"),
111
            description=_(
112
                "Only letters, numbers, and simple punctuation are allowed."),
113
            constraint=name_validator))
8214.1.1 by Curtis Hovey
Added code_name to the list of visible and setable fields.
114
    code_name = exported(
8464.1.3 by Curtis Hovey
Added Noneable widgets.
115
        NoneableTextLine(
116
            title=u'Code name', required=False,
117
            description=_('An alternative name for the milestone.')))
1176 by Canonical.com Patch Queue Manager
Initial support for adding milestones to products. TODO: property
118
    product = Choice(
4152.2.3 by Francis J. Lacoste
Rename "product" to "project" in browser code, and some "project" to "project group".
119
        title=_("Project"),
120
        description=_("The project to which this milestone is associated"),
2269 by Canonical.com Patch Queue Manager
[r=lifeless] add distribution milestones and make them rock
121
        vocabulary="Product")
122
    distribution = Choice(title=_("Distribution"),
123
        description=_("The distribution to which this milestone belongs."),
124
        vocabulary="Distribution")
3472.2.1 by Mark Shuttleworth
Hang milestones mostly off series.
125
    productseries = Choice(
5606.1.2 by Joey Stanford
finished up my overengineered pagetests
126
        title=_("Product Series"),
127
        description=_("The product series for which this is a milestone."),
3472.2.1 by Mark Shuttleworth
Hang milestones mostly off series.
128
        vocabulary="FilteredProductSeries",
129
        required=False) # for now
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
130
    distroseries = Choice(
5606.1.2 by Joey Stanford
finished up my overengineered pagetests
131
        title=_("Distro Series"),
3472.2.1 by Mark Shuttleworth
Hang milestones mostly off series.
132
        description=_(
5606.1.2 by Joey Stanford
finished up my overengineered pagetests
133
            "The distribution series for which this is a milestone."),
4285.2.1 by Mark Shuttleworth
Massive renaming of distrorelease to distroseries
134
        vocabulary="FilteredDistroSeries",
3472.2.1 by Mark Shuttleworth
Hang milestones mostly off series.
135
        required=False) # for now
6837.1.2 by Edwin Grubbs
Exported attributes in IMilestone, IProduct, and IBranch.
136
    dateexpected = exported(
11318.5.7 by j.c.sackett
Changed type of FormattableDate to Date from Datetime. Updated tests.
137
        FormattableDate(title=_("Date Targeted"), required=False,
6837.1.2 by Edwin Grubbs
Exported attributes in IMilestone, IProduct, and IBranch.
138
             description=_("Example: 2005-11-24")),
139
        exported_as='date_targeted')
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
140
    active = exported(
6837.1.2 by Edwin Grubbs
Exported attributes in IMilestone, IProduct, and IBranch.
141
        Bool(
142
            title=_("Active"),
143
            description=_("Whether or not this milestone should be shown "
144
                          "in web forms for bug targeting.")),
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
145
        exported_as='is_active')
146
    summary = exported(
8464.1.3 by Curtis Hovey
Added Noneable widgets.
147
        NoneableDescription(
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
148
            title=_("Summary"),
6837.1.2 by Edwin Grubbs
Exported attributes in IMilestone, IProduct, and IBranch.
149
            required=False,
150
            description=_(
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
151
                "A summary of the features and status of this milestone.")))
6327.12.5 by Francis J. Lacoste
Made IProject, IProduct, IProductSeries, IProductRelease, IMilestone available on the web service.
152
    target = exported(
153
        Reference(
154
            schema=Interface, # IHasMilestones
155
            title=_("The product or distribution of this milestone."),
156
            required=False))
6837.2.1 by Edwin Grubbs
Exported IMilestone.series_target to API
157
    series_target = exported(
158
        Reference(
159
            schema=Interface, # IHasMilestones
160
            title=_("The productseries or distroseries of this milestone."),
161
            required=False))
2269 by Canonical.com Patch Queue Manager
[r=lifeless] add distribution milestones and make them rock
162
    displayname = Attribute("A displayname for this milestone, constructed "
163
        "from the milestone name.")
6837.1.2 by Edwin Grubbs
Exported attributes in IMilestone, IProduct, and IBranch.
164
    title = exported(
165
        TextLine(title=_("A milestone context title for pages."),
166
                 readonly=True))
2344 by Canonical.com Patch Queue Manager
[not r=kiko] specification tracker
167
    specifications = Attribute("A list of the specifications targeted to "
168
        "this milestone.")
2269 by Canonical.com Patch Queue Manager
[r=lifeless] add distribution milestones and make them rock
169
8357.2.1 by Curtis Hovey
Fixed distribution.getSeries error to return 400 for API. Exposed milestone.product_release to the API.
170
    product_release = exported(
171
        Reference(
172
            schema=IProductRelease,
173
            title=_("The release for this milestone."),
174
            required=False,
8357.2.2 by Curtis Hovey
Exposed Product getRelease and getSeries to the API. Discovered that getRelease has been broken--added missing test coverage.
175
            readonly=True),
176
        exported_as='release')
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
177
178
    @call_with(owner=REQUEST_USER)
179
    @rename_parameters_as(datereleased='date_released')
180
    @export_factory_operation(
181
        IProductRelease,
182
        ['datereleased', 'changelog', 'release_notes'])
12599.4.11 by Leonard Richardson
Completed cleanup.
183
    @operation_for_version('beta')
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
184
    def createProductRelease(owner, datereleased,
185
                             changelog=None, release_notes=None):
186
        """Create a new ProductRelease.
187
188
        :param owner: `IPerson` object who manages the release.
189
        :param datereleased: Date of the product release.
190
        :param changelog: Detailed changes in each version.
191
        :param release_notes: Overview of changes in each version.
192
        :returns: `IProductRelease` object.
193
        """
194
7675.501.1 by Curtis Hovey
Moved the milestone createProductRelease "fix committed" to "fix release" rules to
195
    def closeBugsAndBlueprints(user):
196
        """Close completed bugs and blueprints.
197
198
        Bugs that are fix committed status are updated to fix released.
199
        Blueprints that are in deployment status are updated to implemented
200
        status.
201
        XXX sinzui 2010-01-27 bug=341687: blueprints not yet implemented.
202
        """
203
10779.1.1 by Brad Crittenden
Change milestone delete to be a destructor.
204
    @export_destructor_operation()
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
205
    @export_operation_as('delete')
12599.4.11 by Leonard Richardson
Completed cleanup.
206
    @operation_for_version('beta')
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
207
    def destroySelf():
208
        """Delete this milestone.
209
210
        This method must not be used if this milestone has a product
211
        release.
212
        """
213
7662.2.1 by Tom Berger
export IBugTask.milestone as ReferenceChoice
214
# Avoid circular imports
215
IBugTask['milestone'].schema = IMilestone
9119.3.2 by William Grant
Add IBugTask.transitionToMilestone, export it, and make IBugTask.milestone read-only.
216
patch_plain_parameter_type(
217
    IBugTask, 'transitionToMilestone', 'new_milestone', IMilestone)
7662.2.1 by Tom Berger
export IBugTask.milestone as ReferenceChoice
218
1176 by Canonical.com Patch Queue Manager
Initial support for adding milestones to products. TODO: property
219
220
class IMilestoneSet(Interface):
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
221
    """An set provides access `IMilestone`s."""
222
1176 by Canonical.com Patch Queue Manager
Initial support for adding milestones to products. TODO: property
223
    def __iter__():
224
        """Return an iterator over all the milestones for a thing."""
225
1309 by Canonical.com Patch Queue Manager
add the rest of the hard bits of implementing bug privacy. grow the
226
    def get(milestoneid):
227
        """Get a milestone by its id.
228
229
        If the milestone with that ID is not found, a
2976.10.15 by Stuart Bishop
zope.exceptions.NotFoundError is deprecated
230
        NotFoundError will be raised.
1309 by Canonical.com Patch Queue Manager
add the rest of the hard bits of implementing bug privacy. grow the
231
        """
232
12415.7.3 by Robert Collins
Fix late evaluation of bugtask milestones in bug searches.
233
    def getByIds(milestoneids):
234
        """Get the milestones for milestoneids."""
235
3504.1.48 by kiko
Remove self arguments from some interfaces
236
    def getByNameAndProduct(name, product, default=None):
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
237
        """Get a milestone by its name and product.
238
4785.3.5 by Jeroen Vermeulen
Removed whitespace at ends of lines.
239
        If no milestone is found, default will be returned.
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
240
        """
241
3504.1.48 by kiko
Remove self arguments from some interfaces
242
    def getByNameAndDistribution(name, distribution, default=None):
2874.2.12 by gneuman at async
Fix https://launchpad.net/products/launchpad/+bug/3367, creates class MilestoneNameField, related methods and test
243
        """Get a milestone by its name and distribution.
244
245
        If no milestone is found, default will be returned.
246
        """
247
8167.3.1 by Abel Deuring
fix for bug 350520: inefficient generation of milestone vocabularies
248
    def getVisibleMilestones():
249
        """Return all visible milestones."""
250
4606.1.1 by Abel Deuring
bug 116454: implemented reviewer's comments; trunk merged
251
10326.1.1 by Henning Eggers
Mechanically renamed IProject* to IProjectGroup*.
252
class IProjectGroupMilestone(IMilestone):
4606.1.1 by Abel Deuring
bug 116454: implemented reviewer's comments; trunk merged
253
    """A marker interface for milestones related to a project"""
4606.1.4 by Abel Deuring
implemented bjornt's comments
254
255
256
class IHasMilestones(Interface):
4606.1.5 by Abel Deuring
implemented reviewer's comments
257
    """An interface for classes providing milestones."""
6837.2.2 by Edwin Grubbs
Fixed wadl errors
258
    export_as_webservice_entry()
4606.1.4 by Abel Deuring
implemented bjornt's comments
259
11320.1.7 by Edwin Grubbs
Fixed db function permissions. Added HasMilestonesMixin.has_milestones.
260
    has_milestones = Bool(title=_("Whether the object has any milestones."))
261
12177.7.1 by j.c.sackett
Do Not Snapshot CollectionFields for IHasSpecifications and IHasMilestones
262
    milestones = exported(doNotSnapshot(
6789.15.8 by Edwin Grubbs
Exported Product.milestones and Product.all_milestones to API
263
        CollectionField(
264
            title=_("The visible and active milestones associated with this "
265
                    "object, ordered by date expected."),
12177.7.1 by j.c.sackett
Do Not Snapshot CollectionFields for IHasSpecifications and IHasMilestones
266
            value_type=Reference(schema=IMilestone))),
6837.3.4 by Edwin Grubbs
Export IProduct.milestones as active_milestones. Change IMilestoneGetter to ICanGetMilestonesDirectly.
267
        exported_as='active_milestones')
4606.1.4 by Abel Deuring
implemented bjornt's comments
268
12177.7.1 by j.c.sackett
Do Not Snapshot CollectionFields for IHasSpecifications and IHasMilestones
269
    all_milestones = exported(doNotSnapshot(
6789.15.8 by Edwin Grubbs
Exported Product.milestones and Product.all_milestones to API
270
        CollectionField(
271
            title=_("All milestones associated with this object, ordered by "
272
                    "date expected."),
12177.7.1 by j.c.sackett
Do Not Snapshot CollectionFields for IHasSpecifications and IHasMilestones
273
            value_type=Reference(schema=IMilestone))))
4606.1.4 by Abel Deuring
implemented bjornt's comments
274
6837.2.1 by Edwin Grubbs
Exported IMilestone.series_target to API
275
6837.3.4 by Edwin Grubbs
Export IProduct.milestones as active_milestones. Change IMilestoneGetter to ICanGetMilestonesDirectly.
276
class ICanGetMilestonesDirectly(Interface):
6837.2.1 by Edwin Grubbs
Exported IMilestone.series_target to API
277
    """ An interface for classes providing getMilestone(name)."""
278
8357.2.3 by Curtis Hovey
Exposed Product/Project/Distribution getMilestone to the API.
279
    @operation_parameters(
280
        name=TextLine(title=_("Name"), required=True))
281
    @operation_returns_entry(IMilestone)
282
    @export_read_operation()
12599.4.11 by Leonard Richardson
Completed cleanup.
283
    @operation_for_version('beta')
4606.1.4 by Abel Deuring
implemented bjornt's comments
284
    def getMilestone(name):
4606.1.5 by Abel Deuring
implemented reviewer's comments
285
        """Return a milestone with the given name for this object, or None."""
6327.12.5 by Francis J. Lacoste
Made IProject, IProduct, IProductSeries, IProductRelease, IMilestone available on the web service.
286
287
288
# Fix cyclic references.
289
IMilestone['target'].schema = IHasMilestones
6837.2.1 by Edwin Grubbs
Exported IMilestone.series_target to API
290
IMilestone['series_target'].schema = IHasMilestones
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
291
IProductRelease['milestone'].schema = IMilestone