Prepare the underlying data model for organizations.

This commit is contained in:
yackob03 2013-10-31 16:46:04 -04:00
parent 834cb28d30
commit 621f89f826
2 changed files with 33 additions and 1 deletions

View file

@ -34,6 +34,24 @@ class User(BaseModel):
email = CharField(unique=True, index=True)
verified = BooleanField(default=False)
stripe_id = CharField(index=True, null=True)
organization = BooleanField(default=False, index=True)
class Team(BaseModel):
name = CharField()
organization = ForeignKeyField(User, index=True)
class TeamMember(BaseModel):
user = ForeignKeyField(User, index=True)
team = ForeignKeyField(Team, index=True)
class Meta:
database = db
indexes = (
# A user may belong to a team only once
(('user', 'team'), True),
)
class LoginService(BaseModel):
@ -90,6 +108,19 @@ class RepositoryPermission(BaseModel):
)
class TeamPermission(BaseModel):
team = ForeignKeyField(Team, index=True)
organization = ForeignKeyField(User, index=True)
role = ForeignKeyField(Role)
class Meta:
database = db
indexes = (
# A team may only have one permission level in an org
(('team', 'organization'), True),
)
def random_string_generator(length=16):
def random_string():
random = SystemRandom()
@ -172,7 +203,8 @@ def initialize_db():
create_model_tables([User, Repository, Image, AccessToken, Role,
RepositoryPermission, Visibility, RepositoryTag,
EmailConfirmation, FederatedLogin, LoginService,
QueueItem, RepositoryBuild])
QueueItem, RepositoryBuild, Team, TeamMember,
TeamPermission])
Role.create(name='admin')
Role.create(name='write')
Role.create(name='read')

Binary file not shown.