Prepare the underlying data model for organizations.
This commit is contained in:
parent
834cb28d30
commit
621f89f826
2 changed files with 33 additions and 1 deletions
|
@ -34,6 +34,24 @@ class User(BaseModel):
|
||||||
email = CharField(unique=True, index=True)
|
email = CharField(unique=True, index=True)
|
||||||
verified = BooleanField(default=False)
|
verified = BooleanField(default=False)
|
||||||
stripe_id = CharField(index=True, null=True)
|
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):
|
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_generator(length=16):
|
||||||
def random_string():
|
def random_string():
|
||||||
random = SystemRandom()
|
random = SystemRandom()
|
||||||
|
@ -172,7 +203,8 @@ def initialize_db():
|
||||||
create_model_tables([User, Repository, Image, AccessToken, Role,
|
create_model_tables([User, Repository, Image, AccessToken, Role,
|
||||||
RepositoryPermission, Visibility, RepositoryTag,
|
RepositoryPermission, Visibility, RepositoryTag,
|
||||||
EmailConfirmation, FederatedLogin, LoginService,
|
EmailConfirmation, FederatedLogin, LoginService,
|
||||||
QueueItem, RepositoryBuild])
|
QueueItem, RepositoryBuild, Team, TeamMember,
|
||||||
|
TeamPermission])
|
||||||
Role.create(name='admin')
|
Role.create(name='admin')
|
||||||
Role.create(name='write')
|
Role.create(name='write')
|
||||||
Role.create(name='read')
|
Role.create(name='read')
|
||||||
|
|
Binary file not shown.
Reference in a new issue