from django.db import models from django.utils.translation import gettext_lazy as _ from django.conf import settings class OrganizationUser(models.Model): ROLE_ADMIN = 'admin' ROLE_MEMBER = 'member' ROLE_CHOICES = ( (ROLE_ADMIN, _('admin')), (ROLE_MEMBER, _('member')) ) organization = models.ForeignKey( 'pingcap_sso.Organization', on_delete=models.CASCADE) user = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='organization_user_set') role = models.CharField( max_length=8, choices=ROLE_CHOICES, default=ROLE_MEMBER) created_at = models.DateTimeField(auto_now_add=True) created_by = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, related_name='granted_organization_user_set', blank=True, null=True) class Meta: db_table = 'pingcap_organization_users' unique_together = ('organization', 'user') class OrganizationInvitation(models.Model): ACTION_PENDING = 'pending' ACTION_ACCEPT = 'accept' ACTION_REFUSE = 'refuse' ACTION_CHOICES = ( (ACTION_PENDING, _('pending')), (ACTION_ACCEPT, _('accept')), (ACTION_REFUSE, _('refuse')) ) organization = models.ForeignKey( 'pingcap_sso.Organization', on_delete=models.CASCADE) invitee = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, related_name='organization_invitation_set') inviter = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, related_name='organization_invitation_create_set') role = models.CharField( max_length=8, choices=OrganizationUser.ROLE_CHOICES, default=OrganizationUser.ROLE_MEMBER) action = models.CharField( max_length=16, default=ACTION_PENDING, choices=ACTION_CHOICES) valid = models.BooleanField(default=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: db_table = 'pingcap_organization_invitations'