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.2
by Curtis Hovey
Added pylint exceptions to database classes. |
4 |
# pylint: disable-msg=E0611,W0212
|
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
5 |
|
6 |
__metaclass__ = type |
|
7 |
__all__ = ['BranchSubscription'] |
|
8 |
||
9 |
from zope.interface import implements |
|
10 |
||
5485.1.18
by Edwin Grubbs
Fixed lots of lint issues |
11 |
from sqlobject import ForeignKey |
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
12 |
|
3691.323.1
by Tim Penhey
DB changes to extend branch subscriptions, and related code changes |
13 |
from canonical.database.constants import DEFAULT |
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
14 |
from canonical.database.sqlbase import SQLBase |
3691.373.5
by Christian Reis
Move DBSchema and Item into webapp.enum, and put EnumCol into canonical.database.enumcol |
15 |
from canonical.database.enumcol import EnumCol |
7675.708.14
by Tim Penhey
Add canBeUnsubscribedByUser to BranchSubscription, and start to move the code security files. |
16 |
from canonical.launchpad.interfaces.launchpad import IPersonRoles |
8555.2.5
by Tim Penhey
Move the branch subscription enums. |
17 |
from lp.code.enums import ( |
8138.1.2
by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing. |
18 |
BranchSubscriptionDiffSize, BranchSubscriptionNotificationLevel, |
8555.2.5
by Tim Penhey
Move the branch subscription enums. |
19 |
CodeReviewNotificationLevel) |
20 |
from lp.code.interfaces.branchsubscription import IBranchSubscription |
|
8138.1.2
by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing. |
21 |
from lp.code.interfaces.branch import IBranchNavigationMenu |
22 |
from lp.code.interfaces.branchtarget import IHasBranchTarget |
|
7675.708.14
by Tim Penhey
Add canBeUnsubscribedByUser to BranchSubscription, and start to move the code security files. |
23 |
from lp.code.security import BranchSubscriptionEdit |
7675.759.1
by Brad Crittenden
Destroy PRIVATE_MEMBERSHIP teams and remove them from the face of the Earth. |
24 |
from lp.registry.interfaces.person import validate_person |
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
25 |
|
26 |
||
27 |
class BranchSubscription(SQLBase): |
|
28 |
"""A relationship between a person and a branch."""
|
|
29 |
||
7847.1.37
by Jonathan Lange
Add an IHasBranchTarget interface, and make everything that has a branch |
30 |
implements(IBranchSubscription, IBranchNavigationMenu, IHasBranchTarget) |
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
31 |
|
32 |
_table = 'BranchSubscription' |
|
33 |
||
5485.1.17
by Edwin Grubbs
Fixed indentation |
34 |
person = ForeignKey( |
35 |
dbName='person', foreignKey='Person', |
|
7675.759.1
by Brad Crittenden
Destroy PRIVATE_MEMBERSHIP teams and remove them from the face of the Earth. |
36 |
storm_validator=validate_person, notNull=True) |
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
37 |
branch = ForeignKey(dbName='branch', foreignKey='Branch', notNull=True) |
4608.1.2
by Tim Penhey
More import fixes, and schema -> enum renames. |
38 |
notification_level = EnumCol(enum=BranchSubscriptionNotificationLevel, |
3691.323.1
by Tim Penhey
DB changes to extend branch subscriptions, and related code changes |
39 |
notNull=True, default=DEFAULT) |
4608.1.2
by Tim Penhey
More import fixes, and schema -> enum renames. |
40 |
max_diff_lines = EnumCol(enum=BranchSubscriptionDiffSize, |
5852.2.2
by James Henstridge
fix some columns that claimed to be notNull=True but are in fact not not null |
41 |
notNull=False, default=DEFAULT) |
5608.5.1
by Aaron Bentley
Add BranchSubscription.review_level |
42 |
review_level = EnumCol(enum=CodeReviewNotificationLevel, |
43 |
notNull=True, default=DEFAULT) |
|
7675.708.1
by Tim Penhey
Add subscribed_by to the BranchSubscription table. |
44 |
subscribed_by = ForeignKey( |
7675.708.5
by Tim Penhey
Some other necessary bits. |
45 |
dbName='subscribed_by', foreignKey='Person', |
7675.759.1
by Brad Crittenden
Destroy PRIVATE_MEMBERSHIP teams and remove them from the face of the Earth. |
46 |
storm_validator=validate_person, notNull=True) |
7847.1.37
by Jonathan Lange
Add an IHasBranchTarget interface, and make everything that has a branch |
47 |
|
48 |
@property
|
|
49 |
def target(self): |
|
50 |
"""See `IHasBranchTarget`."""
|
|
51 |
return self.branch.target |
|
7675.708.14
by Tim Penhey
Add canBeUnsubscribedByUser to BranchSubscription, and start to move the code security files. |
52 |
|
53 |
def canBeUnsubscribedByUser(self, user): |
|
54 |
"""See `IBranchSubscription`."""
|
|
55 |
if user is None: |
|
56 |
return False |
|
57 |
permission_check = BranchSubscriptionEdit(self) |
|
58 |
return permission_check.checkAuthenticated(IPersonRoles(user)) |