general: apply isort & pyupgrade
This commit is contained in:
parent
e8a9d06b75
commit
80f7f42fc8
|
@ -80,7 +80,7 @@ class DocumentAdmin(admin.ModelAdmin):
|
||||||
def users(self, instance):
|
def users(self, instance):
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
qs = User.objects.filter(user_documents__document=instance)
|
qs = User.objects.filter(user_documents__document=instance)
|
||||||
return u', '.join(u'%s' % u for u in qs)
|
return ', '.join('%s' % u for u in qs)
|
||||||
|
|
||||||
def thumbnail(self, instance):
|
def thumbnail(self, instance):
|
||||||
return instance.thumbnail_img_tag
|
return instance.thumbnail_img_tag
|
||||||
|
|
|
@ -34,4 +34,4 @@ class APIError(ValidationError):
|
||||||
detail = getattr(self, kind).copy()
|
detail = getattr(self, kind).copy()
|
||||||
detail.update(kwargs)
|
detail.update(kwargs)
|
||||||
detail['msg'] = detail['msg'].format(**kwargs)
|
detail['msg'] = detail['msg'].format(**kwargs)
|
||||||
super(APIError, self).__init__([detail])
|
super().__init__([detail])
|
||||||
|
|
|
@ -19,8 +19,8 @@ import uuid
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
|
|
||||||
from rest_framework import fields, serializers
|
from rest_framework import fields, serializers
|
||||||
|
|
||||||
from . import api_errors
|
from . import api_errors
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class SlugCreatedRelatedField(serializers.SlugRelatedField):
|
||||||
class Base64FileField(fields.Field):
|
class Base64FileField(fields.Field):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.max_size = kwargs.pop('max_size', 0)
|
self.max_size = kwargs.pop('max_size', 0)
|
||||||
super(Base64FileField, self).__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def get_max_size(self):
|
def get_max_size(self):
|
||||||
if hasattr(self.max_size, '__call__'):
|
if hasattr(self.max_size, '__call__'):
|
||||||
|
@ -40,7 +40,7 @@ class Base64FileField(fields.Field):
|
||||||
return self.max_size
|
return self.max_size
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
if isinstance(data, six.string_types):
|
if isinstance(data, str):
|
||||||
# base64 encoded image - decode
|
# base64 encoded image - decode
|
||||||
name = uuid.uuid4()
|
name = uuid.uuid4()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -17,19 +17,17 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.urls import reverse
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
from rest_framework import exceptions, filters, mixins, routers, serializers, status, viewsets
|
||||||
from rest_framework import serializers
|
|
||||||
from rest_framework.generics import GenericAPIView, ListAPIView
|
from rest_framework.generics import GenericAPIView, ListAPIView
|
||||||
from rest_framework.permissions import IsAdminUser
|
from rest_framework.permissions import IsAdminUser
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status, filters, mixins, viewsets, routers, exceptions
|
|
||||||
|
|
||||||
from .models import Origin, Document, UserDocument, Validation
|
from . import api_errors, api_fields, utils
|
||||||
from . import utils, api_errors, api_fields
|
from .models import Document, Origin, UserDocument, Validation
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from mellon.models import UserSAMLIdentifier
|
from mellon.models import UserSAMLIdentifier
|
||||||
|
@ -72,16 +70,16 @@ class UserSerializerMixin(serializers.Serializer):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class CommonAPIMixin(object):
|
class CommonAPIMixin:
|
||||||
def handle_exception(self, exc):
|
def handle_exception(self, exc):
|
||||||
if isinstance(exc, exceptions.APIException):
|
if isinstance(exc, exceptions.APIException):
|
||||||
exc.detail = {'result': 0, 'errors': exc.detail}
|
exc.detail = {'result': 0, 'errors': exc.detail}
|
||||||
return super(CommonAPIMixin, self).handle_exception(exc)
|
return super().handle_exception(exc)
|
||||||
|
|
||||||
def finalize_response(self, request, response, *args, **kwargs):
|
def finalize_response(self, request, response, *args, **kwargs):
|
||||||
if not isinstance(response.data, dict) or 'result' not in response.data:
|
if not isinstance(response.data, dict) or 'result' not in response.data:
|
||||||
response.data = {'result': 1, 'data': response.data}
|
response.data = {'result': 1, 'data': response.data}
|
||||||
return super(CommonAPIMixin, self).finalize_response(request, response, *args, **kwargs)
|
return super().finalize_response(request, response, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def get_max_size():
|
def get_max_size():
|
||||||
|
@ -95,7 +93,7 @@ class PushDocumentSerializer(UserSerializerMixin):
|
||||||
deletable_by_user = serializers.BooleanField(required=False, default=True)
|
deletable_by_user = serializers.BooleanField(required=False, default=True)
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
data = super(PushDocumentSerializer, self).validate(data)
|
data = super().validate(data)
|
||||||
user = data['user']
|
user = data['user']
|
||||||
if (
|
if (
|
||||||
Document.objects.used_space(user) + data['file_b64_content'].size
|
Document.objects.used_space(user) + data['file_b64_content'].size
|
||||||
|
@ -175,7 +173,7 @@ class ValidationSerializer(UserSerializerMixin, serializers.ModelSerializer):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
schema = kwargs.pop('schema')
|
schema = kwargs.pop('schema')
|
||||||
super(ValidationSerializer, self).__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.document_type = schema['name']
|
self.document_type = schema['name']
|
||||||
self.document_type_schema = schema
|
self.document_type_schema = schema
|
||||||
for field in schema['metadata']:
|
for field in schema['metadata']:
|
||||||
|
@ -194,7 +192,7 @@ class ValidationSerializer(UserSerializerMixin, serializers.ModelSerializer):
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
data = super(ValidationSerializer, self).validate(data)
|
data = super().validate(data)
|
||||||
data['document_type'] = self.document_type
|
data['document_type'] = self.document_type
|
||||||
data['created'] = now().replace(microsecond=0)
|
data['created'] = now().replace(microsecond=0)
|
||||||
data['start'] = data['created'].date()
|
data['start'] = data['created'].date()
|
||||||
|
@ -230,7 +228,7 @@ class ValidationAPI(
|
||||||
queryset = Validation.objects.all()
|
queryset = Validation.objects.all()
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return super(ValidationAPI, self).get_queryset().filter(document_type=self.document_type)
|
return super().get_queryset().filter(document_type=self.document_type)
|
||||||
|
|
||||||
def initial(self, request, document_type, *args, **kwargs):
|
def initial(self, request, document_type, *args, **kwargs):
|
||||||
self.document_type_schema = utils.get_document_type_schema(settings, document_type)
|
self.document_type_schema = utils.get_document_type_schema(settings, document_type)
|
||||||
|
@ -239,11 +237,11 @@ class ValidationAPI(
|
||||||
error.status_code = status.HTTP_404_NOT_FOUND
|
error.status_code = status.HTTP_404_NOT_FOUND
|
||||||
raise error
|
raise error
|
||||||
self.document_type = document_type
|
self.document_type = document_type
|
||||||
super(ValidationAPI, self).initial(request, document_type, *args, **kwargs)
|
super().initial(request, document_type, *args, **kwargs)
|
||||||
|
|
||||||
def get_serializer(self, *args, **kwargs):
|
def get_serializer(self, *args, **kwargs):
|
||||||
# pass schema to serializer class
|
# pass schema to serializer class
|
||||||
return super(ValidationAPI, self).get_serializer(schema=self.document_type_schema, *args, **kwargs)
|
return super().get_serializer(schema=self.document_type_schema, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
router = routers.SimpleRouter()
|
router = routers.SimpleRouter()
|
||||||
|
|
|
@ -17,10 +17,9 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.template.defaultfilters import filesizeformat
|
from django.template.defaultfilters import filesizeformat
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
@ -57,7 +56,7 @@ class UploadForm(forms.ModelForm):
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.instance.filename = self.files['content'].name[:512]
|
self.instance.filename = self.files['content'].name[:512]
|
||||||
self.instance.document = models.Document.objects.get_by_file(self.files['content'])
|
self.instance.document = models.Document.objects.get_by_file(self.files['content'])
|
||||||
return super(UploadForm, self).save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.UserDocument
|
model = models.UserDocument
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from fargo.fargo.utils import cleanup
|
from fargo.fargo.utils import cleanup
|
||||||
|
|
||||||
|
|
|
@ -46,4 +46,4 @@ class DocumentManager(models.Manager):
|
||||||
return o
|
return o
|
||||||
|
|
||||||
def used_space(self, user):
|
def used_space(self, user):
|
||||||
return sum([doc.content.size for doc in self.filter(user_documents__user=user)])
|
return sum(doc.content.size for doc in self.filter(user_documents__user=user))
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import models, migrations
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.11 on 2018-03-31 13:34
|
# Generated by Django 1.11.11 on 2018-03-31 13:34
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
import jsonfield.fields
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
|
||||||
from django.utils.timezone import utc
|
from django.utils.timezone import utc
|
||||||
import jsonfield.fields
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
from django.db import migrations, models
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import models, migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import models, migrations
|
|
||||||
import jsonfield.fields
|
|
||||||
from django.utils.timezone import utc
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
import jsonfield.fields
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
|
|
||||||
def clear_document(apps, schema_editor):
|
def clear_document(apps, schema_editor):
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
from django.db import migrations, models
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import models, migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.9.7 on 2016-06-29 14:37
|
# Generated by Django 1.9.7 on 2016-06-29 14:37
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.11 on 2018-03-23 15:30
|
# Generated by Django 1.11.11 on 2018-03-23 15:30
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.11 on 2018-03-30 22:48
|
# Generated by Django 1.11.11 on 2018-03-30 22:48
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.11 on 2018-03-31 13:32
|
# Generated by Django 1.11.11 on 2018-03-31 13:32
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# fargo - document box
|
# fargo - document box
|
||||||
# Copyright (C) 2016-2019 Entr'ouvert
|
# Copyright (C) 2016-2019 Entr'ouvert
|
||||||
#
|
#
|
||||||
|
@ -17,30 +16,27 @@
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import subprocess
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.urls import reverse
|
|
||||||
from django.db import models
|
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.text import slugify
|
|
||||||
from django.utils.http import urlquote
|
|
||||||
from django.utils.html import format_html
|
|
||||||
from django.dispatch import receiver
|
|
||||||
from django.db.models.signals import post_save, post_delete
|
|
||||||
from django.core.files.storage import default_storage
|
from django.core.files.storage import default_storage
|
||||||
|
from django.db import models
|
||||||
from sorl.thumbnail import get_thumbnail, delete
|
from django.db.models.signals import post_delete, post_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.encoding import force_text, python_2_unicode_compatible
|
||||||
|
from django.utils.html import format_html
|
||||||
|
from django.utils.http import urlquote
|
||||||
|
from django.utils.text import slugify
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from jsonfield import JSONField
|
||||||
|
from sorl.thumbnail import delete, get_thumbnail
|
||||||
from sorl.thumbnail.conf import settings as thumbnail_settings
|
from sorl.thumbnail.conf import settings as thumbnail_settings
|
||||||
|
|
||||||
from jsonfield import JSONField
|
from . import managers, utils
|
||||||
|
|
||||||
from . import utils, managers
|
|
||||||
|
|
||||||
|
|
||||||
def slug_truncate(label, length=256):
|
def slug_truncate(label, length=256):
|
||||||
|
@ -58,7 +54,7 @@ class Origin(models.Model):
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.slug:
|
if not self.slug:
|
||||||
self.slug = slug_truncate(self.label)
|
self.slug = slug_truncate(self.label)
|
||||||
return super(Origin, self).save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.label
|
return self.label
|
||||||
|
@ -153,13 +149,13 @@ class Validation(models.Model):
|
||||||
parts = []
|
parts = []
|
||||||
for meta_field in self.metadata:
|
for meta_field in self.metadata:
|
||||||
parts.append(
|
parts.append(
|
||||||
_(u'%(label)s: %(value)s')
|
_('%(label)s: %(value)s')
|
||||||
% {
|
% {
|
||||||
'label': meta_field['label'],
|
'label': meta_field['label'],
|
||||||
'value': self.data.get(meta_field['varname'], ''),
|
'value': self.data.get(meta_field['varname'], ''),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return force_text(u'; '.join(parts))
|
return force_text('; '.join(parts))
|
||||||
|
|
||||||
display.short_description = _('description')
|
display.short_description = _('description')
|
||||||
|
|
||||||
|
@ -191,7 +187,7 @@ class Document(models.Model):
|
||||||
self.content_hash = utils.sha256_of_file(self.content)
|
self.content_hash = utils.sha256_of_file(self.content)
|
||||||
if not self.mime_type:
|
if not self.mime_type:
|
||||||
self.mime_type = utils.get_mime_type(self.content.file.name) or ''
|
self.mime_type = utils.get_mime_type(self.content.file.name) or ''
|
||||||
super(Document, self).save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def thumbnail(self):
|
def thumbnail(self):
|
||||||
|
@ -205,7 +201,7 @@ class Document(models.Model):
|
||||||
# check file exists and is readable
|
# check file exists and is readable
|
||||||
default_storage.open(thumbnail.name)
|
default_storage.open(thumbnail.name)
|
||||||
return thumbnail
|
return thumbnail
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -239,7 +235,7 @@ class Document(models.Model):
|
||||||
return {'src': self.thumbnail_data_url, 'width': thumbnail.width, 'height': thumbnail.height}
|
return {'src': self.thumbnail_data_url, 'width': thumbnail.width, 'height': thumbnail.height}
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u'%s %s' % (os.path.basename(self.content.name), self.content_hash[:6])
|
return '%s %s' % (os.path.basename(self.content.name), self.content_hash[:6])
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('document')
|
verbose_name = _('document')
|
||||||
|
|
|
@ -14,9 +14,8 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
|
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from django.utils.timezone import utc
|
|
||||||
from django.utils.encoding import smart_bytes
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.utils.encoding import smart_bytes
|
||||||
|
from django.utils.timezone import utc
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import magic
|
import magic
|
||||||
|
|
|
@ -15,39 +15,37 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from json import dumps
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
from json import dumps
|
||||||
|
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.conf import settings
|
||||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
|
||||||
from django.views.generic import CreateView, DeleteView, UpdateView, View, TemplateView
|
|
||||||
from django.urls import reverse, reverse_lazy
|
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
from django.shortcuts import get_object_or_404, resolve_url
|
|
||||||
from django.http import (
|
|
||||||
HttpResponse,
|
|
||||||
HttpResponseRedirect,
|
|
||||||
HttpResponseBadRequest,
|
|
||||||
HttpResponseForbidden,
|
|
||||||
Http404,
|
|
||||||
)
|
|
||||||
from django.core import signing
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import get_user_model, REDIRECT_FIELD_NAME
|
from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model
|
||||||
from django.contrib.auth import logout as auth_logout
|
from django.contrib.auth import logout as auth_logout
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
from django.utils.http import quote
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.translation import ugettext as _
|
from django.core import signing
|
||||||
|
from django.core.exceptions import PermissionDenied
|
||||||
|
from django.http import (
|
||||||
|
Http404,
|
||||||
|
HttpResponse,
|
||||||
|
HttpResponseBadRequest,
|
||||||
|
HttpResponseForbidden,
|
||||||
|
HttpResponseRedirect,
|
||||||
|
)
|
||||||
|
from django.shortcuts import get_object_or_404, resolve_url
|
||||||
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.http import quote
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
from django.views.decorators.cache import never_cache
|
from django.views.decorators.cache import never_cache
|
||||||
from django.conf import settings
|
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||||
|
from django.views.generic import CreateView, DeleteView, TemplateView, UpdateView, View
|
||||||
from django_tables2 import SingleTableMixin
|
from django_tables2 import SingleTableMixin
|
||||||
|
|
||||||
from ..utils import make_url
|
from ..utils import make_url
|
||||||
from . import models, forms, tables
|
from . import forms, models, tables
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from mellon.utils import get_idps
|
from mellon.utils import get_idps
|
||||||
|
@ -57,12 +55,12 @@ except ImportError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
class Logger(object):
|
class Logger:
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Documents(object):
|
class Documents:
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return models.UserDocument.objects.filter(user=self.request.user).select_related('document', 'user')
|
return models.UserDocument.objects.filter(user=self.request.user).select_related('document', 'user')
|
||||||
|
|
||||||
|
@ -81,14 +79,14 @@ class CommonUpload(Logger, Documents, CreateView):
|
||||||
template_name = 'fargo/upload.html'
|
template_name = 'fargo/upload.html'
|
||||||
|
|
||||||
def get_form_kwargs(self, **kwargs):
|
def get_form_kwargs(self, **kwargs):
|
||||||
kwargs = super(CommonUpload, self).get_form_kwargs(**kwargs)
|
kwargs = super().get_form_kwargs(**kwargs)
|
||||||
kwargs['instance'] = models.UserDocument(user=self.request.user)
|
kwargs['instance'] = models.UserDocument(user=self.request.user)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
result = super(CommonUpload, self).form_valid(form)
|
result = super().form_valid(form)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
u'user uploaded file %s (sha256=%s)', self.object.filename, self.object.document.content_hash
|
'user uploaded file %s (sha256=%s)', self.object.filename, self.object.document.content_hash
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -101,12 +99,12 @@ class Upload(CommonUpload):
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
if self.full:
|
if self.full:
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
return super(Upload, self).dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
if 'cancel' in request.POST:
|
if 'cancel' in request.POST:
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
return super(Upload, self).post(request, *args, **kwargs)
|
return super().post(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Homepage(SingleTableMixin, CommonUpload):
|
class Homepage(SingleTableMixin, CommonUpload):
|
||||||
|
@ -121,7 +119,7 @@ class Homepage(SingleTableMixin, CommonUpload):
|
||||||
success_url = reverse_lazy('home')
|
success_url = reverse_lazy('home')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super(Homepage, self).get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
ctx['include_edit_link'] = settings.INCLUDE_EDIT_LINK
|
ctx['include_edit_link'] = settings.INCLUDE_EDIT_LINK
|
||||||
ctx['max_document_size'] = settings.FARGO_MAX_DOCUMENT_SIZE
|
ctx['max_document_size'] = settings.FARGO_MAX_DOCUMENT_SIZE
|
||||||
occupancy = ctx['occupancy'] = models.Document.objects.used_space(self.request.user)
|
occupancy = ctx['occupancy'] = models.Document.objects.used_space(self.request.user)
|
||||||
|
@ -138,12 +136,12 @@ class Homepage(SingleTableMixin, CommonUpload):
|
||||||
return super(CommonUpload, self).post(request, *args, **kwargs)
|
return super(CommonUpload, self).post(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class PickView(object):
|
class PickView:
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
self.pick_url = request.GET.get('pick')
|
self.pick_url = request.GET.get('pick')
|
||||||
if not self.pick_url:
|
if not self.pick_url:
|
||||||
return HttpResponseBadRequest('missing pick parameter')
|
return HttpResponseBadRequest('missing pick parameter')
|
||||||
return super(PickView, self).dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class PickList(PickView, Homepage):
|
class PickList(PickView, Homepage):
|
||||||
|
@ -152,7 +150,7 @@ class PickList(PickView, Homepage):
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
if 'cancel' in request.POST:
|
if 'cancel' in request.POST:
|
||||||
return HttpResponseRedirect(make_url(self.pick_url, cancel=''))
|
return HttpResponseRedirect(make_url(self.pick_url, cancel=''))
|
||||||
return super(PickList, self).post(request, *args, **kwargs)
|
return super().post(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Delete(Logger, Documents, DeleteView):
|
class Delete(Logger, Documents, DeleteView):
|
||||||
|
@ -161,7 +159,7 @@ class Delete(Logger, Documents, DeleteView):
|
||||||
def delete(self, request, *args, **kwargs):
|
def delete(self, request, *args, **kwargs):
|
||||||
if not self.get_object().deletable_by_user:
|
if not self.get_object().deletable_by_user:
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
result = super(Delete, self).delete(request, *args, **kwargs)
|
result = super().delete(request, *args, **kwargs)
|
||||||
messages.info(request, _('File %s deleted') % self.object.filename)
|
messages.info(request, _('File %s deleted') % self.object.filename)
|
||||||
self.logger.info('user deleted file %r(%s)', self.object.filename, self.object.pk)
|
self.logger.info('user deleted file %r(%s)', self.object.filename, self.object.pk)
|
||||||
return result
|
return result
|
||||||
|
@ -177,7 +175,7 @@ class Edit(Logger, UpdateView):
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
if getattr(request, 'user', None) != self.get_object().user:
|
if getattr(request, 'user', None) != self.get_object().user:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
return super(Edit, self).dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return '../..?%s' % self.request.META['QUERY_STRING']
|
return '../..?%s' % self.request.META['QUERY_STRING']
|
||||||
|
@ -195,7 +193,7 @@ class Pick(PickView, Documents, Logger, View):
|
||||||
request=request,
|
request=request,
|
||||||
)
|
)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
u'user picked file %s sha256 %s returned to %s',
|
'user picked file %s sha256 %s returned to %s',
|
||||||
user_document.filename,
|
user_document.filename,
|
||||||
user_document.document.content_hash,
|
user_document.document.content_hash,
|
||||||
pick,
|
pick,
|
||||||
|
@ -292,7 +290,7 @@ class ChooseDocumentKind(TemplateView):
|
||||||
template_name = 'fargo/choose_document_kind.html'
|
template_name = 'fargo/choose_document_kind.html'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super(ChooseDocumentKind, self).get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
ctx['document_kinds'] = settings.FARGO_DOCUMENT_KINDS
|
ctx['document_kinds'] = settings.FARGO_DOCUMENT_KINDS
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
@ -305,7 +303,7 @@ class LoginView(auth_views.LoginView):
|
||||||
return HttpResponseRedirect(
|
return HttpResponseRedirect(
|
||||||
resolve_url('mellon_login') + '?next=' + quote(request.GET.get('next'))
|
resolve_url('mellon_login') + '?next=' + quote(request.GET.get('next'))
|
||||||
)
|
)
|
||||||
return super(LoginView, self).get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
login = LoginView.as_view()
|
login = LoginView.as_view()
|
||||||
|
@ -316,7 +314,7 @@ class LogoutView(auth_views.LogoutView):
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
if any(get_idps()):
|
if any(get_idps()):
|
||||||
return HttpResponseRedirect(resolve_url('mellon_logout'))
|
return HttpResponseRedirect(resolve_url('mellon_logout'))
|
||||||
return super(LogoutView, self).dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
logout = LogoutView.as_view()
|
logout = LogoutView.as_view()
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from .models import OAuth2Client, OAuth2Authorize, OAuth2TempFile
|
from .models import OAuth2Authorize, OAuth2Client, OAuth2TempFile
|
||||||
|
|
||||||
|
|
||||||
class OAuth2ClientAdmin(admin.ModelAdmin):
|
class OAuth2ClientAdmin(admin.ModelAdmin):
|
||||||
|
|
|
@ -17,19 +17,16 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
from django.utils.six.moves.urllib import parse as urlparse
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from rest_framework.authentication import BasicAuthentication
|
from rest_framework.authentication import BasicAuthentication
|
||||||
from rest_framework.exceptions import AuthenticationFailed
|
from rest_framework.exceptions import AuthenticationFailed
|
||||||
|
|
||||||
from .models import OAuth2Client
|
from .models import OAuth2Client
|
||||||
|
|
||||||
|
|
||||||
class OAuth2User(object):
|
class OAuth2User:
|
||||||
"""Fake user class to return in case OAuth2 Client authentication"""
|
"""Fake user class to return in case OAuth2 Client authentication"""
|
||||||
|
|
||||||
def __init__(self, oauth2_client):
|
def __init__(self, oauth2_client):
|
||||||
|
@ -64,7 +61,7 @@ class FargoOAUTH2Authentication(BasicAuthentication):
|
||||||
|
|
||||||
authentic_idp = getattr(settings, 'FARGO_IDP_URL', None)
|
authentic_idp = getattr(settings, 'FARGO_IDP_URL', None)
|
||||||
if not authentic_idp:
|
if not authentic_idp:
|
||||||
logger.warning(u'idp check-password not configured')
|
logger.warning('idp check-password not configured')
|
||||||
return False, ''
|
return False, ''
|
||||||
|
|
||||||
url = urlparse.urljoin(authentic_idp, 'api/check-password/')
|
url = urlparse.urljoin(authentic_idp, 'api/check-password/')
|
||||||
|
@ -77,16 +74,16 @@ class FargoOAUTH2Authentication(BasicAuthentication):
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
logger.warning(u'idp check-password API failed: %s', e)
|
logger.warning('idp check-password API failed: %s', e)
|
||||||
return False, 'idp is down'
|
return False, 'idp is down'
|
||||||
try:
|
try:
|
||||||
response = response.json()
|
response = response.json()
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.warning(u'idp check-password API failed: %s, %r', e, response.content)
|
logger.warning('idp check-password API failed: %s, %r', e, response.content)
|
||||||
return False, 'idp is down'
|
return False, 'idp is down'
|
||||||
|
|
||||||
if response.get('result') == 0:
|
if response.get('result') == 0:
|
||||||
logger.warning(u'idp check-password API failed')
|
logger.warning('idp check-password API failed')
|
||||||
return False, response.get('errors', [''])[0]
|
return False, response.get('errors', [''])[0]
|
||||||
|
|
||||||
return True, None
|
return True, None
|
||||||
|
|
|
@ -29,6 +29,6 @@ class OAuth2AuthorizeForm(forms.Form):
|
||||||
document = UserDocModelChoiceField(queryset=None)
|
document = UserDocModelChoiceField(queryset=None)
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
def __init__(self, user, *args, **kwargs):
|
||||||
super(OAuth2AuthorizeForm, self).__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['document'].queryset = UserDocument.objects.filter(user=user)
|
self.fields['document'].queryset = UserDocument.objects.filter(user=user)
|
||||||
self.fields['document'].label = _('Document')
|
self.fields['document'].label = _('Document')
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from fargo.utils import make_url
|
|
||||||
from fargo.fargo.models import Document
|
from fargo.fargo.models import Document
|
||||||
from fargo.oauth2.models import OAuth2TempFile, OAuth2Client
|
from fargo.oauth2.models import OAuth2Client, OAuth2TempFile
|
||||||
|
from fargo.utils import make_url
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
from django.db import migrations, models
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import models, migrations
|
|
||||||
import fargo.oauth2.models
|
import fargo.oauth2.models
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.11 on 2018-03-31 13:36
|
# Generated by Django 1.11.11 on 2018-03-31 13:36
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
import fargo.oauth2.models
|
import fargo.oauth2.models
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.11 on 2018-03-21 23:43
|
# 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
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
def delete_all_client_linked_models(apps, schema_editor):
|
def delete_all_client_linked_models(apps, schema_editor):
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.11 on 2018-03-22 10:16
|
# Generated by Django 1.11.11 on 2018-03-22 10:16
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
import fargo.oauth2.models
|
import fargo.oauth2.models
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.11 on 2018-03-26 13:30
|
# Generated by Django 1.11.11 on 2018-03-26 13:30
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.11 on 2018-03-31 13:32
|
# Generated by Django 1.11.11 on 2018-03-31 13:32
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
|
@ -14,17 +14,17 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import uuid
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import uuid
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import URLValidator
|
from django.core.validators import URLValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from fargo.fargo.models import Document, UserDocument
|
from fargo.fargo.models import Document, UserDocument
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,11 @@ from django.conf.urls import url
|
||||||
|
|
||||||
from .views import (
|
from .views import (
|
||||||
authorize_get_document,
|
authorize_get_document,
|
||||||
get_document_token,
|
|
||||||
get_document,
|
|
||||||
authorize_put_document,
|
authorize_put_document,
|
||||||
put_document,
|
|
||||||
download_put_document,
|
download_put_document,
|
||||||
|
get_document,
|
||||||
|
get_document_token,
|
||||||
|
put_document,
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
|
|
||||||
import cgi
|
import cgi
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.http import unquote
|
from django.utils.http import unquote
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
from .models import OAuth2Authorize
|
from .models import OAuth2Authorize
|
||||||
|
|
||||||
|
@ -52,15 +52,7 @@ def get_content_disposition_value(request):
|
||||||
return None, 'wrong disposition type: attachment expected'
|
return None, 'wrong disposition type: attachment expected'
|
||||||
if 'filename*' in filename:
|
if 'filename*' in filename:
|
||||||
encode, country, name = filename['filename*'].split("'")
|
encode, country, name = filename['filename*'].split("'")
|
||||||
if six.PY3:
|
return (unquote(name, encode), None)
|
||||||
return (unquote(name, encode), None)
|
|
||||||
# check accepted charset from rfc 5987
|
|
||||||
if encode == 'UTF-8':
|
|
||||||
return unquote(name).decode('utf8'), None
|
|
||||||
elif encode == 'ISO-8859-1':
|
|
||||||
return unquote(name).decode('iso-8859-1'), None
|
|
||||||
else:
|
|
||||||
return None, 'unknown encoding: UTF-8 or ISO-8859-1 allowed'
|
|
||||||
elif 'filename' in filename:
|
elif 'filename' in filename:
|
||||||
return filename['filename'], None
|
return filename['filename'], None
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -16,30 +16,28 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.shortcuts import get_object_or_404
|
from django.conf import settings
|
||||||
from django.utils.http import quote
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.translation import ugettext as _
|
|
||||||
from django.utils.timezone import now
|
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
from django.urls import reverse
|
|
||||||
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseRedirect
|
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseRedirect
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.http import quote
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.views.generic import FormView, TemplateView, View
|
from django.views.generic import FormView, TemplateView, View
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
from fargo.fargo.models import Document, UserDocument
|
||||||
|
from fargo.utils import make_url
|
||||||
|
|
||||||
from .authentication import FargoOAUTH2Authentication
|
from .authentication import FargoOAUTH2Authentication
|
||||||
from .forms import OAuth2AuthorizeForm
|
from .forms import OAuth2AuthorizeForm
|
||||||
from .models import OAuth2Authorize, OAuth2Client, OAuth2TempFile
|
from .models import OAuth2Authorize, OAuth2Client, OAuth2TempFile
|
||||||
from .utils import authenticate_bearer, get_content_disposition_value
|
from .utils import authenticate_bearer, get_content_disposition_value
|
||||||
|
|
||||||
from fargo.fargo.models import UserDocument, Document
|
|
||||||
from fargo.utils import make_url
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +51,7 @@ class OAUTH2APIViewMixin(APIView):
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
return super(OAUTH2APIViewMixin, self).dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class OAuth2AuthorizeView(FormView):
|
class OAuth2AuthorizeView(FormView):
|
||||||
|
@ -83,15 +81,15 @@ class OAuth2AuthorizeView(FormView):
|
||||||
except OAuth2Client.DoesNotExist:
|
except OAuth2Client.DoesNotExist:
|
||||||
return self.redirect(error='unauthorized_client')
|
return self.redirect(error='unauthorized_client')
|
||||||
self.state = request.GET.get('state', None)
|
self.state = request.GET.get('state', None)
|
||||||
return super(OAuth2AuthorizeView, self).dispatch(request)
|
return super().dispatch(request)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
if 'cancel' in request.POST:
|
if 'cancel' in request.POST:
|
||||||
return self.redirect(error='access_denied')
|
return self.redirect(error='access_denied')
|
||||||
return super(OAuth2AuthorizeView, self).post(request)
|
return super().post(request)
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super(OAuth2AuthorizeView, self).get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
kwargs['user'] = self.request.user
|
kwargs['user'] = self.request.user
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
@ -99,7 +97,7 @@ class OAuth2AuthorizeView(FormView):
|
||||||
document = form.cleaned_data['document']
|
document = form.cleaned_data['document']
|
||||||
authorization = OAuth2Authorize.objects.create(client=self.client, user_document=document)
|
authorization = OAuth2Authorize.objects.create(client=self.client, user_document=document)
|
||||||
logger.info(
|
logger.info(
|
||||||
u'user %s authorized client "%s" to get document "%s" (%s) with code "%s"',
|
'user %s authorized client "%s" to get document "%s" (%s) with code "%s"',
|
||||||
self.request.user,
|
self.request.user,
|
||||||
self.client,
|
self.client,
|
||||||
document,
|
document,
|
||||||
|
@ -110,7 +108,7 @@ class OAuth2AuthorizeView(FormView):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs['oauth2_client'] = self.client
|
kwargs['oauth2_client'] = self.client
|
||||||
return super(OAuth2AuthorizeView, self).get_context_data(**kwargs)
|
return super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
authorize_get_document = login_required(OAuth2AuthorizeView.as_view())
|
authorize_get_document = login_required(OAuth2AuthorizeView.as_view())
|
||||||
|
@ -137,7 +135,7 @@ class GetDocumentTokenView(OAUTH2APIViewMixin):
|
||||||
if (now() - authorize.creation_date).total_seconds() > settings.FARGO_CODE_LIFETIME:
|
if (now() - authorize.creation_date).total_seconds() > settings.FARGO_CODE_LIFETIME:
|
||||||
return self.error('invalid_grant', 'code is expired')
|
return self.error('invalid_grant', 'code is expired')
|
||||||
logger.info(
|
logger.info(
|
||||||
u'client "%s" resolved code "%s" to access token "%s"',
|
'client "%s" resolved code "%s" to access token "%s"',
|
||||||
request.user.oauth2_client,
|
request.user.oauth2_client,
|
||||||
authorize.code,
|
authorize.code,
|
||||||
authorize.access_token,
|
authorize.access_token,
|
||||||
|
@ -172,7 +170,7 @@ def get_document(request):
|
||||||
|
|
||||||
user_document = oauth_authorize.user_document
|
user_document = oauth_authorize.user_document
|
||||||
logger.info(
|
logger.info(
|
||||||
u'client "%s" retrieved document "%s" (%s) with access token "%s"',
|
'client "%s" retrieved document "%s" (%s) with access token "%s"',
|
||||||
oauth_authorize.client,
|
oauth_authorize.client,
|
||||||
user_document,
|
user_document,
|
||||||
user_document.pk,
|
user_document.pk,
|
||||||
|
@ -197,7 +195,7 @@ class PutDocumentAPIView(OAUTH2APIViewMixin):
|
||||||
response = Response()
|
response = Response()
|
||||||
response['Location'] = uri
|
response['Location'] = uri
|
||||||
logger.info(
|
logger.info(
|
||||||
u'client "%s" uploaded document "%s" (%s)',
|
'client "%s" uploaded document "%s" (%s)',
|
||||||
request.user.oauth2_client,
|
request.user.oauth2_client,
|
||||||
filename,
|
filename,
|
||||||
oauth2_document.pk,
|
oauth2_document.pk,
|
||||||
|
@ -220,7 +218,7 @@ class OAuth2AuthorizePutView(TemplateView):
|
||||||
if not self.redirect_uri:
|
if not self.redirect_uri:
|
||||||
return HttpResponseBadRequest('missing redirect_uri parameter')
|
return HttpResponseBadRequest('missing redirect_uri parameter')
|
||||||
self.oauth2_document = OAuth2TempFile.objects.filter(pk=kwargs['pk']).first()
|
self.oauth2_document = OAuth2TempFile.objects.filter(pk=kwargs['pk']).first()
|
||||||
return super(OAuth2AuthorizePutView, self).dispatch(request)
|
return super().dispatch(request)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
if self.oauth2_document:
|
if self.oauth2_document:
|
||||||
|
@ -242,7 +240,7 @@ class OAuth2AuthorizePutView(TemplateView):
|
||||||
else:
|
else:
|
||||||
kwargs['error_message'] = _('The document has not been uploaded')
|
kwargs['error_message'] = _('The document has not been uploaded')
|
||||||
kwargs['redirect_uri'] = self.request.GET['redirect_uri']
|
kwargs['redirect_uri'] = self.request.GET['redirect_uri']
|
||||||
return super(OAuth2AuthorizePutView, self).get_context_data(**kwargs)
|
return super().get_context_data(**kwargs)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
if not self.oauth2_document:
|
if not self.oauth2_document:
|
||||||
|
@ -258,7 +256,7 @@ class OAuth2AuthorizePutView(TemplateView):
|
||||||
filename=self.oauth2_document.filename,
|
filename=self.oauth2_document.filename,
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
u'user %s accepted document "%s" (%s) from client "%s"',
|
'user %s accepted document "%s" (%s) from client "%s"',
|
||||||
request.user,
|
request.user,
|
||||||
self.oauth2_document.filename,
|
self.oauth2_document.filename,
|
||||||
self.oauth2_document.pk,
|
self.oauth2_document.pk,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# fargo - document box
|
# fargo - document box
|
||||||
# Copyright (C) 2016-2019 Entr'ouvert
|
# Copyright (C) 2016-2019 Entr'ouvert
|
||||||
#
|
#
|
||||||
|
@ -24,11 +23,11 @@ https://docs.djangoproject.com/en/1.7/topics/settings/
|
||||||
For the full list of settings and their values, see
|
For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/1.7/ref/settings/
|
https://docs.djangoproject.com/en/1.7/ref/settings/
|
||||||
"""
|
"""
|
||||||
from django.conf.global_settings import STATICFILES_FINDERS
|
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from django.conf.global_settings import STATICFILES_FINDERS
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,17 +184,17 @@ FARGO_VALIDATION_LIFETIME = 3600 * 24 * 31 * 6 # nearly 6 months
|
||||||
FARGO_DOCUMENT_TYPES = [
|
FARGO_DOCUMENT_TYPES = [
|
||||||
{
|
{
|
||||||
'name': 'avis-d-imposition',
|
'name': 'avis-d-imposition',
|
||||||
'label': u'Avis d\'imposition',
|
'label': 'Avis d\'imposition',
|
||||||
'metadata': [
|
'metadata': [
|
||||||
{'label': u'Personne-s concernée-s', 'varname': 'personnes_concernees', 'type': 'string'},
|
{'label': 'Personne-s concernée-s', 'varname': 'personnes_concernees', 'type': 'string'},
|
||||||
{
|
{
|
||||||
'label': u'Année',
|
'label': 'Année',
|
||||||
'varname': 'annee',
|
'varname': 'annee',
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'validation': ' *[0-9]{4} *',
|
'validation': ' *[0-9]{4} *',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': u'Revenu fiscal de référence',
|
'label': 'Revenu fiscal de référence',
|
||||||
'varname': 'revenu_fiscal_de_reference',
|
'varname': 'revenu_fiscal_de_reference',
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
'validation': ' *[0-9]+ *',
|
'validation': ' *[0-9]+ *',
|
||||||
|
|
|
@ -18,23 +18,23 @@ from django.conf import settings
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from .fargo.api_views import push_document, recent_documents, router
|
||||||
from .fargo.views import (
|
from .fargo.views import (
|
||||||
home,
|
|
||||||
jsonp,
|
|
||||||
json,
|
|
||||||
download,
|
|
||||||
pick,
|
|
||||||
delete,
|
delete,
|
||||||
upload,
|
document_types,
|
||||||
|
download,
|
||||||
edit,
|
edit,
|
||||||
remote_download,
|
home,
|
||||||
|
json,
|
||||||
|
jsonp,
|
||||||
login,
|
login,
|
||||||
logout,
|
logout,
|
||||||
|
pick,
|
||||||
pick_list,
|
pick_list,
|
||||||
document_types,
|
remote_download,
|
||||||
thumbnail,
|
thumbnail,
|
||||||
|
upload,
|
||||||
)
|
)
|
||||||
from .fargo.api_views import push_document, recent_documents, router
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', home, name='home'),
|
url(r'^$', home, name='home'),
|
||||||
|
|
|
@ -23,9 +23,10 @@ For more information on this file, see
|
||||||
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
|
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fargo.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fargo.settings")
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
13
setup.py
13
setup.py
|
@ -1,15 +1,14 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from setuptools.command.install_lib import install_lib as _install_lib
|
|
||||||
from distutils.command.build import build as _build
|
|
||||||
from setuptools.command.sdist import sdist
|
|
||||||
from distutils.cmd import Command
|
from distutils.cmd import Command
|
||||||
from setuptools import setup, find_packages
|
from distutils.command.build import build as _build
|
||||||
|
|
||||||
|
from setuptools import find_packages, setup
|
||||||
|
from setuptools.command.install_lib import install_lib as _install_lib
|
||||||
|
from setuptools.command.sdist import sdist
|
||||||
|
|
||||||
|
|
||||||
class eo_sdist(sdist):
|
class eo_sdist(sdist):
|
||||||
|
@ -30,7 +29,7 @@ def get_version():
|
||||||
tag exists, take 0.0- and add the length of the commit log.
|
tag exists, take 0.0- and add the length of the commit log.
|
||||||
"""
|
"""
|
||||||
if os.path.exists('VERSION'):
|
if os.path.exists('VERSION'):
|
||||||
with open('VERSION', 'r') as v:
|
with open('VERSION') as v:
|
||||||
return v.read()
|
return v.read()
|
||||||
if os.path.exists('.git'):
|
if os.path.exists('.git'):
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# fargo - document box
|
# fargo - document box
|
||||||
# Copyright (C) 2016-2019 Entr'ouvert
|
# Copyright (C) 2016-2019 Entr'ouvert
|
||||||
#
|
#
|
||||||
|
@ -17,13 +16,13 @@
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import pytest
|
|
||||||
import django_webtest
|
import django_webtest
|
||||||
|
import pytest
|
||||||
from django.core.files.base import ContentFile
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.files.base import ContentFile
|
||||||
|
|
||||||
from fargo.fargo.models import UserDocument, Document
|
from fargo.fargo.models import Document, UserDocument
|
||||||
|
|
||||||
|
|
||||||
class WebTestMixin(django_webtest.WebTestMixin):
|
class WebTestMixin(django_webtest.WebTestMixin):
|
||||||
|
|
|
@ -18,9 +18,10 @@ import base64
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from fargo.fargo import utils, models
|
|
||||||
from test_manager import login
|
from test_manager import login
|
||||||
|
|
||||||
|
from fargo.fargo import models, utils
|
||||||
|
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,9 +49,9 @@ def test_create_validation(settings, app, admin_user, john_doe, jane_doe):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
response1 = app.post_json(url, params=data, status=201)
|
response1 = app.post_json(url, params=data, status=201)
|
||||||
assert set(response1.json.keys()) == set(['result', 'data'])
|
assert set(response1.json.keys()) == {'result', 'data'}
|
||||||
assert response1.json['result'] == 1
|
assert response1.json['result'] == 1
|
||||||
assert set(data.keys()) - set(['user_email']) < set(response1.json['data'].keys())
|
assert set(data.keys()) - {'user_email'} < set(response1.json['data'].keys())
|
||||||
assert models.Validation.objects.count() == 1
|
assert models.Validation.objects.count() == 1
|
||||||
data['user_email'] = jane_doe.email
|
data['user_email'] = jane_doe.email
|
||||||
response2 = app.post_json(url, params=data, status=201)
|
response2 = app.post_json(url, params=data, status=201)
|
||||||
|
@ -79,7 +80,7 @@ def test_push_document(app, admin_user, john_doe):
|
||||||
assert models.UserDocument.objects.count() == 0
|
assert models.UserDocument.objects.count() == 0
|
||||||
assert models.Document.objects.count() == 0
|
assert models.Document.objects.count() == 0
|
||||||
assert response.json['result'] == 0
|
assert response.json['result'] == 0
|
||||||
assert set(response.json['errors'].keys()) == set(['origin', 'file_b64_content'])
|
assert set(response.json['errors'].keys()) == {'origin', 'file_b64_content'}
|
||||||
data.update(
|
data.update(
|
||||||
{
|
{
|
||||||
'origin': 'wcs',
|
'origin': 'wcs',
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.files.base import ContentFile
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from fargo.fargo.models import Document, UserDocument
|
||||||
from fargo.fargo.models import UserDocument, Document
|
from fargo.oauth2.models import OAuth2Client, OAuth2TempFile
|
||||||
from fargo.oauth2.models import OAuth2TempFile, OAuth2Client
|
|
||||||
from django.core.files.base import ContentFile
|
|
||||||
|
|
||||||
|
|
||||||
def test_cleanup(freezer, john_doe):
|
def test_cleanup(freezer, john_doe):
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
import pytest
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
|
|
||||||
from fargo.fargo.models import Document
|
from fargo.fargo.models import Document
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# fargo - document box
|
# fargo - document box
|
||||||
# Copyright (C) 2016-2019 Entr'ouvert
|
# Copyright (C) 2016-2019 Entr'ouvert
|
||||||
#
|
#
|
||||||
|
@ -15,21 +14,20 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
import mock
|
import os
|
||||||
import pytest
|
from unittest import mock
|
||||||
|
|
||||||
from django.urls import reverse
|
import pytest
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.http import quote, urlencode
|
from django.utils.http import quote, urlencode
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
from django.utils.six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
from fargo.oauth2.models import OAuth2Client, OAuth2Authorize, OAuth2TempFile
|
|
||||||
from fargo.fargo.models import UserDocument
|
|
||||||
|
|
||||||
from test_manager import login
|
from test_manager import login
|
||||||
|
|
||||||
|
from fargo.fargo.models import UserDocument
|
||||||
|
from fargo.oauth2.models import OAuth2Authorize, OAuth2Client, OAuth2TempFile
|
||||||
|
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +77,7 @@ def test_get_document_oauth2(app, john_doe, oauth2_client, user_doc):
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
assert len(resp.form['document'].options) == 2
|
assert len(resp.form['document'].options) == 2
|
||||||
options = resp.form['document'].options
|
options = resp.form['document'].options
|
||||||
assert u'éléphant.txt' in options[1]
|
assert 'éléphant.txt' in options[1]
|
||||||
|
|
||||||
# select the second document 'éléphant.txt'
|
# select the second document 'éléphant.txt'
|
||||||
resp.form['document'].select(options[1][0])
|
resp.form['document'].select(options[1][0])
|
||||||
|
@ -161,9 +159,7 @@ def test_put_document(app, john_doe, oauth2_client):
|
||||||
assert OAuth2TempFile.objects.count() == 1
|
assert OAuth2TempFile.objects.count() == 1
|
||||||
assert UserDocument.objects.count() == 1
|
assert UserDocument.objects.count() == 1
|
||||||
assert OAuth2TempFile.objects.get().document == UserDocument.objects.get().document
|
assert OAuth2TempFile.objects.get().document == UserDocument.objects.get().document
|
||||||
assert UserDocument.objects.filter(
|
assert UserDocument.objects.filter(user=john_doe, document=doc.document, filename='éléphant.txt').exists()
|
||||||
user=john_doe, document=doc.document, filename=u'éléphant.txt'
|
|
||||||
).exists()
|
|
||||||
|
|
||||||
|
|
||||||
def test_confirm_put_document_file_exception(app, oauth2_client, john_doe, user_doc):
|
def test_confirm_put_document_file_exception(app, oauth2_client, john_doe, user_doc):
|
||||||
|
@ -197,7 +193,7 @@ def test_idp_authentication(mocked_post, settings, app, oauth2_client, john_doe,
|
||||||
params['redirect_uri'] = 'https://example.com'
|
params['redirect_uri'] = 'https://example.com'
|
||||||
resp = app.get(url, params=params)
|
resp = app.get(url, params=params)
|
||||||
options = resp.form['document'].options
|
options = resp.form['document'].options
|
||||||
assert u'éléphant.txt' in options[1]
|
assert 'éléphant.txt' in options[1]
|
||||||
resp.form['document'].select(options[1][0])
|
resp.form['document'].select(options[1][0])
|
||||||
resp = resp.form.submit()
|
resp = resp.form.submit()
|
||||||
auth = OAuth2Authorize.objects.filter(user_document__user=john_doe)[0]
|
auth = OAuth2Authorize.objects.filter(user_document__user=john_doe)[0]
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# fargo - document box
|
# fargo - document box
|
||||||
# Copyright (C) 2016-2019 Entr'ouvert
|
# Copyright (C) 2016-2019 Entr'ouvert
|
||||||
#
|
#
|
||||||
|
@ -16,21 +15,20 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
from webtest import Upload
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
from django.utils.six.moves.urllib import parse as urlparse
|
||||||
|
from webtest import Upload
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import magic
|
import magic
|
||||||
except ImportError:
|
except ImportError:
|
||||||
magic = None
|
magic = None
|
||||||
|
|
||||||
from fargo.fargo.models import UserDocument
|
|
||||||
|
|
||||||
from test_manager import login
|
from test_manager import login
|
||||||
|
|
||||||
|
from fargo.fargo.models import UserDocument
|
||||||
|
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +57,7 @@ def test_upload(app, john_doe):
|
||||||
form['content'] = Upload('monfichier.pdf', b'%PDF-1.4 ...', 'application/pdf')
|
form['content'] = Upload('monfichier.pdf', b'%PDF-1.4 ...', 'application/pdf')
|
||||||
response2 = form.submit().follow()
|
response2 = form.submit().follow()
|
||||||
assert 'monfichier.pdf' in response2.text
|
assert 'monfichier.pdf' in response2.text
|
||||||
assert u'12 bytes' in response2.text
|
assert '12 bytes' in response2.text
|
||||||
if magic is not None:
|
if magic is not None:
|
||||||
assert UserDocument.objects.get(filename='monfichier.pdf').document.mime_type == 'application/pdf'
|
assert UserDocument.objects.get(filename='monfichier.pdf').document.mime_type == 'application/pdf'
|
||||||
assert ' mime-application ' in response2.text
|
assert ' mime-application ' in response2.text
|
||||||
|
|
Loading…
Reference in New Issue