class Email(Model): user = String() email = String() verified = Boolean(default=False) class Meta: index = (('user', ), ) unique = (('email', ), )
class PendingOrganization(Model): """ An organization pending a domain verification. """ name = String() lang = String(required=False) domain = String() created_by = String(required=False) # fkey to User created_at = Float(default=time.time)
class OrganizationMember(Model): org = String() user = String() verified = Boolean(default=False) created_at = Float(default=time.time) class Meta: index = (('org', ), ('user', )) unique = (('org', 'user'), )
class Organization(Model): name = String() lang = String(required=False) domain = String(required=False) owned_by = String(required=False) # fkey to User created_at = Float(default=time.time) class Meta: unique = (('domain', ), ) def get_all_members(self): from codebox.apps.auth.models import User memberships = list(OrganizationMember.objects.filter(org=self.pk)) return User.objects.get_many([m.user for m in memberships]) def get_owner(self): from codebox.apps.auth.models import User return User.objects.get(self.owned_by)
class PendingMember(Model): """ A member which has been invited and not yet joined, or who has applied to join an organization. """ org = String() user = String(required=False) email = String() created_by = String(required=False) created_at = Float(default=time.time) class Meta: unique = (('org', 'email'), ) def get_signature(self): sig = hashlib.md5(self.email) sig.update(app.config['SECRET_KEY']) sig = sig.hexdigest() return sig
class Snippet(Model): org = String() user = String() text = String() keywords = String(required=False) lang = String() created_at = Float(default=time.time) languages = [ ('text', 'Plaintext'), ('diff', 'Diff'), ('javascript', 'JavaScript'), ('html', 'HTML'), ('php', 'PHP'), ('python', 'Python'), ('ruby', 'Ruby'), ('applescript', 'AppleScript'), ('bash', 'Bash'), ('c', 'C'), ('c++', 'C++'), ('css', 'CSS'), ('erlang', 'Erlang'), ('java', 'Java'), ('scala', 'Scala'), ('sql', 'SQL'), ('xml', 'XML'), ] class Meta: index = (('org', ), ('user', )) def post_create(self): from codebox.apps.organizations.models import Organization # Fill our dashboard index for user in Organization.objects.get(self.org).get_all_members(): Snippet.objects.add_to_index(self.pk, dashboard=user.pk) def get_user(self): return User.objects.get(self.user)
class User(Model): name = String() email = String(required=False) avatar = String(required=False) created_at = Float(default=time.time) api_token = String(required=False) class Meta: unique = (('email', ), ('api_token', )) def get_all_organizations(self, admin=False): from codebox.apps.organizations.models import OrganizationMember, Organization memberships = list(OrganizationMember.objects.filter(user=self.pk)) orgs = Organization.objects.get_many([m.org for m in memberships]) if admin: orgs = filter(lambda x: x.owned_by == self.pk, orgs) return orgs def can_admin_org(self, org): return org.owned_by == self.pk def get_relation(self, relation): return list(relation.objects.filter(user=self.pk))
class Profile(Model): user = String() created_at = Float(default=time.time) class Meta: index = (('user', ), )