oauth2: link authorizations and temp files to clients (#22717)
This commit is contained in:
parent
1803cb9ddf
commit
1dddba4baf
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.11 on 2018-03-21 23:43
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
def delete_all_client_linked_models(apps, schema_editor):
|
||||
OAuth2Authorize = apps.get_model('oauth2', 'OAuth2Authorize')
|
||||
OAuth2TempFile = apps.get_model('oauth2', 'OAuth2TempFile')
|
||||
OAuth2Authorize.objects.all().delete()
|
||||
OAuth2TempFile.objects.all().delete()
|
||||
|
||||
|
||||
def noop(apps, schema_editor):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('oauth2', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(delete_all_client_linked_models, noop),
|
||||
migrations.AddField(
|
||||
model_name='oauth2authorize',
|
||||
name='client',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='oauth2.OAuth2Client'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='oauth2tempfile',
|
||||
name='client',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='oauth2.OAuth2Client'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -42,16 +42,6 @@ def validate_https_url(data):
|
|||
raise ValidationError(errors)
|
||||
|
||||
|
||||
class OAuth2Authorize(models.Model):
|
||||
user_document = models.ForeignKey(UserDocument)
|
||||
access_token = models.CharField(max_length=255, default=generate_uuid)
|
||||
code = models.CharField(max_length=255, default=generate_uuid)
|
||||
creation_date = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __repr__(self):
|
||||
return 'OAuth2Authorize for document %r' % self.user_document
|
||||
|
||||
|
||||
class OAuth2Client(models.Model):
|
||||
client_secret = models.CharField(max_length=255, default=generate_uuid)
|
||||
client_id = models.CharField(max_length=255, default=generate_uuid)
|
||||
|
@ -73,7 +63,19 @@ class OAuth2Client(models.Model):
|
|||
return self.client_name
|
||||
|
||||
|
||||
class OAuth2Authorize(models.Model):
|
||||
client = models.ForeignKey(OAuth2Client)
|
||||
user_document = models.ForeignKey(UserDocument)
|
||||
access_token = models.CharField(max_length=255, default=generate_uuid)
|
||||
code = models.CharField(max_length=255, default=generate_uuid)
|
||||
creation_date = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __repr__(self):
|
||||
return 'OAuth2Authorize for document %r' % self.user_document
|
||||
|
||||
|
||||
class OAuth2TempFile(models.Model):
|
||||
client = models.ForeignKey(OAuth2Client)
|
||||
hash_key = models.CharField(max_length=128, primary_key=True)
|
||||
document = models.ForeignKey(Document)
|
||||
filename = models.CharField(max_length=512)
|
||||
|
|
|
@ -155,9 +155,12 @@ def test_put_document(app, john_doe, oauth2_client):
|
|||
assert user_document.filename == 'Baudelaire.txt'
|
||||
|
||||
|
||||
def test_confirm_put_document_file_exception(app, john_doe, user_doc):
|
||||
def test_confirm_put_document_file_exception(app, oauth2_client, john_doe, user_doc):
|
||||
login(app, user=john_doe)
|
||||
oauth_tmp_file = OAuth2TempFile.objects.create(document=user_doc.document, filename=user_doc.filename)
|
||||
oauth_tmp_file = OAuth2TempFile.objects.create(
|
||||
client=oauth2_client,
|
||||
document=user_doc.document,
|
||||
filename=user_doc.filename)
|
||||
|
||||
url = reverse('oauth2-put-document-authorize', kwargs={'pk': 'fakemofo'})
|
||||
url += '?%s' % urlencode({'redirect_uri': 'https://example.com'})
|
||||
|
|
Loading…
Reference in New Issue