38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
from django.contrib.auth.models import User
|
|
from django.db import models
|
|
from django.utils.crypto import get_random_string
|
|
|
|
from .integrations.models import OauthIntegration
|
|
|
|
|
|
class AuthorizationGrant(models.Model):
|
|
authorized_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
code_text = models.CharField(
|
|
"Authorization Code",
|
|
primary_key=True,
|
|
unique=True,
|
|
max_length=32,
|
|
default=get_random_string(32),
|
|
blank=True,
|
|
editable=False,
|
|
)
|
|
issued_date = models.DateTimeField("date issued", auto_now_add=True, blank=True)
|
|
issued_to = models.ForeignKey(OauthIntegration, on_delete=models.CASCADE)
|
|
|
|
def __str__(self):
|
|
return f"{self.authorized_by.username}: {self.issued_to.name_text} {self.issued_to.client_id_uuid}"
|