from django.db import models from django.utils.translation import gettext_lazy as _ from django.conf import settings class OrganizationUserAction(models.Model): ACTION_APPLY_ORG = 0 ACTION_ORG_APPLICATION_APPROVED = 1 ACTION_ORG_APPLICATION_DENIED = 2 ACTION_JOIN_ORG = 3 ACTION_LEAVE_ORG = 4 ACTION_CHANGE_ROLE = 5 ACTION_UNKNOWN = 5 ACTION_CHOICES = ( (ACTION_APPLY_ORG, _('apply organization')), (ACTION_ORG_APPLICATION_APPROVED, _('organization application approved')), (ACTION_ORG_APPLICATION_DENIED, _('organization application denied')), (ACTION_JOIN_ORG, _('join organization')), (ACTION_LEAVE_ORG, _('leave organization')), (ACTION_CHANGE_ROLE, _('change role')), (ACTION_UNKNOWN, _('unknown')) ) organization = models.ForeignKey( 'pingcap_sso.Organization', on_delete=models.CASCADE, blank=True, null=True ) user = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE) action_type = models.SmallIntegerField( default=ACTION_UNKNOWN, choices=ACTION_CHOICES ) role = models.CharField(max_length=8) acting_user = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, blank=True, null=True, related_name='organization_user_action_acting_set' ) created_at = models.DateTimeField(auto_now_add=True) class Meta: db_table = 'pingcap_organization_user_actions'