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 |
||
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
9 |
from sqlobject import ForeignKey |
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
10 |
from zope.interface import implements |
11 |
||
8555.2.5
by Tim Penhey
Move the branch subscription enums. |
12 |
from lp.code.enums import ( |
11403.1.4
by Henning Eggers
Reformatted imports using format-imports script r32. |
13 |
BranchSubscriptionDiffSize, |
14 |
BranchSubscriptionNotificationLevel, |
|
15 |
CodeReviewNotificationLevel, |
|
16 |
)
|
|
17 |
from lp.code.interfaces.branch import IBranchNavigationMenu |
|
8555.2.5
by Tim Penhey
Move the branch subscription enums. |
18 |
from lp.code.interfaces.branchsubscription import IBranchSubscription |
8138.1.2
by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing. |
19 |
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. |
20 |
from lp.code.security import BranchSubscriptionEdit |
7675.759.17
by Brad Crittenden
Reverted removal of validate_person. |
21 |
from lp.registry.interfaces.person import validate_person |
13130.1.8
by Curtis Hovey
Updated import of hasdriver. |
22 |
from lp.registry.interfaces.role import IPersonRoles |
14606.3.1
by William Grant
Merge canonical.database into lp.services.database. |
23 |
from lp.services.database.constants import DEFAULT |
24 |
from lp.services.database.enumcol import EnumCol |
|
25 |
from lp.services.database.sqlbase import SQLBase |
|
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
26 |
|
27 |
||
28 |
class BranchSubscription(SQLBase): |
|
29 |
"""A relationship between a person and a branch."""
|
|
30 |
||
7847.1.37
by Jonathan Lange
Add an IHasBranchTarget interface, and make everything that has a branch |
31 |
implements(IBranchSubscription, IBranchNavigationMenu, IHasBranchTarget) |
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
32 |
|
33 |
_table = 'BranchSubscription' |
|
34 |
||
5485.1.17
by Edwin Grubbs
Fixed indentation |
35 |
person = ForeignKey( |
7675.759.17
by Brad Crittenden
Reverted removal of validate_person. |
36 |
dbName='person', foreignKey='Person', |
37 |
storm_validator=validate_person, notNull=True) |
|
1102.1.85
by David Allouche
can subscribe to and unsubscribe from branch |
38 |
branch = ForeignKey(dbName='branch', foreignKey='Branch', notNull=True) |
4608.1.2
by Tim Penhey
More import fixes, and schema -> enum renames. |
39 |
notification_level = EnumCol(enum=BranchSubscriptionNotificationLevel, |
3691.323.1
by Tim Penhey
DB changes to extend branch subscriptions, and related code changes |
40 |
notNull=True, default=DEFAULT) |
4608.1.2
by Tim Penhey
More import fixes, and schema -> enum renames. |
41 |
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 |
42 |
notNull=False, default=DEFAULT) |
5608.5.1
by Aaron Bentley
Add BranchSubscription.review_level |
43 |
review_level = EnumCol(enum=CodeReviewNotificationLevel, |
44 |
notNull=True, default=DEFAULT) |
|
7675.708.1
by Tim Penhey
Add subscribed_by to the BranchSubscription table. |
45 |
subscribed_by = ForeignKey( |
7675.759.17
by Brad Crittenden
Reverted removal of validate_person. |
46 |
dbName='subscribed_by', foreignKey='Person', |
47 |
storm_validator=validate_person, notNull=True) |
|
7847.1.37
by Jonathan Lange
Add an IHasBranchTarget interface, and make everything that has a branch |
48 |
|
49 |
@property
|
|
50 |
def target(self): |
|
51 |
"""See `IHasBranchTarget`."""
|
|
52 |
return self.branch.target |
|
7675.708.14
by Tim Penhey
Add canBeUnsubscribedByUser to BranchSubscription, and start to move the code security files. |
53 |
|
54 |
def canBeUnsubscribedByUser(self, user): |
|
55 |
"""See `IBranchSubscription`."""
|
|
56 |
if user is None: |
|
57 |
return False |
|
58 |
permission_check = BranchSubscriptionEdit(self) |
|
59 |
return permission_check.checkAuthenticated(IPersonRoles(user)) |