Skip to content

Commit

Permalink
Add created and updated fields to all models
Browse files Browse the repository at this point in the history
Closes #321
  • Loading branch information
jleclanche committed Jun 6, 2017
1 parent 643c3d0 commit 2f28da1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
44 changes: 44 additions & 0 deletions oauth2_provider/migrations/0005_auto_20170514_1141.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,48 @@ class Migration(migrations.Migration):
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='oauth2_provider_refreshtoken', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='accesstoken',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='accesstoken',
name='updated',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='application',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='application',
name='updated',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='grant',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='grant',
name='updated',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='refreshtoken',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='refreshtoken',
name='updated',
field=models.DateTimeField(auto_now=True),
),
]
12 changes: 12 additions & 0 deletions oauth2_provider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class AbstractApplication(models.Model):
name = models.CharField(max_length=255, blank=True)
skip_authorization = models.BooleanField(default=False)

created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

class Meta:
abstract = True

Expand Down Expand Up @@ -182,6 +185,9 @@ class AbstractGrant(models.Model):
redirect_uri = models.CharField(max_length=255)
scope = models.TextField(blank=True)

created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

def is_expired(self):
"""
Check token expiration with timezone awareness
Expand Down Expand Up @@ -232,6 +238,9 @@ class AbstractAccessToken(models.Model):
expires = models.DateTimeField()
scope = models.TextField(blank=True)

created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

def is_valid(self, scopes=None):
"""
Checks if the access token is valid.
Expand Down Expand Up @@ -318,6 +327,9 @@ class AbstractRefreshToken(models.Model):
related_name="refresh_token"
)

created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

def revoke(self):
"""
Delete this refresh token along with related access token
Expand Down

0 comments on commit 2f28da1

Please sign in to comment.