diff --git a/authentic2-ctl b/authentic2-ctl index ee2fef05d..7ac5bfa43 100755 --- a/authentic2-ctl +++ b/authentic2-ctl @@ -1,6 +1,7 @@ #!/usr/bin/env python import os import sys + import authentic2.logger if __name__ == "__main__": diff --git a/debian/debian_config.py b/debian/debian_config.py index 530d00d93..64a459624 100644 --- a/debian/debian_config.py +++ b/debian/debian_config.py @@ -1,6 +1,7 @@ import glob import os import warnings + from authentic2 import logger ETC_DIR = '/etc/authentic2/' @@ -123,6 +124,7 @@ A2_OPENED_SESSION_COOKIE_SECURE = True # Old settings method def extract_settings_from_environ(): import json + from django.core.exceptions import ImproperlyConfigured global MANAGERS, DATABASES, SENTRY_TRANSPORT, SENTRY_DSN, INSTALLED_APPS, SECURE_PROXY_SSL_HEADER, CACHES, SESSION_ENGINE, LDAP_AUTH_SETTINGS diff --git a/debian/multitenant/debian_config.py b/debian/multitenant/debian_config.py index 345028933..53e3a2d48 100644 --- a/debian/multitenant/debian_config.py +++ b/debian/multitenant/debian_config.py @@ -1,4 +1,5 @@ import os + from django.utils.translation import ugettext_lazy as _ # Debian defaults diff --git a/doc/conf.py b/doc/conf.py index 1413d24eb..961ffc73a 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -11,7 +11,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import os +import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/merge-coverage.py b/merge-coverage.py index 15577d5f0..73034c834 100755 --- a/merge-coverage.py +++ b/merge-coverage.py @@ -1,13 +1,13 @@ #!/usr/bin/python from __future__ import print_function -import sys -import os -import xml.etree.ElementTree as ET import logging +import os import re -from shutil import copyfile +import sys +import xml.etree.ElementTree as ET from optparse import OptionParser +from shutil import copyfile ### This file came from the https://github.com/flow123d/flow123d repo they were nice enough to spend time to write this. ### It is copied here for other people to use on its own. diff --git a/setup.py b/setup.py index 50dbe9c23..f313eb6ee 100755 --- a/setup.py +++ b/setup.py @@ -4,16 +4,16 @@ Setup script for Authentic 2 ''' +import glob +import os import subprocess import sys -import os -import glob +from distutils.cmd import Command +from distutils.command.build import build as _build -from setuptools import setup, find_packages +from setuptools import find_packages, setup from setuptools.command.install_lib import install_lib as _install_lib from setuptools.command.sdist import sdist as _sdist -from distutils.command.build import build as _build -from distutils.cmd import Command class compile_translations(Command): diff --git a/src/authentic2/__init__.py b/src/authentic2/__init__.py index 3624002d9..b5f7c7f9c 100644 --- a/src/authentic2/__init__.py +++ b/src/authentic2/__init__.py @@ -19,9 +19,10 @@ import django default_app_config = 'authentic2.app.Authentic2Config' if django.VERSION < (2,): - from . import validators from django.forms import fields + from . import validators + # query-string and form parameters used to query database charfield must be checked for NULL characters # https://code.djangoproject.com/ticket/30064 if not getattr(fields.CharField, 'a2_workaround', False): diff --git a/src/authentic2/a2_rbac/admin.py b/src/authentic2/a2_rbac/admin.py index 1c5c46d82..d7dedaecc 100644 --- a/src/authentic2/a2_rbac/admin.py +++ b/src/authentic2/a2_rbac/admin.py @@ -15,8 +15,8 @@ # along with this program. If not, see . from django.contrib import admin -from django.utils.translation import ugettext_lazy as _ from django.utils import six +from django.utils.translation import ugettext_lazy as _ from . import models diff --git a/src/authentic2/a2_rbac/apps.py b/src/authentic2/a2_rbac/apps.py index 737ea51f0..f19122af2 100644 --- a/src/authentic2/a2_rbac/apps.py +++ b/src/authentic2/a2_rbac/apps.py @@ -22,10 +22,12 @@ class Authentic2RBACConfig(AppConfig): verbose_name = 'Authentic2 RBAC' def ready(self): - from . import signal_handlers, models - from django.db.models.signals import post_save, post_migrate, post_delete + from django.db.models.signals import post_delete, post_migrate, post_save + from authentic2.models import Service + from . import models, signal_handlers + # update rbac on save to contenttype, ou and roles post_save.connect(signal_handlers.update_rbac_on_ou_post_save, sender=models.OrganizationalUnit) post_delete.connect(signal_handlers.update_rbac_on_ou_post_delete, sender=models.OrganizationalUnit) diff --git a/src/authentic2/a2_rbac/fields.py b/src/authentic2/a2_rbac/fields.py index 4b447f9b6..5d4137e87 100644 --- a/src/authentic2/a2_rbac/fields.py +++ b/src/authentic2/a2_rbac/fields.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.db.models import NullBooleanField from django import forms +from django.db.models import NullBooleanField class UniqueBooleanField(NullBooleanField): diff --git a/src/authentic2/a2_rbac/management.py b/src/authentic2/a2_rbac/management.py index 030d701f3..8e288f4b4 100644 --- a/src/authentic2/a2_rbac/management.py +++ b/src/authentic2/a2_rbac/management.py @@ -14,18 +14,17 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.utils import six -from django.utils.translation import ugettext_lazy as _, ugettext -from django.utils.text import slugify from django.contrib.contenttypes.models import ContentType +from django.utils import six +from django.utils.text import slugify +from django.utils.translation import ugettext +from django.utils.translation import ugettext_lazy as _ from django_rbac.models import ADMIN_OP -from django_rbac.utils import get_ou_model -from django_rbac.utils import get_permission_model -from django_rbac.utils import get_role_model +from django_rbac.utils import get_ou_model, get_permission_model, get_role_model from ..utils import get_fk_model -from . import utils, app_settings +from . import app_settings, utils from .models import MANAGE_MEMBERS_OP diff --git a/src/authentic2/a2_rbac/managers.py b/src/authentic2/a2_rbac/managers.py index 98066503b..37e4c8975 100644 --- a/src/authentic2/a2_rbac/managers.py +++ b/src/authentic2/a2_rbac/managers.py @@ -16,10 +16,11 @@ from django.contrib.contenttypes.models import ContentType -from django_rbac.models import ADMIN_OP -from django_rbac.managers import RoleManager as BaseRoleManager, AbstractBaseManager -from django_rbac.utils import get_operation from django_rbac import utils as rbac_utils +from django_rbac.managers import AbstractBaseManager +from django_rbac.managers import RoleManager as BaseRoleManager +from django_rbac.models import ADMIN_OP +from django_rbac.utils import get_operation class OrganizationalUnitManager(AbstractBaseManager): diff --git a/src/authentic2/a2_rbac/migrations/0001_initial.py b/src/authentic2/a2_rbac/migrations/0001_initial.py index c6106014d..a4d5d6dfb 100644 --- a/src/authentic2/a2_rbac/migrations/0001_initial.py +++ b/src/authentic2/a2_rbac/migrations/0001_initial.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations -import authentic2.utils -import authentic2.a2_rbac.fields from django.conf import settings +from django.db import migrations, models + +import authentic2.a2_rbac.fields +import authentic2.utils class Migration(migrations.Migration): diff --git a/src/authentic2/a2_rbac/migrations/0002_role_external_id.py b/src/authentic2/a2_rbac/migrations/0002_role_external_id.py index 42ef1b57d..58ffd5278 100644 --- a/src/authentic2/a2_rbac/migrations/0002_role_external_id.py +++ b/src/authentic2/a2_rbac/migrations/0002_role_external_id.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/a2_rbac/migrations/0003_partial_unique_index_on_name_and_slug.py b/src/authentic2/a2_rbac/migrations/0003_partial_unique_index_on_name_and_slug.py index 1283a296e..fb6d18906 100644 --- a/src/authentic2/a2_rbac/migrations/0003_partial_unique_index_on_name_and_slug.py +++ b/src/authentic2/a2_rbac/migrations/0003_partial_unique_index_on_name_and_slug.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models + from authentic2.migrations import CreatePartialIndexes diff --git a/src/authentic2/a2_rbac/migrations/0004_auto_20150523_0028.py b/src/authentic2/a2_rbac/migrations/0004_auto_20150523_0028.py index d6545dc88..1d933518a 100644 --- a/src/authentic2/a2_rbac/migrations/0004_auto_20150523_0028.py +++ b/src/authentic2/a2_rbac/migrations/0004_auto_20150523_0028.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/a2_rbac/migrations/0005_auto_20150526_1406.py b/src/authentic2/a2_rbac/migrations/0005_auto_20150526_1406.py index b64ac0846..537537a75 100644 --- a/src/authentic2/a2_rbac/migrations/0005_auto_20150526_1406.py +++ b/src/authentic2/a2_rbac/migrations/0005_auto_20150526_1406.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/a2_rbac/migrations/0006_auto_20150619_1056.py b/src/authentic2/a2_rbac/migrations/0006_auto_20150619_1056.py index 690922721..663442607 100644 --- a/src/authentic2/a2_rbac/migrations/0006_auto_20150619_1056.py +++ b/src/authentic2/a2_rbac/migrations/0006_auto_20150619_1056.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/a2_rbac/migrations/0007_auto_20150708_1337.py b/src/authentic2/a2_rbac/migrations/0007_auto_20150708_1337.py index 9c745deca..948e0dbf9 100644 --- a/src/authentic2/a2_rbac/migrations/0007_auto_20150708_1337.py +++ b/src/authentic2/a2_rbac/migrations/0007_auto_20150708_1337.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/a2_rbac/migrations/0008_auto_20150810_1953.py b/src/authentic2/a2_rbac/migrations/0008_auto_20150810_1953.py index 945071136..4cbd0b6ca 100644 --- a/src/authentic2/a2_rbac/migrations/0008_auto_20150810_1953.py +++ b/src/authentic2/a2_rbac/migrations/0008_auto_20150810_1953.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/a2_rbac/migrations/0009_partial_unique_index_on_permission.py b/src/authentic2/a2_rbac/migrations/0009_partial_unique_index_on_permission.py index ce496741a..1cdddf4ba 100644 --- a/src/authentic2/a2_rbac/migrations/0009_partial_unique_index_on_permission.py +++ b/src/authentic2/a2_rbac/migrations/0009_partial_unique_index_on_permission.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models + from authentic2.migrations import CreatePartialIndexes diff --git a/src/authentic2/a2_rbac/migrations/0010_auto_20160209_1417.py b/src/authentic2/a2_rbac/migrations/0010_auto_20160209_1417.py index 1a0575b60..bf17ea996 100644 --- a/src/authentic2/a2_rbac/migrations/0010_auto_20160209_1417.py +++ b/src/authentic2/a2_rbac/migrations/0010_auto_20160209_1417.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals + from collections import defaultdict from django.db import migrations diff --git a/src/authentic2/a2_rbac/migrations/0011_auto_20160209_1511.py b/src/authentic2/a2_rbac/migrations/0011_auto_20160209_1511.py index 3fd5a9e35..82eed852f 100644 --- a/src/authentic2/a2_rbac/migrations/0011_auto_20160209_1511.py +++ b/src/authentic2/a2_rbac/migrations/0011_auto_20160209_1511.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/a2_rbac/migrations/0018_organizationalunit_user_add_password_policy.py b/src/authentic2/a2_rbac/migrations/0018_organizationalunit_user_add_password_policy.py index ac5ea45ee..cce62117c 100644 --- a/src/authentic2/a2_rbac/migrations/0018_organizationalunit_user_add_password_policy.py +++ b/src/authentic2/a2_rbac/migrations/0018_organizationalunit_user_add_password_policy.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/a2_rbac/migrations/0020_partial_unique_index_on_name.py b/src/authentic2/a2_rbac/migrations/0020_partial_unique_index_on_name.py index 039b710c8..e5533406c 100644 --- a/src/authentic2/a2_rbac/migrations/0020_partial_unique_index_on_name.py +++ b/src/authentic2/a2_rbac/migrations/0020_partial_unique_index_on_name.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models + from authentic2.migrations import CreatePartialIndexes diff --git a/src/authentic2/a2_rbac/migrations/0021_auto_20200317_1514.py b/src/authentic2/a2_rbac/migrations/0021_auto_20200317_1514.py index b08f6d5bb..6cbdca632 100644 --- a/src/authentic2/a2_rbac/migrations/0021_auto_20200317_1514.py +++ b/src/authentic2/a2_rbac/migrations/0021_auto_20200317_1514.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from django.db import migrations, models + import django_rbac.utils diff --git a/src/authentic2/a2_rbac/models.py b/src/authentic2/a2_rbac/models.py index 8c796e2d3..b17e8df9b 100644 --- a/src/authentic2/a2_rbac/models.py +++ b/src/authentic2/a2_rbac/models.py @@ -15,25 +15,26 @@ # along with this program. If not, see . from collections import namedtuple + +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError from django.core.validators import MinValueValidator -from django.utils import six -from django.utils.translation import ugettext_lazy as _, pgettext_lazy -from django.utils.text import slugify from django.db import models -from django.contrib.contenttypes.models import ContentType - -from django_rbac.models import ( - RoleAbstractBase, - PermissionAbstractBase, - OrganizationalUnitAbstractBase, - RoleParentingAbstractBase, - VIEW_OP, - Operation, -) -from django_rbac import utils as rbac_utils +from django.utils import six +from django.utils.text import slugify +from django.utils.translation import pgettext_lazy +from django.utils.translation import ugettext_lazy as _ from authentic2.decorators import errorcollector +from django_rbac import utils as rbac_utils +from django_rbac.models import ( + VIEW_OP, + Operation, + OrganizationalUnitAbstractBase, + PermissionAbstractBase, + RoleAbstractBase, + RoleParentingAbstractBase, +) try: from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation @@ -43,7 +44,7 @@ except ImportError: from authentic2.decorators import GlobalCache -from . import managers, fields, app_settings +from . import app_settings, fields, managers class OrganizationalUnit(OrganizationalUnitAbstractBase): diff --git a/src/authentic2/a2_rbac/signal_handlers.py b/src/authentic2/a2_rbac/signal_handlers.py index 2bb81ac5d..6447f7f87 100644 --- a/src/authentic2/a2_rbac/signal_handlers.py +++ b/src/authentic2/a2_rbac/signal_handlers.py @@ -14,15 +14,16 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.utils.translation import ugettext as _ -from django.conf import settings from django.apps import apps -from django.utils.translation import override +from django.conf import settings from django.db import DEFAULT_DB_ALIAS, router, transaction +from django.utils.translation import override +from django.utils.translation import ugettext as _ + +from django_rbac.managers import defer_update_transitive_closure +from django_rbac.utils import get_operation, get_ou_model, get_role_model from ..utils import get_fk_model -from django_rbac.utils import get_ou_model, get_role_model, get_operation -from django_rbac.managers import defer_update_transitive_closure def create_default_ou(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs): @@ -52,7 +53,7 @@ def create_default_ou(app_config, verbosity=2, interactive=True, using=DEFAULT_D def post_migrate_update_rbac(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs): # be sure new objects names are localized using the default locale - from .management import update_ous_admin_roles, update_content_types_roles + from .management import update_content_types_roles, update_ous_admin_roles if not router.allow_migrate(using, get_role_model()): return @@ -85,12 +86,12 @@ def update_service_role_ou(sender, instance, created, raw, **kwargs): def create_default_permissions(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs): from .models import ( - CHANGE_PASSWORD_OP, - RESET_PASSWORD_OP, ACTIVATE_OP, CHANGE_EMAIL_OP, - MANAGE_MEMBERS_OP, + CHANGE_PASSWORD_OP, MANAGE_AUTHORIZATIONS_OP, + MANAGE_MEMBERS_OP, + RESET_PASSWORD_OP, ) if not router.allow_migrate(using, get_ou_model()): diff --git a/src/authentic2/a2_rbac/utils.py b/src/authentic2/a2_rbac/utils.py index 468aed043..1a4cf78a8 100644 --- a/src/authentic2/a2_rbac/utils.py +++ b/src/authentic2/a2_rbac/utils.py @@ -16,9 +16,9 @@ from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType -from django_rbac.models import VIEW_OP, SEARCH_OP from django_rbac import utils as rbac_utils +from django_rbac.models import SEARCH_OP, VIEW_OP from . import models diff --git a/src/authentic2/admin.py b/src/authentic2/admin.py index f0d075176..667acd1a7 100644 --- a/src/authentic2/admin.py +++ b/src/authentic2/admin.py @@ -14,25 +14,25 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from copy import deepcopy import pprint +from copy import deepcopy -from django.contrib import admin -from django.conf import settings -from django.utils.translation import ugettext_lazy as _ -from django.utils import timezone -from django.views.decorators.cache import never_cache -from django.contrib.auth.admin import UserAdmin -from django.contrib.sessions.models import Session -from django.contrib.admin.utils import flatten_fieldsets -from django.db import transaction from django import forms +from django.conf import settings +from django.contrib import admin +from django.contrib.admin.utils import flatten_fieldsets +from django.contrib.auth.admin import UserAdmin from django.contrib.auth.forms import ReadOnlyPasswordHashField +from django.contrib.sessions.models import Session +from django.db import transaction +from django.utils import timezone +from django.utils.translation import ugettext_lazy as _ +from django.views.decorators.cache import never_cache -from .nonce.models import Nonce -from . import models, app_settings, decorators, attribute_kinds, utils +from . import app_settings, attribute_kinds, decorators, models, utils +from .custom_user.models import DeletedUser, User from .forms.profile import BaseUserForm, modelform_factory -from .custom_user.models import User, DeletedUser +from .nonce.models import Nonce def cleanup_action(modeladmin, request, queryset): diff --git a/src/authentic2/api_mixins.py b/src/authentic2/api_mixins.py index 41d5df1e7..84bc77b27 100644 --- a/src/authentic2/api_mixins.py +++ b/src/authentic2/api_mixins.py @@ -16,11 +16,9 @@ from django.db import transaction from django.utils.translation import ugettext_lazy as _ - from rest_framework import status +from rest_framework.exceptions import APIException, ValidationError from rest_framework.settings import api_settings -from rest_framework.exceptions import APIException -from rest_framework.exceptions import ValidationError from rest_framework.utils import model_meta diff --git a/src/authentic2/api_views.py b/src/authentic2/api_views.py index f92e7cf1d..6e83b6161 100644 --- a/src/authentic2/api_views.py +++ b/src/authentic2/api_views.py @@ -14,62 +14,60 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from functools import partial import logging import smtplib +from functools import partial -from pytz.exceptions import AmbiguousTimeError import django -from django.db import models +import requests from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.hashers import identify_hasher from django.core.exceptions import MultipleObjectsReturned -from django.utils.translation import ugettext as _ -from django.utils.text import slugify -from django.utils.encoding import force_text -from django.utils.dateparse import parse_datetime -from django.utils.translation import ugettext_lazy as _ -from django.views.decorators.vary import vary_on_headers -from django.views.decorators.cache import cache_control +from django.db import models from django.shortcuts import get_object_or_404 - -from django_rbac.utils import get_ou_model, get_role_model -import requests +from django.utils.dateparse import parse_datetime +from django.utils.encoding import force_text +from django.utils.text import slugify +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_lazy as _ +from django.views.decorators.cache import cache_control +from django.views.decorators.vary import vary_on_headers +from django_filters.fields import IsoDateTimeField +from django_filters.filters import IsoDateTimeFilter +from django_filters.rest_framework import FilterSet +from django_filters.utils import handle_timezone +from pytz.exceptions import AmbiguousTimeError from requests.exceptions import RequestException - -from rest_framework import serializers, pagination, VERSION as drf_version +from rest_framework import VERSION as drf_version +from rest_framework import authentication, pagination, permissions, serializers, status +from rest_framework.authentication import SessionAuthentication +from rest_framework.exceptions import AuthenticationFailed, NotFound, PermissionDenied, ValidationError +from rest_framework.fields import CreateOnlyDefault +from rest_framework.filters import BaseFilterBackend +from rest_framework.generics import GenericAPIView +from rest_framework.response import Response +from rest_framework.routers import SimpleRouter +from rest_framework.settings import api_settings from rest_framework.validators import UniqueTogetherValidator from rest_framework.views import APIView from rest_framework.viewsets import ModelViewSet, ViewSet -from rest_framework.routers import SimpleRouter -from rest_framework.generics import GenericAPIView -from rest_framework.response import Response -from rest_framework import permissions, status, authentication -from rest_framework.exceptions import PermissionDenied, AuthenticationFailed, ValidationError, NotFound -from rest_framework.fields import CreateOnlyDefault + from authentic2.compat.drf import action -from rest_framework.authentication import SessionAuthentication -from rest_framework.filters import BaseFilterBackend -from rest_framework.settings import api_settings +from django_rbac.utils import get_ou_model, get_role_model -from django_filters.rest_framework import FilterSet -from django_filters.filters import IsoDateTimeFilter -from django_filters.fields import IsoDateTimeField -from django_filters.utils import handle_timezone - -from .passwords import get_password_checker -from .custom_user.models import User -from . import utils, decorators, attribute_kinds, app_settings, hooks, api_mixins -from .models import Attribute, PasswordReset, Service +from . import api_mixins, app_settings, attribute_kinds, decorators, hooks, utils from .a2_rbac.utils import get_default_ou +from .custom_user.models import User from .journal_event_types import UserLogin, UserRegistration +from .models import Attribute, PasswordReset, Service +from .passwords import get_password_checker from .utils.lookups import Unaccent - # Retro-compatibility with older Django versions if django.VERSION < (2,): import rest_framework.fields + from . import validators rest_framework.fields.ProhibitNullCharactersValidator = validators.ProhibitNullCharactersValidator diff --git a/src/authentic2/app_settings.py b/src/authentic2/app_settings.py index 56b7c72bd..24be4e6c8 100644 --- a/src/authentic2/app_settings.py +++ b/src/authentic2/app_settings.py @@ -15,10 +15,10 @@ # along with this program. If not, see . import sys -import six -from django.utils.translation import ugettext_lazy as _ +import six from django.core.exceptions import ImproperlyConfigured +from django.utils.translation import ugettext_lazy as _ class Setting(object): diff --git a/src/authentic2/apps/journal/admin.py b/src/authentic2/apps/journal/admin.py index d930164cb..ca88f178b 100644 --- a/src/authentic2/apps/journal/admin.py +++ b/src/authentic2/apps/journal/admin.py @@ -19,7 +19,7 @@ import json from django.contrib import admin from django.utils.html import format_html -from .models import EventType, Event +from .models import Event, EventType class EventTypeAdmin(admin.ModelAdmin): diff --git a/src/authentic2/apps/journal/forms.py b/src/authentic2/apps/journal/forms.py index a18707b24..edc96a33c 100644 --- a/src/authentic2/apps/journal/forms.py +++ b/src/authentic2/apps/journal/forms.py @@ -16,11 +16,11 @@ from datetime import datetime +from django import forms from django.http import QueryDict from django.utils.formats import date_format from django.utils.functional import cached_property from django.utils.translation import ugettext_lazy as _ -from django import forms from . import models, search_engine diff --git a/src/authentic2/apps/journal/migrations/0001_initial.py b/src/authentic2/apps/journal/migrations/0001_initial.py index 7bcdc79d6..f200b40c9 100644 --- a/src/authentic2/apps/journal/migrations/0001_initial.py +++ b/src/authentic2/apps/journal/migrations/0001_initial.py @@ -1,10 +1,10 @@ # Generated by Django 2.2.15 on 2020-08-23 16:56 -from django.conf import settings import django.contrib.postgres.fields import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models from django.utils import timezone diff --git a/src/authentic2/apps/journal/models.py b/src/authentic2/apps/journal/models.py index 9963432a1..d7414b2fb 100644 --- a/src/authentic2/apps/journal/models.py +++ b/src/authentic2/apps/journal/models.py @@ -14,23 +14,23 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import logging +import re from collections import defaultdict from contextlib import contextmanager from datetime import datetime, timedelta -import logging -import re from django.conf import settings from django.contrib.auth import get_user_model +from django.contrib.contenttypes.models import ContentType from django.contrib.postgres.fields import ArrayField, JSONField from django.contrib.postgres.fields.jsonb import KeyTextTransform -from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.db import models -from django.db.models import QuerySet, Q, F, Value, Count +from django.db.models import Count, F, Q, QuerySet, Value from django.db.models.functions import Trunc +from django.utils.timezone import now, utc from django.utils.translation import ugettext_lazy as _ -from django.utils.timezone import utc, now from authentic2.decorators import GlobalCache diff --git a/src/authentic2/apps/journal/search_engine.py b/src/authentic2/apps/journal/search_engine.py index 58ef22053..e3d3669cd 100644 --- a/src/authentic2/apps/journal/search_engine.py +++ b/src/authentic2/apps/journal/search_engine.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from functools import reduce import re +from functools import reduce from django.contrib.auth import get_user_model from django.db.models import Q diff --git a/src/authentic2/apps/journal/sql.py b/src/authentic2/apps/journal/sql.py index 1f136246a..443c6c53f 100644 --- a/src/authentic2/apps/journal/sql.py +++ b/src/authentic2/apps/journal/sql.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.db.models import Func, Subquery from django.contrib.postgres.fields import ArrayField +from django.db.models import Func, Subquery class ArraySubquery(Func): diff --git a/src/authentic2/apps/journal/utils.py b/src/authentic2/apps/journal/utils.py index b3fd00358..366a39d57 100644 --- a/src/authentic2/apps/journal/utils.py +++ b/src/authentic2/apps/journal/utils.py @@ -14,9 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from datetime import timedelta, date +from datetime import date, timedelta -from django.db.models import Min, Max, DateField +from django.db.models import DateField, Max, Min def _json_value(value): diff --git a/src/authentic2/apps/journal/views.py b/src/authentic2/apps/journal/views.py index c4ea43fa4..0ff84528d 100644 --- a/src/authentic2/apps/journal/views.py +++ b/src/authentic2/apps/journal/views.py @@ -17,7 +17,7 @@ from django.views.generic import TemplateView from django.views.generic.edit import FormMixin -from . import models, forms +from . import forms, models class JournalView(FormMixin, TemplateView): diff --git a/src/authentic2/attribute_aggregator/migrations/0001_initial.py b/src/authentic2/attribute_aggregator/migrations/0001_initial.py index 9ce675ea0..e26665858 100644 --- a/src/authentic2/attribute_aggregator/migrations/0001_initial.py +++ b/src/authentic2/attribute_aggregator/migrations/0001_initial.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/attribute_aggregator/migrations/0002_auto_20150409_1840.py b/src/authentic2/attribute_aggregator/migrations/0002_auto_20150409_1840.py index 23618254d..60c9bbb6b 100644 --- a/src/authentic2/attribute_aggregator/migrations/0002_auto_20150409_1840.py +++ b/src/authentic2/attribute_aggregator/migrations/0002_auto_20150409_1840.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/attribute_aggregator/migrations/0003_auto_20150526_2239.py b/src/authentic2/attribute_aggregator/migrations/0003_auto_20150526_2239.py index 2d33df35b..e0370b69d 100644 --- a/src/authentic2/attribute_aggregator/migrations/0003_auto_20150526_2239.py +++ b/src/authentic2/attribute_aggregator/migrations/0003_auto_20150526_2239.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/attribute_aggregator/migrations/0004_auto_20150915_2041.py b/src/authentic2/attribute_aggregator/migrations/0004_auto_20150915_2041.py index 6fa2a5577..1a5d450f7 100644 --- a/src/authentic2/attribute_aggregator/migrations/0004_auto_20150915_2041.py +++ b/src/authentic2/attribute_aggregator/migrations/0004_auto_20150915_2041.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/attribute_kinds.py b/src/authentic2/attribute_kinds.py index 920312f47..60fd15be9 100644 --- a/src/authentic2/attribute_kinds.py +++ b/src/authentic2/attribute_kinds.py @@ -14,35 +14,32 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import re -import string import datetime import hashlib import os - +import re +import string from itertools import chain from django import forms from django.conf import settings from django.core.exceptions import ValidationError -from django.core.validators import RegexValidator -from django.urls import reverse -from django.utils import six, formats -from django.utils.translation import ugettext_lazy as _, pgettext_lazy -from django.utils import html from django.core.files.storage import default_storage +from django.core.validators import RegexValidator from django.db.models import query - +from django.urls import reverse +from django.utils import formats, html, six from django.utils.functional import keep_lazy - +from django.utils.translation import pgettext_lazy +from django.utils.translation import ugettext_lazy as _ from gadjo.templatetags.gadjo import xstatic from rest_framework import serializers from rest_framework.fields import empty -from .decorators import to_iter -from .plugins import collect_from_plugins from . import app_settings -from .forms import widgets, fields +from .decorators import to_iter +from .forms import fields, widgets +from .plugins import collect_from_plugins @keep_lazy(six.text_type) diff --git a/src/authentic2/attributes_ng/engine.py b/src/authentic2/attributes_ng/engine.py index c7f775451..f566cc827 100644 --- a/src/authentic2/attributes_ng/engine.py +++ b/src/authentic2/attributes_ng/engine.py @@ -18,8 +18,8 @@ import logging from django.utils.translation import ugettext as _ -from ..decorators import to_iter, to_list from .. import app_settings, plugins, utils +from ..decorators import to_iter, to_list __ALL__ = ['get_attribute_names', 'get_attributes', 'get_service_attributes'] diff --git a/src/authentic2/attributes_ng/sources/django_user.py b/src/authentic2/attributes_ng/sources/django_user.py index 0537016cb..13ab0c0b2 100644 --- a/src/authentic2/attributes_ng/sources/django_user.py +++ b/src/authentic2/attributes_ng/sources/django_user.py @@ -20,9 +20,8 @@ from django.utils.translation import ugettext_lazy as _ from django_rbac.utils import get_role_model -from ...models import Attribute, AttributeValue - from ...decorators import to_list +from ...models import Attribute, AttributeValue @to_list diff --git a/src/authentic2/attributes_ng/sources/format.py b/src/authentic2/attributes_ng/sources/format.py index 507075aad..93ed095ed 100644 --- a/src/authentic2/attributes_ng/sources/format.py +++ b/src/authentic2/attributes_ng/sources/format.py @@ -15,7 +15,6 @@ # along with this program. If not, see . import six - from django.core.exceptions import ImproperlyConfigured from ...decorators import to_list diff --git a/src/authentic2/attributes_ng/sources/ldap.py b/src/authentic2/attributes_ng/sources/ldap.py index ce0256c59..af520fbbe 100644 --- a/src/authentic2/attributes_ng/sources/ldap.py +++ b/src/authentic2/attributes_ng/sources/ldap.py @@ -14,10 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from ...decorators import to_list - from authentic2.backends.ldap_backend import LDAPBackend, LDAPUser +from ...decorators import to_list + @to_list def get_instances(ctx): diff --git a/src/authentic2/attributes_ng/sources/service_roles.py b/src/authentic2/attributes_ng/sources/service_roles.py index b001857db..0e83fae5b 100644 --- a/src/authentic2/attributes_ng/sources/service_roles.py +++ b/src/authentic2/attributes_ng/sources/service_roles.py @@ -16,10 +16,10 @@ from django.utils.translation import ugettext_lazy as _ -from ...models import Service from authentic2.a2_rbac.models import Role from ...decorators import to_list +from ...models import Service @to_list diff --git a/src/authentic2/auth2_auth/auth2_ssl/migrations/0001_initial.py b/src/authentic2/auth2_auth/auth2_ssl/migrations/0001_initial.py index 2f330ca6c..5ee7dd0d9 100644 --- a/src/authentic2/auth2_auth/auth2_ssl/migrations/0001_initial.py +++ b/src/authentic2/auth2_auth/auth2_ssl/migrations/0001_initial.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/auth2_auth/auth2_ssl/migrations/0002_auto_20150409_1840.py b/src/authentic2/auth2_auth/auth2_ssl/migrations/0002_auto_20150409_1840.py index 3cf5ca1de..683ec577d 100644 --- a/src/authentic2/auth2_auth/auth2_ssl/migrations/0002_auto_20150409_1840.py +++ b/src/authentic2/auth2_auth/auth2_ssl/migrations/0002_auto_20150409_1840.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/auth_migrations_18/0001_initial.py b/src/authentic2/auth_migrations_18/0001_initial.py index 916f2741b..82a81934f 100644 --- a/src/authentic2/auth_migrations_18/0001_initial.py +++ b/src/authentic2/auth_migrations_18/0001_initial.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django.core import validators -from django.db import models, migrations +from django.db import migrations, models from django.utils import timezone diff --git a/src/authentic2/auth_migrations_18/0002_auto_20150323_1720.py b/src/authentic2/auth_migrations_18/0002_auto_20150323_1720.py index a226231f0..360a16f63 100644 --- a/src/authentic2/auth_migrations_18/0002_auto_20150323_1720.py +++ b/src/authentic2/auth_migrations_18/0002_auto_20150323_1720.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations import django.core.validators +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/auth_migrations_18/0004_user.py b/src/authentic2/auth_migrations_18/0004_user.py index 2da7c25d7..54e3b0286 100644 --- a/src/authentic2/auth_migrations_18/0004_user.py +++ b/src/authentic2/auth_migrations_18/0004_user.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations -import django.utils.timezone import django.core.validators +import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/auth_migrations_18/0005_auto_20150526_2303.py b/src/authentic2/auth_migrations_18/0005_auto_20150526_2303.py index 52c018d7d..eee04666f 100644 --- a/src/authentic2/auth_migrations_18/0005_auto_20150526_2303.py +++ b/src/authentic2/auth_migrations_18/0005_auto_20150526_2303.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations -import django.core.validators import django.contrib.auth.models +import django.core.validators +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/authentication.py b/src/authentic2/authentication.py index 6cfb3a3dc..b1b76a4a9 100644 --- a/src/authentic2/authentication.py +++ b/src/authentic2/authentication.py @@ -23,10 +23,10 @@ try: except ImportError: CallableTrue = True -from authentic2_idp_oidc.models import OIDCClient - -from rest_framework.exceptions import AuthenticationFailed from rest_framework.authentication import BasicAuthentication +from rest_framework.exceptions import AuthenticationFailed + +from authentic2_idp_oidc.models import OIDCClient class OIDCUser(object): diff --git a/src/authentic2/authenticators.py b/src/authentic2/authenticators.py index 228fd3bf2..0e8e46adb 100644 --- a/src/authentic2/authenticators.py +++ b/src/authentic2/authenticators.py @@ -18,15 +18,18 @@ import logging from django.db.models import Count from django.shortcuts import render -from django.utils.translation import ugettext as _, ugettext_lazy +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_lazy -from authentic2.a2_rbac.models import OrganizationalUnit as OU, Role +from authentic2.a2_rbac.models import OrganizationalUnit as OU +from authentic2.a2_rbac.models import Role from authentic2.custom_user.models import User -from . import views, app_settings, utils -from .utils.views import csrf_token_check -from .utils.service import get_service_from_request + +from . import app_settings, utils, views from .forms import authentication as authentication_forms from .utils.evaluate import evaluate_condition +from .utils.service import get_service_from_request +from .utils.views import csrf_token_check logger = logging.getLogger(__name__) diff --git a/src/authentic2/backends/__init__.py b/src/authentic2/backends/__init__.py index 424c5cf58..cd1840c7c 100644 --- a/src/authentic2/backends/__init__.py +++ b/src/authentic2/backends/__init__.py @@ -15,6 +15,7 @@ # along with this program. If not, see . from django.contrib.auth import get_user_model + from authentic2 import app_settings diff --git a/src/authentic2/backends/ldap_backend.py b/src/authentic2/backends/ldap_backend.py index 797bddbcb..0bd3d0cc1 100644 --- a/src/authentic2/backends/ldap_backend.py +++ b/src/authentic2/backends/ldap_backend.py @@ -20,11 +20,10 @@ try: import ldap import ldap.modlist import ldap.sasl - from ldap.filter import filter_format + from ldap.controls import DecodeControlTuples, SimplePagedResultsControl, ppolicy from ldap.dn import escape_dn_chars + from ldap.filter import filter_format from ldap.ldapobject import ReconnectLDAPObject as NativeLDAPObject - from ldap.controls import SimplePagedResultsControl, DecodeControlTuples - from ldap.controls import ppolicy from pyasn1.codec.der import decoder PYTHON_LDAP3 = [int(x) for x in ldap.__version__.split('.')] >= [3] @@ -32,41 +31,40 @@ try: except ImportError: ldap = None PYTHON_LDAP3 = None -import logging -import random import base64 -import os import json +import logging +import os +import random import time -# code originaly copied from by now merely inspired by -# http://www.amherst.k12.oh.us/django-ldap.html - -from django.core.cache import cache -from django.core.exceptions import ImproperlyConfigured from django.conf import settings from django.contrib import messages from django.contrib.auth import get_user_model from django.contrib.auth.models import Group -from django.utils.encoding import force_bytes, force_text +from django.core.cache import cache +from django.core.exceptions import ImproperlyConfigured from django.utils import six +from django.utils.encoding import force_bytes, force_text from django.utils.six.moves.urllib import parse as urlparse -from django.utils.translation import ugettext as _, ngettext +from django.utils.translation import ngettext +from django.utils.translation import ugettext as _ +from authentic2 import app_settings, crypto from authentic2.a2_rbac.models import Role - -from authentic2.compat_lasso import lasso - -from authentic2 import crypto, app_settings -from authentic2.models import UserExternalId -from authentic2.middleware import StoreRequestMiddleware -from authentic2.user_login_failure import user_login_failure, user_login_success -from django_rbac.utils import get_ou_model from authentic2.a2_rbac.utils import get_default_ou -from authentic2.ldap_utils import FilterFormatter -from authentic2.utils import to_list - from authentic2.backends import is_user_authenticable +from authentic2.compat_lasso import lasso +from authentic2.ldap_utils import FilterFormatter +from authentic2.middleware import StoreRequestMiddleware +from authentic2.models import UserExternalId +from authentic2.user_login_failure import user_login_failure, user_login_success +from authentic2.utils import to_list +from django_rbac.utils import get_ou_model + +# code originaly copied from by now merely inspired by +# http://www.amherst.k12.oh.us/django-ldap.html + log = logging.getLogger(__name__) diff --git a/src/authentic2/backends/models_backend.py b/src/authentic2/backends/models_backend.py index 04ba13327..0fffa85e3 100644 --- a/src/authentic2/backends/models_backend.py +++ b/src/authentic2/backends/models_backend.py @@ -16,15 +16,15 @@ from __future__ import unicode_literals -from django.db import models from django.contrib.auth import get_user_model from django.contrib.auth.backends import ModelBackend +from django.db import models from django.utils import six -from .. import app_settings -from authentic2.user_login_failure import user_login_success, user_login_failure - from authentic2.backends import get_user_queryset +from authentic2.user_login_failure import user_login_failure, user_login_success + +from .. import app_settings def upn(username, realm): diff --git a/src/authentic2/cbv.py b/src/authentic2/cbv.py index b1edbbfa7..223eec063 100644 --- a/src/authentic2/cbv.py +++ b/src/authentic2/cbv.py @@ -14,14 +14,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.views.decorators.csrf import ensure_csrf_cookie, csrf_exempt - -from django.utils.decorators import method_decorator -from django.forms import Form -from django.contrib.auth import REDIRECT_FIELD_NAME from django.conf import settings +from django.contrib.auth import REDIRECT_FIELD_NAME +from django.forms import Form +from django.utils.decorators import method_decorator +from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie -from . import utils, hooks +from . import hooks, utils from .utils.views import csrf_token_check diff --git a/src/authentic2/compat/drf.py b/src/authentic2/compat/drf.py index fe9f9f3d1..a0d507a69 100644 --- a/src/authentic2/compat/drf.py +++ b/src/authentic2/compat/drf.py @@ -18,7 +18,7 @@ try: from rest_framework.decorators import action except ImportError: - from rest_framework.decorators import list_route, detail_route + from rest_framework.decorators import detail_route, list_route def action(**kwargs): kwargs.pop('name', None) diff --git a/src/authentic2/compat/misc.py b/src/authentic2/compat/misc.py index bbb44dc8e..d31107169 100644 --- a/src/authentic2/compat/misc.py +++ b/src/authentic2/compat/misc.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from datetime import datetime import inspect +from datetime import datetime from django.conf import settings from django.utils import six diff --git a/src/authentic2/context_processors.py b/src/authentic2/context_processors.py index 1f3dbbbb4..fe03aea0e 100644 --- a/src/authentic2/context_processors.py +++ b/src/authentic2/context_processors.py @@ -14,10 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from pkg_resources import get_distribution from django.conf import settings +from pkg_resources import get_distribution -from . import utils, app_settings, constants +from . import app_settings, constants, utils from .models import Service diff --git a/src/authentic2/cors.py b/src/authentic2/cors.py index 77d322fc2..25e67cc47 100644 --- a/src/authentic2/cors.py +++ b/src/authentic2/cors.py @@ -15,13 +15,13 @@ # along with this program. If not, see . import itertools -from .decorators import SessionCache from django.apps import apps from django.conf import settings from django.utils.six.moves.urllib import parse as urlparse -from . import plugins, app_settings +from . import app_settings, plugins +from .decorators import SessionCache def make_origin(url): diff --git a/src/authentic2/crypto.py b/src/authentic2/crypto.py index ab361efb7..091885c21 100644 --- a/src/authentic2/crypto.py +++ b/src/authentic2/crypto.py @@ -19,12 +19,10 @@ import hashlib import hmac import struct -from Cryptodome.Cipher import AES -from Cryptodome.Protocol.KDF import PBKDF2 -from Cryptodome.Hash import SHA256 -from Cryptodome.Hash import HMAC from Cryptodome import Random - +from Cryptodome.Cipher import AES +from Cryptodome.Hash import HMAC, SHA256 +from Cryptodome.Protocol.KDF import PBKDF2 from django.utils.crypto import constant_time_compare from django.utils.encoding import force_bytes from django.utils.six import text_type diff --git a/src/authentic2/csv_import.py b/src/authentic2/csv_import.py index ceac21941..f4da52934 100644 --- a/src/authentic2/csv_import.py +++ b/src/authentic2/csv_import.py @@ -19,9 +19,8 @@ from __future__ import unicode_literals import csv import io -from chardet.universaldetector import UniversalDetector import attr - +from chardet.universaldetector import UniversalDetector from django import forms from django.contrib.auth.hashers import identify_hasher from django.core.exceptions import FieldDoesNotExist, ValidationError @@ -29,18 +28,16 @@ from django.core.validators import RegexValidator from django.db import IntegrityError, models from django.db.transaction import atomic from django.utils import six -from django.utils.encoding import force_bytes -from django.utils.encoding import force_text +from django.utils.encoding import force_bytes, force_text from django.utils.translation import ugettext as _ -from django_rbac.utils import get_role_model - from authentic2 import app_settings from authentic2.a2_rbac.utils import get_default_ou from authentic2.custom_user.models import User -from authentic2.forms.profile import modelform_factory, BaseUserForm +from authentic2.forms.profile import BaseUserForm, modelform_factory from authentic2.models import Attribute, AttributeValue, UserExternalId from authentic2.utils import send_password_reset_mail +from django_rbac.utils import get_role_model Role = get_role_model() diff --git a/src/authentic2/custom_user/apps.py b/src/authentic2/custom_user/apps.py index 8b8eec057..b2d44522e 100644 --- a/src/authentic2/custom_user/apps.py +++ b/src/authentic2/custom_user/apps.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.db import DEFAULT_DB_ALIAS, router from django.apps import AppConfig +from django.db import DEFAULT_DB_ALIAS, router class CustomUserConfig(AppConfig): @@ -30,13 +30,14 @@ class CustomUserConfig(AppConfig): def create_first_name_last_name_attributes( self, app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs ): - from django.utils import translation - from django.utils.translation import ugettext_lazy as _ from django.conf import settings - from authentic2.attribute_kinds import get_kind - from authentic2.models import Attribute, AttributeValue from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType + from django.utils import translation + from django.utils.translation import ugettext_lazy as _ + + from authentic2.attribute_kinds import get_kind + from authentic2.models import Attribute, AttributeValue if not router.allow_migrate(using, Attribute): return diff --git a/src/authentic2/custom_user/management/commands/changepassword.py b/src/authentic2/custom_user/management/commands/changepassword.py index be045e1dd..8f2c92805 100644 --- a/src/authentic2/custom_user/management/commands/changepassword.py +++ b/src/authentic2/custom_user/management/commands/changepassword.py @@ -14,16 +14,16 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from __future__ import unicode_literals, print_function +from __future__ import print_function, unicode_literals import getpass from django.contrib.auth import get_user_model +from django.core.exceptions import MultipleObjectsReturned from django.core.management.base import BaseCommand, CommandError from django.db import DEFAULT_DB_ALIAS -from django.utils.encoding import force_str from django.db.models.query import Q -from django.core.exceptions import MultipleObjectsReturned +from django.utils.encoding import force_str class Command(BaseCommand): diff --git a/src/authentic2/custom_user/management/commands/fix-attributes.py b/src/authentic2/custom_user/management/commands/fix-attributes.py index d6f7c0aac..236c75429 100644 --- a/src/authentic2/custom_user/management/commands/fix-attributes.py +++ b/src/authentic2/custom_user/management/commands/fix-attributes.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from __future__ import unicode_literals, print_function +from __future__ import print_function, unicode_literals from django.core.management.base import BaseCommand diff --git a/src/authentic2/custom_user/managers.py b/src/authentic2/custom_user/managers.py index 18331906a..4b79bc50f 100644 --- a/src/authentic2/custom_user/managers.py +++ b/src/authentic2/custom_user/managers.py @@ -17,21 +17,20 @@ import unicodedata import uuid -from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.search import TrigramDistance -from django.core.exceptions import ValidationError -from django.db import models, connection -from django.db.models import F, Value, FloatField, Subquery, OuterRef, Q -from django.db.models.functions import Lower, Coalesce -from django.utils import timezone from django.contrib.auth.models import BaseUserManager -from django.contrib.postgres.search import SearchQuery +from django.contrib.contenttypes.models import ContentType +from django.contrib.postgres.search import SearchQuery, TrigramDistance +from django.core.exceptions import ValidationError +from django.db import connection, models +from django.db.models import F, FloatField, OuterRef, Q, Subquery, Value +from django.db.models.functions import Coalesce, Lower +from django.utils import timezone from authentic2 import app_settings -from authentic2.models import AttributeValue -from authentic2.utils.lookups import Unaccent, ImmutableConcat -from authentic2.utils.date import parse_date from authentic2.attribute_kinds import clean_number +from authentic2.models import AttributeValue +from authentic2.utils.date import parse_date +from authentic2.utils.lookups import ImmutableConcat, Unaccent class UserQuerySet(models.QuerySet): diff --git a/src/authentic2/custom_user/migrations/0001_initial.py b/src/authentic2/custom_user/migrations/0001_initial.py index 371a5e387..f25c0175b 100644 --- a/src/authentic2/custom_user/migrations/0001_initial.py +++ b/src/authentic2/custom_user/migrations/0001_initial.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations import django.utils.timezone +from django.db import migrations, models + import authentic2.utils import authentic2.validators diff --git a/src/authentic2/custom_user/migrations/0002_auto_20150410_1823.py b/src/authentic2/custom_user/migrations/0002_auto_20150410_1823.py index fa2759968..a0e02fe24 100644 --- a/src/authentic2/custom_user/migrations/0002_auto_20150410_1823.py +++ b/src/authentic2/custom_user/migrations/0002_auto_20150410_1823.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django.conf import settings -from django.db import models, migrations +from django.db import migrations, models class ThirdPartyAlterField(migrations.AlterField): diff --git a/src/authentic2/custom_user/migrations/0003_auto_20150504_1410.py b/src/authentic2/custom_user/migrations/0003_auto_20150504_1410.py index f19665135..90d779979 100644 --- a/src/authentic2/custom_user/migrations/0003_auto_20150504_1410.py +++ b/src/authentic2/custom_user/migrations/0003_auto_20150504_1410.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/custom_user/migrations/0004_user_ou.py b/src/authentic2/custom_user/migrations/0004_user_ou.py index 6aab7d434..c79c65ba9 100644 --- a/src/authentic2/custom_user/migrations/0004_user_ou.py +++ b/src/authentic2/custom_user/migrations/0004_user_ou.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/custom_user/migrations/0005_auto_20150522_1527.py b/src/authentic2/custom_user/migrations/0005_auto_20150522_1527.py index bcf37fa7a..9f8c3c43e 100644 --- a/src/authentic2/custom_user/migrations/0005_auto_20150522_1527.py +++ b/src/authentic2/custom_user/migrations/0005_auto_20150522_1527.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/custom_user/migrations/0006_auto_20150527_1212.py b/src/authentic2/custom_user/migrations/0006_auto_20150527_1212.py index 9ed54453c..26293a915 100644 --- a/src/authentic2/custom_user/migrations/0006_auto_20150527_1212.py +++ b/src/authentic2/custom_user/migrations/0006_auto_20150527_1212.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def noop(apps, schema_editor): diff --git a/src/authentic2/custom_user/migrations/0007_auto_20150610_1527.py b/src/authentic2/custom_user/migrations/0007_auto_20150610_1527.py index 32d6a8005..c39313cdb 100644 --- a/src/authentic2/custom_user/migrations/0007_auto_20150610_1527.py +++ b/src/authentic2/custom_user/migrations/0007_auto_20150610_1527.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def noop(apps, schema_editor): diff --git a/src/authentic2/custom_user/migrations/0008_auto_20150617_1606.py b/src/authentic2/custom_user/migrations/0008_auto_20150617_1606.py index bedac22b9..89f6a0924 100644 --- a/src/authentic2/custom_user/migrations/0008_auto_20150617_1606.py +++ b/src/authentic2/custom_user/migrations/0008_auto_20150617_1606.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/custom_user/migrations/0009_auto_20150810_1953.py b/src/authentic2/custom_user/migrations/0009_auto_20150810_1953.py index d36b8b519..2e481b668 100644 --- a/src/authentic2/custom_user/migrations/0009_auto_20150810_1953.py +++ b/src/authentic2/custom_user/migrations/0009_auto_20150810_1953.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/custom_user/migrations/0010_auto_20160307_1418.py b/src/authentic2/custom_user/migrations/0010_auto_20160307_1418.py index 16e03b95b..4faf10af5 100644 --- a/src/authentic2/custom_user/migrations/0010_auto_20160307_1418.py +++ b/src/authentic2/custom_user/migrations/0010_auto_20160307_1418.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/custom_user/migrations/0012_user_modified.py b/src/authentic2/custom_user/migrations/0012_user_modified.py index 8ad2bac54..44c3b6766 100644 --- a/src/authentic2/custom_user/migrations/0012_user_modified.py +++ b/src/authentic2/custom_user/migrations/0012_user_modified.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models import datetime + +from django.db import migrations, models from django.utils.timezone import utc diff --git a/src/authentic2/custom_user/migrations/0021_set_unusable_password.py b/src/authentic2/custom_user/migrations/0021_set_unusable_password.py index 688e242ea..6a5174e4e 100644 --- a/src/authentic2/custom_user/migrations/0021_set_unusable_password.py +++ b/src/authentic2/custom_user/migrations/0021_set_unusable_password.py @@ -2,9 +2,8 @@ # Generated by Django 1.11.29 on 2020-11-02 21:52 from __future__ import unicode_literals - -from django.db import migrations from django.contrib.auth.models import AbstractUser +from django.db import migrations def noop(apps, schema_editor): diff --git a/src/authentic2/custom_user/migrations/0026_remove_user_deleted.py b/src/authentic2/custom_user/migrations/0026_remove_user_deleted.py index dee7570fc..a4dae668e 100644 --- a/src/authentic2/custom_user/migrations/0026_remove_user_deleted.py +++ b/src/authentic2/custom_user/migrations/0026_remove_user_deleted.py @@ -1,6 +1,7 @@ # Generated by Django 2.2.19 on 2021-02-26 10:02 from django.db import migrations + from authentic2 import app_settings diff --git a/src/authentic2/custom_user/models.py b/src/authentic2/custom_user/models.py index 7e39d771d..a571bcbe5 100644 --- a/src/authentic2/custom_user/models.py +++ b/src/authentic2/custom_user/models.py @@ -22,28 +22,27 @@ import datetime import os import random -from django.db import models, transaction -from django.utils import timezone +from django.core.exceptions import MultipleObjectsReturned, ValidationError from django.core.mail import send_mail -from django.utils import six +from django.db import models, transaction +from django.utils import six, timezone from django.utils.translation import ugettext_lazy as _ -from django.core.exceptions import ValidationError, MultipleObjectsReturned try: from django.contrib.contenttypes.fields import GenericRelation except ImportError: from django.contrib.contenttypes.generic import GenericRelation + from django.contrib.auth.models import AbstractBaseUser from django.contrib.postgres.fields import JSONField +from authentic2 import app_settings, utils +from authentic2.decorators import RequestCache, errorcollector +from authentic2.models import Attribute, AttributeValue, Service, UserExternalId +from authentic2.validators import email_validator from django_rbac.models import PermissionMixin from django_rbac.utils import get_role_parenting_model -from authentic2 import utils, app_settings -from authentic2.decorators import errorcollector, RequestCache -from authentic2.models import Service, AttributeValue, Attribute, UserExternalId -from authentic2.validators import email_validator - from .managers import UserManager, UserQuerySet diff --git a/src/authentic2/data_transfer.py b/src/authentic2/data_transfer.py index b8c48bda4..361deb4b0 100644 --- a/src/authentic2/data_transfer.py +++ b/src/authentic2/data_transfer.py @@ -18,17 +18,16 @@ from __future__ import unicode_literals from functools import wraps -from django.core.exceptions import ValidationError, NON_FIELD_ERRORS from django.contrib.contenttypes.models import ContentType -from django.utils.translation import ugettext_lazy as _ +from django.core.exceptions import NON_FIELD_ERRORS, ValidationError from django.utils.text import format_lazy +from django.utils.translation import ugettext_lazy as _ -from django_rbac.models import Operation -from django_rbac.utils import get_ou_model, get_role_model, get_role_parenting_model, get_permission_model - -from authentic2.decorators import errorcollector from authentic2.a2_rbac.models import RoleAttribute +from authentic2.decorators import errorcollector from authentic2.utils.lazy import lazy_join +from django_rbac.models import Operation +from django_rbac.utils import get_ou_model, get_permission_model, get_role_model, get_role_parenting_model def update_model(obj, d): diff --git a/src/authentic2/decorators.py b/src/authentic2/decorators.py index d9ec93ae3..62641a4a3 100644 --- a/src/authentic2/decorators.py +++ b/src/authentic2/decorators.py @@ -17,21 +17,21 @@ import base64 import pickle import re -from json import dumps as json_dumps -from contextlib import contextmanager import time +from contextlib import contextmanager from functools import wraps +from json import dumps as json_dumps -from django.views.debug import technical_404_response -from django.http import Http404, HttpResponseForbidden, HttpResponse, HttpResponseBadRequest from django.core.cache import cache as django_cache from django.core.exceptions import ValidationError +from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseForbidden from django.utils import six +from django.views.debug import technical_404_response from . import app_settings, middleware # XXX: import to_list for retrocompaibility -from .utils import to_list, to_iter # noqa: F401 +from .utils import to_iter, to_list # noqa: F401 class CacheUnusable(RuntimeError): diff --git a/src/authentic2/disco_service/disco_responder.py b/src/authentic2/disco_service/disco_responder.py index 8a6e46a97..7ac230afa 100644 --- a/src/authentic2/disco_service/disco_responder.py +++ b/src/authentic2/disco_service/disco_responder.py @@ -23,15 +23,14 @@ import logging - from xml.dom.minidom import parseString -from django.http import HttpResponseRedirect from django.conf.urls import url -from django.utils.translation import ugettext as _ +from django.http import HttpResponseRedirect +from django.urls import reverse from django.utils.http import urlquote from django.utils.six.moves.urllib import parse as urlparse -from django.urls import reverse +from django.utils.translation import ugettext as _ from authentic2 import settings from authentic2.saml.common import error_page as base_error_page diff --git a/src/authentic2/exponential_retry_timeout.py b/src/authentic2/exponential_retry_timeout.py index 0968b8f2e..42f9d7ecf 100644 --- a/src/authentic2/exponential_retry_timeout.py +++ b/src/authentic2/exponential_retry_timeout.py @@ -14,12 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import time -import logging import hashlib +import logging +import time -from django.utils import six from django.core.cache import cache +from django.utils import six class ExponentialRetryTimeout(object): diff --git a/src/authentic2/forms/authentication.py b/src/authentic2/forms/authentication.py index ab4a5bc0b..8e3dc1575 100644 --- a/src/authentic2/forms/authentication.py +++ b/src/authentic2/forms/authentication.py @@ -19,17 +19,18 @@ import math from django import forms from django.conf import settings -from django.forms.widgets import Media -from django.utils.translation import ugettext_lazy as _, ugettext from django.contrib.auth import forms as auth_forms +from django.forms.widgets import Media from django.utils import html from django.utils.encoding import force_text +from django.utils.translation import ugettext +from django.utils.translation import ugettext_lazy as _ from authentic2.forms.fields import PasswordField from authentic2.utils.lazy import lazy_label -from ..a2_rbac.models import OrganizationalUnit as OU from .. import app_settings, utils +from ..a2_rbac.models import OrganizationalUnit as OU from ..exponential_retry_timeout import ExponentialRetryTimeout diff --git a/src/authentic2/forms/fields.py b/src/authentic2/forms/fields.py index 13fdb5343..9e77863c8 100644 --- a/src/authentic2/forms/fields.py +++ b/src/authentic2/forms/fields.py @@ -14,26 +14,25 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import warnings import io - -from django.forms import CharField, FileField, ValidationError, EmailField -from django.forms.fields import FILE_INPUT_CONTRADICTION -from django.utils.translation import ugettext_lazy as _ -from django.core.files import File - -from authentic2 import app_settings -from authentic2.passwords import password_help_text, validate_password -from authentic2.forms.widgets import ( - PasswordInput, - NewPasswordInput, - CheckPasswordInput, - ProfileImageInput, - EmailInput, -) -from authentic2.validators import email_validator +import warnings import PIL.Image +from django.core.files import File +from django.forms import CharField, EmailField, FileField, ValidationError +from django.forms.fields import FILE_INPUT_CONTRADICTION +from django.utils.translation import ugettext_lazy as _ + +from authentic2 import app_settings +from authentic2.forms.widgets import ( + CheckPasswordInput, + EmailInput, + NewPasswordInput, + PasswordInput, + ProfileImageInput, +) +from authentic2.passwords import password_help_text, validate_password +from authentic2.validators import email_validator class PasswordField(CharField): diff --git a/src/authentic2/forms/honeypot.py b/src/authentic2/forms/honeypot.py index 991b6db02..db51dc8b6 100644 --- a/src/authentic2/forms/honeypot.py +++ b/src/authentic2/forms/honeypot.py @@ -16,7 +16,7 @@ from django.core.exceptions import ValidationError -from django.forms import Form, CheckboxInput, BooleanField +from django.forms import BooleanField, CheckboxInput, Form from django.utils.html import mark_safe from django.utils.translation import gettext as _ diff --git a/src/authentic2/forms/passwords.py b/src/authentic2/forms/passwords.py index f71ab7b7f..e9d0a844c 100644 --- a/src/authentic2/forms/passwords.py +++ b/src/authentic2/forms/passwords.py @@ -17,20 +17,19 @@ import logging from collections import OrderedDict +from django import forms from django.contrib.auth import forms as auth_forms from django.core.exceptions import ValidationError from django.db.models import Q from django.forms import Form -from django import forms from django.urls import reverse from django.utils.translation import ugettext_lazy as _ -from .. import models, hooks, app_settings, utils +from .. import app_settings, hooks, models, utils from ..backends import get_user_queryset -from .fields import PasswordField, NewPasswordField, CheckPasswordField, ValidatedEmailField +from .fields import CheckPasswordField, NewPasswordField, PasswordField, ValidatedEmailField from .utils import NextUrlFormMixin - logger = logging.getLogger(__name__) diff --git a/src/authentic2/forms/profile.py b/src/authentic2/forms/profile.py index f6f77ed0a..ecf4f529e 100644 --- a/src/authentic2/forms/profile.py +++ b/src/authentic2/forms/profile.py @@ -16,15 +16,17 @@ from collections import OrderedDict -from django.forms.models import modelform_factory as dj_modelform_factory from django import forms -from django.utils.translation import ugettext_lazy as _, ugettext +from django.forms.models import modelform_factory as dj_modelform_factory +from django.utils.translation import ugettext +from django.utils.translation import ugettext_lazy as _ from authentic2 import app_settings, models from authentic2.custom_user.models import User -from .utils import NextUrlFormMixin -from .mixins import LockedFieldFormMixin + from .fields import ValidatedEmailField +from .mixins import LockedFieldFormMixin +from .utils import NextUrlFormMixin class DeleteAccountForm(forms.Form): diff --git a/src/authentic2/forms/registration.py b/src/authentic2/forms/registration.py index 263a7a895..d4d8d0530 100644 --- a/src/authentic2/forms/registration.py +++ b/src/authentic2/forms/registration.py @@ -17,19 +17,19 @@ import re from django.contrib.auth import get_user_model +from django.contrib.auth.models import BaseUserManager, Group from django.core.exceptions import ValidationError from django.core.validators import RegexValidator -from django.utils.translation import ugettext_lazy as _, ugettext +from django.utils.translation import ugettext +from django.utils.translation import ugettext_lazy as _ -from django.contrib.auth.models import BaseUserManager, Group - -from authentic2.forms.fields import NewPasswordField, CheckPasswordField from authentic2.a2_rbac.models import OrganizationalUnit +from authentic2.forms.fields import CheckPasswordField, NewPasswordField from .. import app_settings, models from . import profile as profile_forms -from .honeypot import HoneypotForm from .fields import ValidatedEmailField +from .honeypot import HoneypotForm User = get_user_model() diff --git a/src/authentic2/forms/widgets.py b/src/authentic2/forms/widgets.py index 9ce92e693..9f81fc798 100644 --- a/src/authentic2/forms/widgets.py +++ b/src/authentic2/forms/widgets.py @@ -23,21 +23,21 @@ # License: BSD # Initial Author: Alfredo Saglimbeni +import datetime import json import re import uuid -import datetime import django from django import forms -from django.forms.widgets import DateTimeInput, DateInput, TimeInput, ClearableFileInput +from django.forms.widgets import ClearableFileInput, DateInput, DateTimeInput +from django.forms.widgets import EmailInput as BaseEmailInput from django.forms.widgets import PasswordInput as BasePasswordInput -from django.forms.widgets import TextInput, EmailInput as BaseEmailInput -from django.utils.formats import get_language, get_format +from django.forms.widgets import TextInput, TimeInput +from django.utils.encoding import force_text +from django.utils.formats import get_format, get_language from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ -from django.utils.encoding import force_text - from gadjo.templatetags.gadjo import xstatic from authentic2 import app_settings diff --git a/src/authentic2/hashers.py b/src/authentic2/hashers.py index d6e138a2a..9d32c8006 100644 --- a/src/authentic2/hashers.py +++ b/src/authentic2/hashers.py @@ -14,17 +14,17 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import base64 import hashlib import math -import base64 from binascii import hexlify, unhexlify from collections import OrderedDict from django.contrib.auth import hashers -from django.utils.crypto import constant_time_compare -from django.utils.translation import ugettext_noop as _ -from django.utils.encoding import force_bytes, force_text from django.contrib.auth.hashers import make_password +from django.utils.crypto import constant_time_compare +from django.utils.encoding import force_bytes, force_text +from django.utils.translation import ugettext_noop as _ class Drupal7PasswordHasher(hashers.BasePasswordHasher): diff --git a/src/authentic2/idp/migrations/0001_initial.py b/src/authentic2/idp/migrations/0001_initial.py index 0559d3d94..9cfd46118 100644 --- a/src/authentic2/idp/migrations/0001_initial.py +++ b/src/authentic2/idp/migrations/0001_initial.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/idp/migrations/0002_auto_20150526_2239.py b/src/authentic2/idp/migrations/0002_auto_20150526_2239.py index ce360ce5f..9a2dd7665 100644 --- a/src/authentic2/idp/migrations/0002_auto_20150526_2239.py +++ b/src/authentic2/idp/migrations/0002_auto_20150526_2239.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/idp/migrations/0003_auto_20150915_2041.py b/src/authentic2/idp/migrations/0003_auto_20150915_2041.py index 9ec73b5b0..a1b5a923e 100644 --- a/src/authentic2/idp/migrations/0003_auto_20150915_2041.py +++ b/src/authentic2/idp/migrations/0003_auto_20150915_2041.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/idp/saml/__init__.py b/src/authentic2/idp/saml/__init__.py index 126945114..7d1d4580d 100644 --- a/src/authentic2/idp/saml/__init__.py +++ b/src/authentic2/idp/saml/__init__.py @@ -14,9 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.conf import settings -from django.core.checks import register, Warning, Tags from django.apps import AppConfig +from django.conf import settings +from django.core.checks import Tags, Warning, register class Plugin(object): diff --git a/src/authentic2/idp/saml/backend.py b/src/authentic2/idp/saml/backend.py index 5dafc5653..38b73be98 100644 --- a/src/authentic2/idp/saml/backend.py +++ b/src/authentic2/idp/saml/backend.py @@ -18,17 +18,16 @@ import logging import operator import random -from django.utils.translation import ugettext as _ -from django.template.loader import render_to_string from django.db.models import Q +from django.template.loader import render_to_string +from django.urls import reverse from django.utils import six from django.utils.six.moves.urllib.parse import quote -from django.urls import reverse +from django.utils.translation import ugettext as _ -import authentic2.saml.models as models import authentic2.idp.saml.saml2_endpoints as saml2_endpoints import authentic2.saml.common as common - +import authentic2.saml.models as models from authentic2.decorators import to_list from authentic2.utils import Service diff --git a/src/authentic2/idp/saml/common.py b/src/authentic2/idp/saml/common.py index 06c55bd3a..ec2da4b7c 100644 --- a/src/authentic2/idp/saml/common.py +++ b/src/authentic2/idp/saml/common.py @@ -15,12 +15,12 @@ # along with this program. If not, see . import logging - -from django.contrib.auth import REDIRECT_FIELD_NAME -from django.utils.http import urlencode from importlib import import_module + from django.conf import settings +from django.contrib.auth import REDIRECT_FIELD_NAME from django.http import HttpResponseRedirect +from django.utils.http import urlencode def redirect_to_login(next_url, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME, other_keys={}): diff --git a/src/authentic2/idp/saml/saml2_endpoints.py b/src/authentic2/idp/saml/saml2_endpoints.py index 4076871d9..96f468fe8 100644 --- a/src/authentic2/idp/saml/saml2_endpoints.py +++ b/src/authentic2/idp/saml/saml2_endpoints.py @@ -35,97 +35,87 @@ from __future__ import unicode_literals import datetime -import logging -import xml.etree.cElementTree as ctree import hashlib +import logging import random import string +import xml.etree.cElementTree as ctree from functools import wraps -from authentic2.compat_lasso import lasso -from django.contrib.auth import get_user_model +from django.conf import settings +from django.contrib import messages +from django.contrib.auth import BACKEND_SESSION_KEY, REDIRECT_FIELD_NAME, get_user_model, load_backend from django.contrib.auth.decorators import login_required from django.core.exceptions import ObjectDoesNotExist -from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, HttpResponseBadRequest -from django.utils import six -from django.utils.translation import ugettext as _, ugettext_noop as N_ -from django.views.decorators.csrf import csrf_exempt -from django.views.decorators.cache import never_cache -from django.views.decorators.http import require_POST -from django.contrib.auth import BACKEND_SESSION_KEY, REDIRECT_FIELD_NAME -from django.conf import settings -from django.utils.encoding import force_str, force_bytes, force_text -from django.utils.six.moves.urllib.parse import quote, urlencode +from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect +from django.shortcuts import redirect, render from django.urls import reverse -from django.contrib.auth import load_backend -from django.shortcuts import render, redirect -from django.contrib import messages - +from django.utils import six +from django.utils.encoding import force_bytes, force_str, force_text +from django.utils.six.moves.urllib.parse import quote, urlencode +from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_noop as N_ +from django.views.decorators.cache import never_cache +from django.views.decorators.csrf import csrf_exempt +from django.views.decorators.http import require_POST +import authentic2.saml.saml2utils as saml2utils import authentic2.views as a2_views -from authentic2.saml.models import ( - LibertyArtifact, - LibertySession, - LibertyFederation, - nameid2kwargs, - saml2_urn_to_nidformat, - nidformat_to_saml2_urn, - save_key_values, - get_and_delete_key_values, - LibertyProvider, - LibertyServiceProvider, - SAMLAttribute, - NAME_ID_FORMATS, -) +from authentic2 import hooks, utils +from authentic2.attributes_ng.engine import get_attributes +from authentic2.compat_lasso import lasso +from authentic2.constants import NONCE_FIELD_NAME +from authentic2.idp import signals as idp_signals +from authentic2.idp.saml.common import kill_django_sessions from authentic2.saml.common import ( - redirect_next, - asynchronous_bindings, - soap_bindings, - load_provider, - get_saml2_request_message, - error_page, - set_saml2_response_responder_status_code, + AUTHENTIC_SAME_ID_SENTINEL, + AUTHENTIC_STATUS_CODE_INTERNAL_SERVER_ERROR, AUTHENTIC_STATUS_CODE_MISSING_DESTINATION, - load_federation, - return_saml2_response, - get_soap_message, - soap_fault, - return_saml_soap_response, - AUTHENTIC_STATUS_CODE_UNKNOWN_PROVIDER, AUTHENTIC_STATUS_CODE_MISSING_NAMEID, AUTHENTIC_STATUS_CODE_MISSING_SESSION_INDEX, - AUTHENTIC_STATUS_CODE_UNKNOWN_SESSION, - AUTHENTIC_STATUS_CODE_INTERNAL_SERVER_ERROR, AUTHENTIC_STATUS_CODE_UNAUTHORIZED, - send_soap_request, - get_saml2_query_request, - get_saml2_request_message_async_binding, + AUTHENTIC_STATUS_CODE_UNKNOWN_PROVIDER, + AUTHENTIC_STATUS_CODE_UNKNOWN_SESSION, + asynchronous_bindings, create_saml2_server, - get_saml2_metadata, - get_sp_options_policy, + error_page, get_entity_id, - AUTHENTIC_SAME_ID_SENTINEL, + get_saml2_metadata, + get_saml2_query_request, + get_saml2_request_message, + get_saml2_request_message_async_binding, + get_soap_message, + get_sp_options_policy, + load_federation, + load_provider, + redirect_next, + return_saml2_response, + return_saml_soap_response, + send_soap_request, + set_saml2_response_responder_status_code, + soap_bindings, + soap_fault, ) -import authentic2.saml.saml2utils as saml2utils -from authentic2.idp.saml.common import kill_django_sessions -from authentic2.constants import NONCE_FIELD_NAME - -from authentic2.idp import signals as idp_signals - -from authentic2.utils import ( - make_url, - get_backends as get_idp_backends, - login_require, - find_authentication_event, - datetime_to_xs_datetime, +from authentic2.saml.models import ( + NAME_ID_FORMATS, + LibertyArtifact, + LibertyFederation, + LibertyProvider, + LibertyServiceProvider, + LibertySession, + SAMLAttribute, + get_and_delete_key_values, + nameid2kwargs, + nidformat_to_saml2_urn, + saml2_urn_to_nidformat, + save_key_values, ) -from authentic2 import utils -from authentic2.attributes_ng.engine import get_attributes -from authentic2 import hooks +from authentic2.utils import datetime_to_xs_datetime, find_authentication_event +from authentic2.utils import get_backends as get_idp_backends +from authentic2.utils import login_require, make_url from . import app_settings - User = get_user_model() logger = logging.getLogger(__name__) diff --git a/src/authentic2/idp/saml/urls.py b/src/authentic2/idp/saml/urls.py index de2b9d122..df87f69b7 100644 --- a/src/authentic2/idp/saml/urls.py +++ b/src/authentic2/idp/saml/urls.py @@ -16,20 +16,21 @@ from django.conf.urls import url -from . import views from authentic2.idp.saml.saml2_endpoints import ( - metadata, - sso, - continue_sso, - slo, - slo_soap, - idp_slo, - slo_return, - finish_slo, artifact, + continue_sso, + finish_slo, + idp_slo, idp_sso, + metadata, + slo, + slo_return, + slo_soap, + sso, ) +from . import views + urlpatterns = [ url(r'^metadata$', metadata, name='a2-idp-saml-metadata'), url(r'^sso$', sso, name='a2-idp-saml-sso'), diff --git a/src/authentic2/idp/saml/views.py b/src/authentic2/idp/saml/views.py index e267932ec..d77fa6733 100644 --- a/src/authentic2/idp/saml/views.py +++ b/src/authentic2/idp/saml/views.py @@ -14,13 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.utils.translation import ugettext as _ -from django.views.generic import DeleteView, View +from django.contrib import messages +from django.contrib.auth import REDIRECT_FIELD_NAME from django.http import HttpResponseRedirect from django.urls import reverse - -from django.contrib.auth import REDIRECT_FIELD_NAME -from django.contrib import messages +from django.utils.translation import ugettext as _ +from django.views.generic import DeleteView, View from authentic2.saml.models import LibertyFederation diff --git a/src/authentic2/idp/urls.py b/src/authentic2/idp/urls.py index b8f7c5787..abdba3091 100644 --- a/src/authentic2/idp/urls.py +++ b/src/authentic2/idp/urls.py @@ -15,6 +15,7 @@ # along with this program. If not, see . from django.conf.urls import url + from authentic2.idp.interactions import consent_federation urlpatterns = [ diff --git a/src/authentic2/journal.py b/src/authentic2/journal.py index dfd7b9a14..8e00e52e2 100644 --- a/src/authentic2/journal.py +++ b/src/authentic2/journal.py @@ -14,9 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from authentic2.utils.service import get_service_from_request - from authentic2.apps.journal.journal import Journal +from authentic2.utils.service import get_service_from_request class Journal(Journal): diff --git a/src/authentic2/journal_event_types.py b/src/authentic2/journal_event_types.py index 27c1a56ff..7629fd13e 100644 --- a/src/authentic2/journal_event_types.py +++ b/src/authentic2/journal_event_types.py @@ -17,10 +17,9 @@ from django.contrib.contenttypes.models import ContentType from django.utils.translation import ugettext_lazy as _ -from authentic2.custom_user.models import get_attributes_map from authentic2.apps.journal.models import EventTypeDefinition, n_2_pairing_rev -from authentic2.apps.journal.utils import form_to_old_new, Statistics -from authentic2.custom_user.models import User +from authentic2.apps.journal.utils import Statistics, form_to_old_new +from authentic2.custom_user.models import User, get_attributes_map from .models import Service diff --git a/src/authentic2/ldap_utils.py b/src/authentic2/ldap_utils.py index 61d2317e8..213ff0158 100644 --- a/src/authentic2/ldap_utils.py +++ b/src/authentic2/ldap_utils.py @@ -19,7 +19,6 @@ import string import ldap.dn import ldap.filter - from django.utils.encoding import force_text diff --git a/src/authentic2/log_filters.py b/src/authentic2/log_filters.py index b8bf29f19..9e38966ae 100644 --- a/src/authentic2/log_filters.py +++ b/src/authentic2/log_filters.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import logging + from django.utils import six diff --git a/src/authentic2/management/commands/check-and-repair.py b/src/authentic2/management/commands/check-and-repair.py index 47131da0a..2e17b7caf 100644 --- a/src/authentic2/management/commands/check-and-repair.py +++ b/src/authentic2/management/commands/check-and-repair.py @@ -30,12 +30,12 @@ from django.db.transaction import atomic from django.utils.six.moves import input from django.utils.timezone import localtime +from authentic2 import app_settings +from authentic2.a2_rbac.models import OrganizationalUnit as OU +from authentic2.a2_rbac.models import Permission, Role from django_rbac.models import ADMIN_OP from django_rbac.utils import get_operation -from authentic2 import app_settings -from authentic2.a2_rbac.models import OrganizationalUnit as OU, Role, Permission - try: from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP except ImportError: @@ -44,8 +44,8 @@ from authentic2.custom_user.models import User MULTITENANT = 'hobo.multitenant' in settings.INSTALLED_APPS if MULTITENANT: - from tenant_schemas.utils import tenant_context from hobo.multitenant.middleware import TenantMiddleware + from tenant_schemas.utils import tenant_context class FakeState(object): diff --git a/src/authentic2/management/commands/clean-unused-accounts.py b/src/authentic2/management/commands/clean-unused-accounts.py index 67b3a574e..46a4f00e0 100644 --- a/src/authentic2/management/commands/clean-unused-accounts.py +++ b/src/authentic2/management/commands/clean-unused-accounts.py @@ -17,20 +17,19 @@ from __future__ import print_function import logging - from datetime import timedelta + +from django.conf import settings from django.contrib.auth import get_user_model from django.core.management.base import BaseCommand from django.db import transaction from django.db.models import F from django.utils import timezone, translation from django.utils.six.moves.urllib import parse as urlparse -from django_rbac.utils import get_ou_model from authentic2.backends.ldap_backend import LDAPBackend from authentic2.utils import send_templated_mail - -from django.conf import settings +from django_rbac.utils import get_ou_model logger = logging.getLogger(__name__) diff --git a/src/authentic2/management/commands/import_site.py b/src/authentic2/management/commands/import_site.py index 9ef8b7bf4..902833874 100644 --- a/src/authentic2/management/commands/import_site.py +++ b/src/authentic2/management/commands/import_site.py @@ -23,7 +23,7 @@ from django.core.management.base import BaseCommand from django.db import transaction from django.utils import translation -from authentic2.data_transfer import import_site, ImportContext +from authentic2.data_transfer import ImportContext, import_site class DryRunException(Exception): diff --git a/src/authentic2/management/commands/load-ldif.py b/src/authentic2/management/commands/load-ldif.py index d3687a29d..02108a6fa 100644 --- a/src/authentic2/management/commands/load-ldif.py +++ b/src/authentic2/management/commands/load-ldif.py @@ -15,22 +15,18 @@ # along with this program. If not, see . import argparse -import logging import json +import logging - -from django.core.management.base import BaseCommand +import ldif from django.contrib.auth import get_user_model +from django.core.management.base import BaseCommand from django.db.transaction import atomic - from authentic2.hashers import olap_password_to_dj from authentic2.models import Attribute -import ldif - - class DjangoUserLDIFParser(ldif.LDIFParser): def __init__(self, *args, **kwargs): self.options = kwargs.pop('options') diff --git a/src/authentic2/management/commands/resetpassword.py b/src/authentic2/management/commands/resetpassword.py index 60431180c..2a5d7a62c 100644 --- a/src/authentic2/management/commands/resetpassword.py +++ b/src/authentic2/management/commands/resetpassword.py @@ -20,9 +20,8 @@ from django.contrib.auth import get_user_model from django.core.management.base import BaseCommand, CommandError from django.db import DEFAULT_DB_ALIAS -from authentic2.utils import generate_password from authentic2.models import PasswordReset - +from authentic2.utils import generate_password User = get_user_model() diff --git a/src/authentic2/management/commands/slapd-shell.py b/src/authentic2/management/commands/slapd-shell.py index eb7eaa98e..7beaffa9a 100644 --- a/src/authentic2/management/commands/slapd-shell.py +++ b/src/authentic2/management/commands/slapd-shell.py @@ -17,16 +17,14 @@ from __future__ import print_function import logging -import sys import re - -from ldap.dn import escape_dn_chars -from ldif import LDIFWriter - +import sys from django.contrib.auth import get_user_model from django.core.management.base import BaseCommand from django.utils import six +from ldap.dn import escape_dn_chars +from ldif import LDIFWriter COMMAND = 1 ATTR = 2 diff --git a/src/authentic2/manager/apps.py b/src/authentic2/manager/apps.py index 7d36b4689..d918dc56a 100644 --- a/src/authentic2/manager/apps.py +++ b/src/authentic2/manager/apps.py @@ -23,6 +23,7 @@ class AppConfig(AppConfig): def ready(self): from django.db.models.signals import post_save + from django_rbac.utils import get_ou_model post_save.connect(self.post_save_ou, sender=get_ou_model()) diff --git a/src/authentic2/manager/forms.py b/src/authentic2/manager/forms.py index f07263bbd..a6d57e4cf 100644 --- a/src/authentic2/manager/forms.py +++ b/src/authentic2/manager/forms.py @@ -16,34 +16,36 @@ import hashlib import json -import smtplib import logging +import smtplib -from django.utils.translation import ugettext_lazy as _, pgettext, ugettext from django import forms -from django.contrib.contenttypes.models import ContentType from django.contrib.auth import get_user_model +from django.contrib.contenttypes.models import ContentType +from django.core.exceptions import ValidationError from django.db.models.query import Q from django.utils import six from django.utils.text import slugify -from django.core.exceptions import ValidationError - -from authentic2.passwords import generate_password -from authentic2.utils import send_templated_mail -from authentic2.forms.fields import NewPasswordField, CheckPasswordField, ValidatedEmailField - -from django_rbac.models import Operation -from django_rbac.utils import get_ou_model, get_role_model, get_permission_model -from django_rbac.backends import DjangoRBACBackend +from django.utils.translation import pgettext, ugettext +from django.utils.translation import ugettext_lazy as _ +from authentic2 import app_settings as a2_app_settings +from authentic2.a2_rbac.utils import get_default_ou +from authentic2.forms.fields import CheckPasswordField, NewPasswordField, ValidatedEmailField from authentic2.forms.profile import BaseUserForm from authentic2.models import PasswordReset -from authentic2.utils import import_module_or_class -from authentic2.a2_rbac.utils import get_default_ou -from authentic2.utils import send_password_reset_mail, send_email_change_email -from authentic2 import app_settings as a2_app_settings +from authentic2.passwords import generate_password +from authentic2.utils import ( + import_module_or_class, + send_email_change_email, + send_password_reset_mail, + send_templated_mail, +) +from django_rbac.backends import DjangoRBACBackend +from django_rbac.models import Operation +from django_rbac.utils import get_ou_model, get_permission_model, get_role_model -from . import fields, app_settings, utils +from . import app_settings, fields, utils User = get_user_model() OU = get_ou_model() diff --git a/src/authentic2/manager/journal_event_types.py b/src/authentic2/manager/journal_event_types.py index bccb9c46e..5fc5c9d6f 100644 --- a/src/authentic2/manager/journal_event_types.py +++ b/src/authentic2/manager/journal_event_types.py @@ -17,11 +17,9 @@ from django.contrib.auth import get_user_model from django.utils.translation import ugettext_lazy as _ -from authentic2.journal_event_types import get_attributes_label, EventTypeWithService from authentic2.apps.journal.models import EventTypeDefinition from authentic2.apps.journal.utils import form_to_old_new - - +from authentic2.journal_event_types import EventTypeWithService, get_attributes_label from django_rbac.utils import get_role_model User = get_user_model() diff --git a/src/authentic2/manager/ou_views.py b/src/authentic2/manager/ou_views.py index aa65b4cba..4886349a7 100644 --- a/src/authentic2/manager/ou_views.py +++ b/src/authentic2/manager/ou_views.py @@ -16,19 +16,19 @@ import json -from django_rbac.utils import get_ou_model -from django.http import HttpResponseRedirect from django.contrib import messages from django.core.exceptions import PermissionDenied, ValidationError from django.db import transaction +from django.http import HttpResponseRedirect from django.urls import reverse from django.utils import six from django.utils.translation import ugettext as _ from django.views.generic import FormView from authentic2 import data_transfer +from django_rbac.utils import get_ou_model -from . import tables, views, forms +from . import forms, tables, views class OrganizationalUnitView(views.BaseTableView): diff --git a/src/authentic2/manager/resources.py b/src/authentic2/manager/resources.py index 6df47c39f..2cb01adc8 100644 --- a/src/authentic2/manager/resources.py +++ b/src/authentic2/manager/resources.py @@ -16,9 +16,8 @@ from django.contrib.auth import get_user_model from django.utils import six - -from import_export.resources import ModelResource from import_export.fields import Field +from import_export.resources import ModelResource from import_export.widgets import Widget from authentic2.a2_rbac.models import Role diff --git a/src/authentic2/manager/role_views.py b/src/authentic2/manager/role_views.py index 0ab50a2f4..ddd5bdb81 100644 --- a/src/authentic2/manager/role_views.py +++ b/src/authentic2/manager/role_views.py @@ -16,30 +16,29 @@ import json +from django.contrib import messages +from django.contrib.auth import get_user_model +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied, ValidationError +from django.db import transaction +from django.db.models import Count, F +from django.db.models.query import Prefetch, Q +from django.shortcuts import get_object_or_404 +from django.urls import reverse from django.utils.functional import cached_property from django.utils.translation import ugettext_lazy as _ -from django.urls import reverse from django.views.generic import FormView, TemplateView from django.views.generic.detail import SingleObjectMixin -from django.contrib import messages -from django.contrib.contenttypes.models import ContentType -from django.db import transaction -from django.db.models.query import Q, Prefetch -from django.db.models import Count, F -from django.contrib.auth import get_user_model -from django.shortcuts import get_object_or_404 - -from django_rbac.utils import get_role_model, get_permission_model, get_ou_model +from authentic2 import data_transfer, hooks +from authentic2.apps.journal.views import JournalViewWithContext from authentic2.forms.profile import modelform_factory from authentic2.utils import redirect -from authentic2 import hooks, data_transfer -from authentic2.apps.journal.views import JournalViewWithContext +from django_rbac.utils import get_ou_model, get_permission_model, get_role_model -from . import tables, views, resources, forms, app_settings -from .utils import has_show_username +from . import app_settings, forms, resources, tables, views from .journal_views import BaseJournalView +from .utils import has_show_username OU = get_ou_model() diff --git a/src/authentic2/manager/service_views.py b/src/authentic2/manager/service_views.py index 390444951..1556d5bb5 100644 --- a/src/authentic2/manager/service_views.py +++ b/src/authentic2/manager/service_views.py @@ -14,13 +14,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from django.contrib import messages from django.utils import six from django.utils.translation import ugettext as _ -from django.contrib import messages from authentic2.models import Service -from . import tables, views, forms, role_views +from . import forms, role_views, tables, views class ServicesView(views.HideOUColumnMixin, views.BaseTableView): diff --git a/src/authentic2/manager/tables.py b/src/authentic2/manager/tables.py index 7739bc8a9..06a413a0e 100644 --- a/src/authentic2/manager/tables.py +++ b/src/authentic2/manager/tables.py @@ -14,20 +14,18 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import django_tables2 as tables from django.contrib.auth import get_user_model from django.utils import html from django.utils.safestring import SafeText from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_noop - -import django_tables2 as tables from django_tables2.utils import A -from django_rbac.utils import get_role_model, get_permission_model, get_ou_model - -from authentic2.models import Service from authentic2.middleware import StoreRequestMiddleware +from authentic2.models import Service from authentic2_idp_oidc.models import OIDCAuthorization +from django_rbac.utils import get_ou_model, get_permission_model, get_role_model User = get_user_model() diff --git a/src/authentic2/manager/urls.py b/src/authentic2/manager/urls.py index 763d0e326..35fb042da 100644 --- a/src/authentic2/manager/urls.py +++ b/src/authentic2/manager/urls.py @@ -15,14 +15,15 @@ # along with this program. If not, see . from django.conf.urls import url - -from django.views.i18n import JavaScriptCatalog from django.contrib.auth.decorators import login_required from django.utils.functional import lazy -from . import views, role_views, ou_views, user_views, service_views, journal_views -from ..decorators import required +from django.views.i18n import JavaScriptCatalog + from authentic2 import utils +from ..decorators import required +from . import journal_views, ou_views, role_views, service_views, user_views, views + def manager_login_required(func): return login_required(func, login_url=lazy(utils.get_manager_login_url, str)()) diff --git a/src/authentic2/manager/user_import.py b/src/authentic2/manager/user_import.py index 82b3b31ea..8ef1f29cc 100644 --- a/src/authentic2/manager/user_import.py +++ b/src/authentic2/manager/user_import.py @@ -23,15 +23,13 @@ import logging import os import pickle import shutil -import uuid import threading - +import uuid from atomicwrites import AtomicWriter - +from django.conf import settings from django.core.files.storage import default_storage from django.db import connection -from django.conf import settings from django.utils import six from django.utils.encoding import force_text from django.utils.functional import cached_property diff --git a/src/authentic2/manager/user_views.py b/src/authentic2/manager/user_views.py index 338d0b296..f09f1334b 100644 --- a/src/authentic2/manager/user_views.py +++ b/src/authentic2/manager/user_views.py @@ -15,73 +15,72 @@ # along with this program. If not, see . import base64 -import datetime import collections +import datetime import operator -from django.db import models, transaction -from django.utils.functional import cached_property -from django.utils.translation import ugettext_lazy as _, pgettext_lazy, ugettext -from django.utils.html import format_html -from django.urls import reverse, reverse_lazy +import tablib +from django.contrib import messages +from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied from django.core.mail import EmailMultiAlternatives -from django.template import loader -from django.contrib.auth import get_user_model, REDIRECT_FIELD_NAME -from django.contrib.contenttypes.models import ContentType -from django.contrib import messages -from django.views.generic import FormView, TemplateView, DetailView -from django.views.generic.edit import BaseFormView -from django.views.generic.detail import SingleObjectMixin -from django.http import Http404, FileResponse, HttpResponseRedirect +from django.db import models, transaction +from django.http import FileResponse, Http404, HttpResponseRedirect from django.shortcuts import get_object_or_404 +from django.template import loader +from django.urls import reverse, reverse_lazy +from django.utils.functional import cached_property +from django.utils.html import format_html +from django.utils.translation import pgettext_lazy, ugettext +from django.utils.translation import ugettext_lazy as _ +from django.views.generic import DetailView, FormView, TemplateView +from django.views.generic.detail import SingleObjectMixin +from django.views.generic.edit import BaseFormView -import tablib - -from authentic2.models import Attribute, AttributeValue, PasswordReset -from authentic2.utils import send_password_reset_mail, redirect, select_next_url, make_url, switch_user -from authentic2.a2_rbac.utils import get_default_ou from authentic2 import hooks -from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient +from authentic2.a2_rbac.utils import get_default_ou from authentic2.apps.journal.views import JournalViewWithContext +from authentic2.models import Attribute, AttributeValue, PasswordReset +from authentic2.utils import make_url, redirect, select_next_url, send_password_reset_mail, switch_user +from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient +from django_rbac.utils import get_ou_model, get_role_model, get_role_parenting_model -from django_rbac.utils import get_role_model, get_role_parenting_model, get_ou_model - +from . import app_settings +from .forms import ( + ChooseUserAuthorizationsForm, + ChooseUserRoleForm, + UserAddChooseOUForm, + UserAddForm, + UserChangeEmailForm, + UserChangePasswordForm, + UserEditForm, + UserEditImportForm, + UserNewImportForm, + UserRoleSearchForm, + UserSearchForm, +) +from .journal_views import BaseJournalView +from .resources import UserResource +from .tables import OuUserRolesTable, UserAuthorizationsTable, UserRolesTable, UserTable +from .utils import get_ou_count, has_show_username from .views import ( - BaseTableView, - BaseAddView, - BaseEditView, - ActionMixin, - OtherActionsMixin, Action, - ExportMixin, - BaseSubTableView, - HideOUColumnMixin, + ActionMixin, + BaseAddView, BaseDeleteView, BaseDetailView, - TitleMixin, - PermissionMixin, - MediaMixin, + BaseEditView, + BaseSubTableView, + BaseTableView, + ExportMixin, FormNeedsRequest, + HideOUColumnMixin, + MediaMixin, + OtherActionsMixin, + PermissionMixin, + TitleMixin, ) -from .tables import UserTable, UserRolesTable, OuUserRolesTable, UserAuthorizationsTable -from .forms import ( - UserSearchForm, - UserAddForm, - UserEditForm, - UserChangePasswordForm, - ChooseUserRoleForm, - UserRoleSearchForm, - UserChangeEmailForm, - UserNewImportForm, - UserEditImportForm, - ChooseUserAuthorizationsForm, - UserAddChooseOUForm, -) -from .resources import UserResource -from .utils import get_ou_count, has_show_username -from .journal_views import BaseJournalView -from . import app_settings User = get_user_model() OU = get_ou_model() diff --git a/src/authentic2/manager/utils.py b/src/authentic2/manager/utils.py index 6bea152e9..a4aeb435a 100644 --- a/src/authentic2/manager/utils.py +++ b/src/authentic2/manager/utils.py @@ -14,9 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django_rbac.utils import get_ou_model - from authentic2.decorators import GlobalCache +from django_rbac.utils import get_ou_model OU = get_ou_model() diff --git a/src/authentic2/manager/views.py b/src/authentic2/manager/views.py index 1d2641a7d..ccfb5d559 100644 --- a/src/authentic2/manager/views.py +++ b/src/authentic2/manager/views.py @@ -15,44 +15,39 @@ # along with this program. If not, see . import base64 -import json import itertools +import json import pickle +from django.contrib.messages.views import SuccessMessageMixin from django.core import signing from django.core.exceptions import PermissionDenied, ValidationError from django.db import transaction +from django.forms import MediaDefiningClass +from django.http import Http404, HttpResponse +from django.urls import reverse, reverse_lazy +from django.utils import six +from django.utils.encoding import force_text +from django.utils.functional import cached_property +from django.utils.timezone import now +from django.utils.translation import ugettext_lazy as _ +from django.views.generic import CreateView, DeleteView, DetailView, FormView, TemplateView, UpdateView, View from django.views.generic.base import ContextMixin -from django.views.generic import FormView, UpdateView, CreateView, DeleteView, TemplateView, DetailView, View from django.views.generic.detail import SingleObjectMixin from django.views.generic.edit import FormMixin -from django.http import HttpResponse, Http404 -from django.utils.encoding import force_text -from django.utils import six -from django.utils.functional import cached_property -from django.utils.translation import ugettext_lazy as _ -from django.utils.timezone import now -from django.urls import reverse -from django.urls import reverse_lazy -from django.contrib.messages.views import SuccessMessageMixin -from django.forms import MediaDefiningClass - -from django_tables2 import SingleTableView, SingleTableMixin - from django_select2.views import AutoResponseView - +from django_tables2 import SingleTableMixin, SingleTableView from gadjo.templatetags.gadjo import xstatic +from authentic2 import hooks +from authentic2.a2_rbac.models import OrganizationalUnit as OU +from authentic2.data_transfer import ImportContext, export_site, import_site +from authentic2.decorators import json as json_view +from authentic2.forms.profile import modelform_factory +from authentic2.utils import batch_queryset, redirect from django_rbac.utils import get_ou_model -from authentic2.a2_rbac.models import OrganizationalUnit as OU -from authentic2.data_transfer import export_site, import_site, ImportContext -from authentic2.forms.profile import modelform_factory -from authentic2.utils import redirect, batch_queryset -from authentic2.decorators import json as json_view -from authentic2 import hooks - -from . import app_settings, utils, forms, widgets +from . import app_settings, forms, utils, widgets class MediaMixinBase(MediaDefiningClass, FormMixin): diff --git a/src/authentic2/manager/widgets.py b/src/authentic2/manager/widgets.py index 2ef63e709..319441b6f 100644 --- a/src/authentic2/manager/widgets.py +++ b/src/authentic2/manager/widgets.py @@ -18,17 +18,15 @@ import base64 import operator import pickle -from django_select2.forms import ModelSelect2Widget, ModelSelect2MultipleWidget - from django.contrib.auth import get_user_model from django.core import signing from django.utils import six from django.utils.encoding import force_text - -from django_rbac.utils import get_role_model, get_ou_model +from django_select2.forms import ModelSelect2MultipleWidget, ModelSelect2Widget from authentic2.models import Service from authentic2_idp_oidc.models import OIDCAuthorization +from django_rbac.utils import get_ou_model, get_role_model from . import utils diff --git a/src/authentic2/managers.py b/src/authentic2/managers.py index fed9280c1..2a6b98219 100644 --- a/src/authentic2/managers.py +++ b/src/authentic2/managers.py @@ -14,19 +14,18 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from datetime import timedelta import logging +from datetime import timedelta - -from django.db import models -from django.db.models.query import QuerySet -from django.utils.timezone import now from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.contrib.postgres.search import SearchVector +from django.db import models +from django.db.models.query import QuerySet +from django.utils.timezone import now +from model_utils import managers from django_rbac.utils import get_ou_model -from model_utils import managers logger = logging.getLogger(__name__) diff --git a/src/authentic2/middleware.py b/src/authentic2/middleware.py index d1e2c0e4a..8912b5d1c 100644 --- a/src/authentic2/middleware.py +++ b/src/authentic2/middleware.py @@ -21,15 +21,15 @@ try: except ImportError: threading = None +from django import http from django.conf import settings from django.contrib import messages from django.utils.deprecation import MiddlewareMixin from django.utils.functional import SimpleLazyObject -from django.utils.translation import ugettext as _ from django.utils.six.moves.urllib import parse as urlparse -from django import http +from django.utils.translation import ugettext as _ -from . import app_settings, utils, plugins +from . import app_settings, plugins, utils from .utils.service import get_service_from_request, get_service_from_session @@ -107,6 +107,7 @@ class ViewRestrictionMiddleware(MiddlewareMixin): def check_view_restrictions(self, request): '''Check if a restriction on accessible views must be applied''' from django.db.models import Model + from .models import PasswordReset user = request.user diff --git a/src/authentic2/migrations/0001_initial.py b/src/authentic2/migrations/0001_initial.py index 69254de65..d47d93e37 100644 --- a/src/authentic2/migrations/0001_initial.py +++ b/src/authentic2/migrations/0001_initial.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0002_auto_20150320_1418.py b/src/authentic2/migrations/0002_auto_20150320_1418.py index 008998a68..0dc730d36 100644 --- a/src/authentic2/migrations/0002_auto_20150320_1418.py +++ b/src/authentic2/migrations/0002_auto_20150320_1418.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0003_auto_20150409_1840.py b/src/authentic2/migrations/0003_auto_20150409_1840.py index d8a52fe40..74db976a8 100644 --- a/src/authentic2/migrations/0003_auto_20150409_1840.py +++ b/src/authentic2/migrations/0003_auto_20150409_1840.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0004_service.py b/src/authentic2/migrations/0004_service.py index d5c68454a..b48219d3f 100644 --- a/src/authentic2/migrations/0004_service.py +++ b/src/authentic2/migrations/0004_service.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0005_service_ou.py b/src/authentic2/migrations/0005_service_ou.py index dd2134e04..8aa6770c9 100644 --- a/src/authentic2/migrations/0005_service_ou.py +++ b/src/authentic2/migrations/0005_service_ou.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0006_conditional_slug_index.py b/src/authentic2/migrations/0006_conditional_slug_index.py index 12be4e26d..7b8dbe24f 100644 --- a/src/authentic2/migrations/0006_conditional_slug_index.py +++ b/src/authentic2/migrations/0006_conditional_slug_index.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations + from authentic2.migrations import CreatePartialIndexes diff --git a/src/authentic2/migrations/0007_auto_20150523_0028.py b/src/authentic2/migrations/0007_auto_20150523_0028.py index 5c08a7922..76c1698ee 100644 --- a/src/authentic2/migrations/0007_auto_20150523_0028.py +++ b/src/authentic2/migrations/0007_auto_20150523_0028.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0008_auto_20160204_1415.py b/src/authentic2/migrations/0008_auto_20160204_1415.py index a606ae1e5..0be06d7b6 100644 --- a/src/authentic2/migrations/0008_auto_20160204_1415.py +++ b/src/authentic2/migrations/0008_auto_20160204_1415.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0009_auto_20160211_2247.py b/src/authentic2/migrations/0009_auto_20160211_2247.py index af4abb26a..b59fe8e65 100644 --- a/src/authentic2/migrations/0009_auto_20160211_2247.py +++ b/src/authentic2/migrations/0009_auto_20160211_2247.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def deduplicate_attribute_values(apps, schema_editor): diff --git a/src/authentic2/migrations/0010_attributevalue_multiple.py b/src/authentic2/migrations/0010_attributevalue_multiple.py index b7121bdd0..39f7a5ffa 100644 --- a/src/authentic2/migrations/0010_attributevalue_multiple.py +++ b/src/authentic2/migrations/0010_attributevalue_multiple.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0011_auto_20160211_2253.py b/src/authentic2/migrations/0011_auto_20160211_2253.py index 1bd1a3417..5f8729c86 100644 --- a/src/authentic2/migrations/0011_auto_20160211_2253.py +++ b/src/authentic2/migrations/0011_auto_20160211_2253.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def fill_attribute_value_multiple(apps, schema_editor): diff --git a/src/authentic2/migrations/0012_auto_20160211_2255.py b/src/authentic2/migrations/0012_auto_20160211_2255.py index e747e8930..ec4ca2963 100644 --- a/src/authentic2/migrations/0012_auto_20160211_2255.py +++ b/src/authentic2/migrations/0012_auto_20160211_2255.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals import django -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0013_auto_20160211_2258.py b/src/authentic2/migrations/0013_auto_20160211_2258.py index 5607e2d3b..093c719ab 100644 --- a/src/authentic2/migrations/0013_auto_20160211_2258.py +++ b/src/authentic2/migrations/0013_auto_20160211_2258.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models from authentic2.migrations import CreatePartialIndexes diff --git a/src/authentic2/migrations/0015_auto_20160621_1711.py b/src/authentic2/migrations/0015_auto_20160621_1711.py index f61796253..542889c9c 100644 --- a/src/authentic2/migrations/0015_auto_20160621_1711.py +++ b/src/authentic2/migrations/0015_auto_20160621_1711.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0018_auto_20170524_0842.py b/src/authentic2/migrations/0018_auto_20170524_0842.py index 56f33eb7a..83caeb658 100644 --- a/src/authentic2/migrations/0018_auto_20170524_0842.py +++ b/src/authentic2/migrations/0018_auto_20170524_0842.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0021_attribute_order.py b/src/authentic2/migrations/0021_attribute_order.py index 48c2a9453..f05264c71 100644 --- a/src/authentic2/migrations/0021_attribute_order.py +++ b/src/authentic2/migrations/0021_attribute_order.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models import django.db.models.manager +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0025_auto_20191009_1047.py b/src/authentic2/migrations/0025_auto_20191009_1047.py index 1937bc3a2..668c86dce 100644 --- a/src/authentic2/migrations/0025_auto_20191009_1047.py +++ b/src/authentic2/migrations/0025_auto_20191009_1047.py @@ -2,9 +2,9 @@ # Generated by Django 1.11.20 on 2019-10-09 08:47 from __future__ import unicode_literals +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0026_token.py b/src/authentic2/migrations/0026_token.py index 66ca9304e..ec81872b7 100644 --- a/src/authentic2/migrations/0026_token.py +++ b/src/authentic2/migrations/0026_token.py @@ -2,9 +2,10 @@ # Generated by Django 1.11.20 on 2020-02-11 10:27 from __future__ import unicode_literals +import uuid + import django.contrib.postgres.fields.jsonb from django.db import migrations, models -import uuid class Migration(migrations.Migration): diff --git a/src/authentic2/migrations/0030_clean_admin_tools_tables.py b/src/authentic2/migrations/0030_clean_admin_tools_tables.py index 3d73374d9..3eb24318e 100644 --- a/src/authentic2/migrations/0030_clean_admin_tools_tables.py +++ b/src/authentic2/migrations/0030_clean_admin_tools_tables.py @@ -1,6 +1,7 @@ -from django.db import migrations import logging +from django.db import migrations + def noop(apps, schema_editor): pass diff --git a/src/authentic2/models.py b/src/authentic2/models.py index 70dbf0b46..dd0340fe9 100644 --- a/src/authentic2/models.py +++ b/src/authentic2/models.py @@ -19,23 +19,22 @@ import time import uuid import django -from django.utils.http import urlquote from django.conf import settings +from django.contrib.contenttypes.models import ContentType +from django.contrib.postgres.fields import jsonb +from django.contrib.postgres.indexes import GinIndex +from django.contrib.postgres.search import SearchVectorField +from django.core.exceptions import ValidationError from django.db import models, transaction from django.db.models.query import Q from django.utils import six, timezone -from django.utils.translation import ugettext_lazy as _ +from django.utils.http import urlquote from django.utils.six.moves.urllib import parse as urlparse -from django.core.exceptions import ValidationError -from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import jsonb -from django.contrib.postgres.search import SearchVectorField -from django.contrib.postgres.indexes import GinIndex - +from django.utils.translation import ugettext_lazy as _ from model_utils.managers import QueryManager from authentic2.a2_rbac.models import Role -from authentic2.crypto import base64url_encode, base64url_decode +from authentic2.crypto import base64url_decode, base64url_encode from django_rbac.utils import get_role_model_name try: @@ -43,9 +42,8 @@ try: except ImportError: from django.contrib.contenttypes.generic import GenericForeignKey -from . import managers - # install our natural_key implementation +from . import managers from . import natural_key as unused_natural_key # noqa: F401 from .utils import ServiceAccessDenied @@ -180,6 +178,7 @@ class Attribute(models.Model): def get_drf_field(self, **kwargs): from rest_framework import serializers + from authentic2.attribute_kinds import DateRestField kind = self.get_kind() diff --git a/src/authentic2/natural_key.py b/src/authentic2/natural_key.py index 6024c6866..05af722ca 100644 --- a/src/authentic2/natural_key.py +++ b/src/authentic2/natural_key.py @@ -14,10 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.db import models - -from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey +from django.contrib.contenttypes.models import ContentType +from django.db import models def get_natural_keys(model): diff --git a/src/authentic2/nonce/migrations/0001_initial.py b/src/authentic2/nonce/migrations/0001_initial.py index 37539773a..fbd2e936e 100644 --- a/src/authentic2/nonce/migrations/0001_initial.py +++ b/src/authentic2/nonce/migrations/0001_initial.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/nonce/utils.py b/src/authentic2/nonce/utils.py index 89d5cb7ec..e5a684150 100644 --- a/src/authentic2/nonce/utils.py +++ b/src/authentic2/nonce/utils.py @@ -14,12 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import os.path import datetime as dt -from calendar import timegm -import tempfile -import glob import errno +import glob +import os.path +import tempfile +from calendar import timegm from django.conf import settings diff --git a/src/authentic2/passwords.py b/src/authentic2/passwords.py index 0bc2bfe51..804131b6b 100644 --- a/src/authentic2/passwords.py +++ b/src/authentic2/passwords.py @@ -14,17 +14,16 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import string +import abc import random import re -import abc +import string -from django.utils.translation import ugettext as _ -from django.utils.module_loading import import_string -from django.utils.functional import lazy -from django.utils import six from django.core.exceptions import ValidationError - +from django.utils import six +from django.utils.functional import lazy +from django.utils.module_loading import import_string +from django.utils.translation import ugettext as _ from . import app_settings diff --git a/src/authentic2/plugins.py b/src/authentic2/plugins.py index 3b31acfe2..048eb8297 100644 --- a/src/authentic2/plugins.py +++ b/src/authentic2/plugins.py @@ -19,13 +19,12 @@ Propose helper methods to load urls from plugins or modify INSTALLED_APPS """ -import pkg_resources import logging +import pkg_resources from django.apps import apps from django.conf.urls import include, url - logger = logging.getLogger(__name__) diff --git a/src/authentic2/saml/admin.py b/src/authentic2/saml/admin.py index 23c45af6e..fcbabc678 100644 --- a/src/authentic2/saml/admin.py +++ b/src/authentic2/saml/admin.py @@ -16,33 +16,31 @@ import logging -from django.contrib import admin +from django import forms +from django.conf import settings +from django.conf.urls import url +from django.contrib import admin, messages +from django.core.exceptions import ValidationError +from django.forms import ModelForm from django.utils import six from django.utils.translation import ugettext as _ -from django.conf.urls import url -from django.conf import settings -from django.forms import ModelForm -from django import forms -from django.contrib import messages -from django.core.exceptions import ValidationError try: from django.contrib.contenttypes.admin import GenericTabularInline except ImportError: from django.contrib.contenttypes.generic import GenericTabularInline +from authentic2.attributes_ng.engine import get_service_attributes from authentic2.saml.models import ( + KeyValue, + LibertyFederation, LibertyProvider, LibertyServiceProvider, - SPOptionsIdPPolicy, - LibertyFederation, - KeyValue, LibertySession, SAMLAttribute, + SPOptionsIdPPolicy, ) -from authentic2.attributes_ng.engine import get_service_attributes - from . import admin_views logger = logging.getLogger(__name__) diff --git a/src/authentic2/saml/admin_views.py b/src/authentic2/saml/admin_views.py index 0bc3ec632..d1d4b5aef 100644 --- a/src/authentic2/saml/admin_views.py +++ b/src/authentic2/saml/admin_views.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.views.generic import FormView from django.urls import reverse +from django.views.generic import FormView from .forms import AddLibertyProviderFromUrlForm diff --git a/src/authentic2/saml/common.py b/src/authentic2/saml/common.py index ec4f907e8..84cc9dde9 100644 --- a/src/authentic2/saml/common.py +++ b/src/authentic2/saml/common.py @@ -14,35 +14,33 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import os.path -import logging -import re import datetime +import logging +import os.path +import re import requests - -from authentic2.compat_lasso import lasso from django.conf import settings -from django.http import HttpResponseRedirect, Http404, HttpResponse +from django.core.exceptions import ValidationError +from django.http import Http404, HttpResponse, HttpResponseRedirect from django.shortcuts import render +from django.urls import reverse from django.utils import six from django.utils.encoding import force_text from django.utils.six.moves.urllib import parse as urlparse -from django.core.exceptions import ValidationError -from django.urls import reverse +from authentic2.compat_lasso import lasso +from authentic2.decorators import RequestCache +from authentic2.http_utils import get_url +from authentic2.idp.saml import app_settings +from authentic2.saml import models, saml2utils from authentic2.saml.models import ( LibertyFederation, LibertyProvider, LibertyServiceProvider, SPOptionsIdPPolicy, ) -from authentic2.saml import models -from authentic2.saml import saml2utils -from authentic2.http_utils import get_url -from authentic2.decorators import RequestCache -from authentic2.idp.saml import app_settings from .. import nonce AUTHENTIC_STATUS_CODE_NS = "http://authentic.entrouvert.org/status_code/" diff --git a/src/authentic2/saml/fields.py b/src/authentic2/saml/fields.py index 43b7a2a14..5897a8732 100644 --- a/src/authentic2/saml/fields.py +++ b/src/authentic2/saml/fields.py @@ -23,13 +23,13 @@ except ImportError: import django from django import forms -from django.db import models -from django.core.exceptions import ValidationError -from django.utils import six -from django.utils.text import capfirst -from django.utils.encoding import force_bytes, force_text from django.contrib.humanize.templatetags.humanize import apnumber +from django.core.exceptions import ValidationError +from django.db import models from django.template.defaultfilters import pluralize +from django.utils import six +from django.utils.encoding import force_bytes, force_text +from django.utils.text import capfirst def loads(value): diff --git a/src/authentic2/saml/forms.py b/src/authentic2/saml/forms.py index 5ffb10427..42d2d4bdf 100644 --- a/src/authentic2/saml/forms.py +++ b/src/authentic2/saml/forms.py @@ -17,19 +17,16 @@ import xml.etree.ElementTree as ET import requests - -from authentic2.compat_lasso import lasso - from django import forms from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ -from .models import LibertyProvider, LibertyServiceProvider - from authentic2.a2_rbac.utils import get_default_ou - +from authentic2.compat_lasso import lasso from django_rbac.utils import get_ou_model +from .models import LibertyProvider, LibertyServiceProvider + class AddLibertyProviderFromUrlForm(forms.Form): name = forms.CharField(max_length=140, label=_('Name')) diff --git a/src/authentic2/saml/lasso_helper.py b/src/authentic2/saml/lasso_helper.py index 1d43dd6ad..edbf40b04 100644 --- a/src/authentic2/saml/lasso_helper.py +++ b/src/authentic2/saml/lasso_helper.py @@ -16,7 +16,6 @@ import xml.etree.ElementTree as etree - LASSO_NS = 'http://www.entrouvert.org/namespaces/lasso/0.0' SAML_ASSERTION_NS = 'urn:oasis:names:tc:SAML:2.0:assertion' diff --git a/src/authentic2/saml/management/commands/sync-metadata.py b/src/authentic2/saml/management/commands/sync-metadata.py index e70569e27..000c821e2 100644 --- a/src/authentic2/saml/management/commands/sync-metadata.py +++ b/src/authentic2/saml/management/commands/sync-metadata.py @@ -16,29 +16,29 @@ from __future__ import print_function -import sys -import xml.etree.ElementTree as etree import os -import requests +import sys import warnings +import xml.etree.ElementTree as etree +import requests +from django.contrib.contenttypes.models import ContentType from django.core.management.base import BaseCommand, CommandError from django.db.transaction import atomic from django.template.defaultfilters import slugify from django.utils import six from django.utils.translation import gettext as _ -from django.contrib.contenttypes.models import ContentType from authentic2.compat_lasso import lasso +from authentic2.saml.models import LibertyProvider, LibertyServiceProvider, SAMLAttribute, SPOptionsIdPPolicy from authentic2.saml.shibboleth.afp_parser import parse_attribute_filters_file -from authentic2.saml.models import LibertyProvider, SAMLAttribute, LibertyServiceProvider, SPOptionsIdPPolicy from .mapping import ( + get_def_name_from_alias, get_def_name_from_oid, + get_definition_from_alias, get_definition_from_oid, get_full_definition, - get_definition_from_alias, - get_def_name_from_alias, ) SAML2_METADATA_UI_HREF = 'urn:oasis:names:tc:SAML:metadata:ui' diff --git a/src/authentic2/saml/managers.py b/src/authentic2/saml/managers.py index 7eb687b85..1b2133951 100644 --- a/src/authentic2/saml/managers.py +++ b/src/authentic2/saml/managers.py @@ -17,19 +17,17 @@ import base64 import binascii import datetime - +from importlib import import_module from django.conf import settings +from django.contrib.contenttypes.models import ContentType from django.db import models from django.db.models.query import QuerySet from django.dispatch import Signal from django.utils.timezone import now -from importlib import import_module -from django.contrib.contenttypes.models import ContentType - +from ..managers import GenericManager, GetBySlugQuerySet from . import lasso_helper -from ..managers import GetBySlugQuerySet, GenericManager federation_delete = Signal() diff --git a/src/authentic2/saml/migrations/0001_initial.py b/src/authentic2/saml/migrations/0001_initial.py index fafa87bd5..215a845a7 100644 --- a/src/authentic2/saml/migrations/0001_initial.py +++ b/src/authentic2/saml/migrations/0001_initial.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations -import authentic2.saml.models import django.db.models.deletion +from django.db import migrations, models + import authentic2.saml.fields +import authentic2.saml.models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0002_auto_20150320_1245.py b/src/authentic2/saml/migrations/0002_auto_20150320_1245.py index 6253c70df..c12c3565d 100644 --- a/src/authentic2/saml/migrations/0002_auto_20150320_1245.py +++ b/src/authentic2/saml/migrations/0002_auto_20150320_1245.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0003_merge.py b/src/authentic2/saml/migrations/0003_merge.py index a33adf29e..e4edc3fe5 100644 --- a/src/authentic2/saml/migrations/0003_merge.py +++ b/src/authentic2/saml/migrations/0003_merge.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0004_auto_20150410_1438.py b/src/authentic2/saml/migrations/0004_auto_20150410_1438.py index 8e5fe7d9b..93fe7b490 100644 --- a/src/authentic2/saml/migrations/0004_auto_20150410_1438.py +++ b/src/authentic2/saml/migrations/0004_auto_20150410_1438.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0005_make_liberty_provider_inherit_from_service.py b/src/authentic2/saml/migrations/0005_make_liberty_provider_inherit_from_service.py index e681fb699..6cd39b494 100644 --- a/src/authentic2/saml/migrations/0005_make_liberty_provider_inherit_from_service.py +++ b/src/authentic2/saml/migrations/0005_make_liberty_provider_inherit_from_service.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0006_restore_foreign_keys.py b/src/authentic2/saml/migrations/0006_restore_foreign_keys.py index 15853e7fc..b624b12e1 100644 --- a/src/authentic2/saml/migrations/0006_restore_foreign_keys.py +++ b/src/authentic2/saml/migrations/0006_restore_foreign_keys.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def create_services(apps, schema_editor): diff --git a/src/authentic2/saml/migrations/0007_copy_service_ptr_id_to_old_id.py b/src/authentic2/saml/migrations/0007_copy_service_ptr_id_to_old_id.py index 0680e38b7..88bf3b386 100644 --- a/src/authentic2/saml/migrations/0007_copy_service_ptr_id_to_old_id.py +++ b/src/authentic2/saml/migrations/0007_copy_service_ptr_id_to_old_id.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0008_alter_foreign_keys.py b/src/authentic2/saml/migrations/0008_alter_foreign_keys.py index ebb544a0a..1906cbdee 100644 --- a/src/authentic2/saml/migrations/0008_alter_foreign_keys.py +++ b/src/authentic2/saml/migrations/0008_alter_foreign_keys.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def alter_foreign_keys(apps, schema_editor): diff --git a/src/authentic2/saml/migrations/0009_auto.py b/src/authentic2/saml/migrations/0009_auto.py index a17548c04..df987d488 100644 --- a/src/authentic2/saml/migrations/0009_auto.py +++ b/src/authentic2/saml/migrations/0009_auto.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0010_auto.py b/src/authentic2/saml/migrations/0010_auto.py index a5949893e..88e9b2d05 100644 --- a/src/authentic2/saml/migrations/0010_auto.py +++ b/src/authentic2/saml/migrations/0010_auto.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def noop(apps, schema_editor): diff --git a/src/authentic2/saml/migrations/0011_auto.py b/src/authentic2/saml/migrations/0011_auto.py index 4d43ded93..6220a394b 100644 --- a/src/authentic2/saml/migrations/0011_auto.py +++ b/src/authentic2/saml/migrations/0011_auto.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0012_auto_20150526_2239.py b/src/authentic2/saml/migrations/0012_auto_20150526_2239.py index 07dde7060..759783571 100644 --- a/src/authentic2/saml/migrations/0012_auto_20150526_2239.py +++ b/src/authentic2/saml/migrations/0012_auto_20150526_2239.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0013_auto_20150617_1004.py b/src/authentic2/saml/migrations/0013_auto_20150617_1004.py index 5ecfa6db5..4af648c9f 100644 --- a/src/authentic2/saml/migrations/0013_auto_20150617_1004.py +++ b/src/authentic2/saml/migrations/0013_auto_20150617_1004.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def noop(apps, schema_editor): diff --git a/src/authentic2/saml/migrations/0014_auto_20150617_1216.py b/src/authentic2/saml/migrations/0014_auto_20150617_1216.py index 93c1f3f9c..00a09508f 100644 --- a/src/authentic2/saml/migrations/0014_auto_20150617_1216.py +++ b/src/authentic2/saml/migrations/0014_auto_20150617_1216.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/migrations/0015_auto_20150915_2032.py b/src/authentic2/saml/migrations/0015_auto_20150915_2032.py index e5682ff04..ec6dd0895 100644 --- a/src/authentic2/saml/migrations/0015_auto_20150915_2032.py +++ b/src/authentic2/saml/migrations/0015_auto_20150915_2032.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models + import authentic2.saml.fields diff --git a/src/authentic2/saml/migrations/0016_auto_20150915_2041.py b/src/authentic2/saml/migrations/0016_auto_20150915_2041.py index 0f75b8bf2..0ca3e7ed9 100644 --- a/src/authentic2/saml/migrations/0016_auto_20150915_2041.py +++ b/src/authentic2/saml/migrations/0016_auto_20150915_2041.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2/saml/models.py b/src/authentic2/saml/models.py index 4a465c5b1..4e2e80e1f 100644 --- a/src/authentic2/saml/models.py +++ b/src/authentic2/saml/models.py @@ -15,25 +15,22 @@ # along with this program. If not, see . import collections - -import xml.etree.ElementTree as etree import hashlib +import xml.etree.ElementTree as etree import requests -from authentic2.compat_lasso import lasso -from authentic2.utils import normalize_attribute_values - +from django.conf import settings +from django.contrib.contenttypes.models import ContentType +from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db import models from django.db.models import Q from django.db.models.query import QuerySet -from django.conf import settings -from django.core.exceptions import ValidationError from django.utils import six -from django.utils.encoding import force_str -from django.utils.encoding import force_text +from django.utils.encoding import force_str, force_text from django.utils.translation import ugettext_lazy as _ -from django.core.exceptions import ObjectDoesNotExist -from django.contrib.contenttypes.models import ContentType + +from authentic2.compat_lasso import lasso +from authentic2.utils import normalize_attribute_values try: from django.contrib.contenttypes.fields import GenericForeignKey @@ -44,11 +41,11 @@ try: except ImportError: from django.contrib.contenttypes.generic import GenericRelation -from authentic2.saml.fields import PickledObjectField, MultiSelectField +from authentic2.saml.fields import MultiSelectField, PickledObjectField -from . import app_settings, managers from .. import managers as a2_managers from ..models import Service +from . import app_settings, managers def metadata_validator(meta): diff --git a/src/authentic2/saml/saml2utils.py b/src/authentic2/saml/saml2utils.py index aad5c77bb..156b47afb 100644 --- a/src/authentic2/saml/saml2utils.py +++ b/src/authentic2/saml/saml2utils.py @@ -16,19 +16,20 @@ from __future__ import print_function -import xml.etree.ElementTree as etree -import collections -from authentic2.compat_lasso import lasso -from authentic2.saml import x509utils import base64 import binascii -import re +import collections import datetime +import re import time +import xml.etree.ElementTree as etree from django.utils import six from django.utils.encoding import force_text +from authentic2.compat_lasso import lasso +from authentic2.saml import x509utils + def filter_attribute_private_key(message): if isinstance(message, six.string_types): diff --git a/src/authentic2/saml/x509utils.py b/src/authentic2/saml/x509utils.py index a15508c35..89c14e45a 100644 --- a/src/authentic2/saml/x509utils.py +++ b/src/authentic2/saml/x509utils.py @@ -16,9 +16,10 @@ import base64 import binascii -import tempfile import os import subprocess +import tempfile + import six _openssl = 'openssl' diff --git a/src/authentic2/serializers.py b/src/authentic2/serializers.py index a0319888b..dd376242c 100644 --- a/src/authentic2/serializers.py +++ b/src/authentic2/serializers.py @@ -17,13 +17,13 @@ import json import sys -from django.utils import six -from django.core.serializers.json import Serializer as JSONSerializer -from django.core.serializers.python import _get_model -from django.core.serializers.base import DeserializationError from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType +from django.core.serializers.base import DeserializationError +from django.core.serializers.json import Serializer as JSONSerializer +from django.core.serializers.python import _get_model from django.db import DEFAULT_DB_ALIAS +from django.utils import six class Serializer(JSONSerializer): diff --git a/src/authentic2/settings.py b/src/authentic2/settings.py index d706b081e..167fe2084 100644 --- a/src/authentic2/settings.py +++ b/src/authentic2/settings.py @@ -16,14 +16,13 @@ import logging import logging.config +import os # Load default from Django from django.conf import global_settings -import os - - from gadjo.templatetags.gadjo import xstatic -from . import plugins, logger + +from . import logger, plugins # debian/debian_config.py::extract_settings_from_environ expects CACHES to be in its NAMESPACE CACHES = global_settings.CACHES diff --git a/src/authentic2/urls.py b/src/authentic2/urls.py index aa8f3a919..bb4764a7c 100644 --- a/src/authentic2/urls.py +++ b/src/authentic2/urls.py @@ -14,26 +14,26 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.conf.urls import url, include from django.conf import settings +from django.conf.urls import include, url from django.contrib import admin -from django.contrib.auth.decorators import login_required from django.contrib.auth import views as dj_auth_views +from django.contrib.auth.decorators import login_required from django.contrib.staticfiles.views import serve from django.utils.translation import ugettext_lazy as _ +from django.views.decorators.clickjacking import xframe_options_deny from django.views.generic.base import TemplateView from django.views.static import serve as media_serve -from django.views.decorators.clickjacking import xframe_options_deny -from . import plugins, views -from authentic2.decorators import setting_enabled, required, lasso_required +import authentic2.idp.saml.app_settings import authentic2_auth_fc.urls import authentic2_auth_oidc.urls import authentic2_auth_saml.urls import authentic2_idp_cas.app_settings import authentic2_idp_oidc.urls -import authentic2.idp.saml.app_settings +from authentic2.decorators import lasso_required, required, setting_enabled +from . import plugins, views admin.autodiscover() diff --git a/src/authentic2/user_login_failure.py b/src/authentic2/user_login_failure.py index 974006ba6..53f7e35d0 100644 --- a/src/authentic2/user_login_failure.py +++ b/src/authentic2/user_login_failure.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import logging import hashlib +import logging from django.core.cache import cache from django.utils.encoding import smart_bytes diff --git a/src/authentic2/utils/__init__.py b/src/authentic2/utils/__init__.py index 754605e36..4d49c292e 100644 --- a/src/authentic2/utils/__init__.py +++ b/src/authentic2/utils/__init__.py @@ -14,49 +14,43 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import inspect -import random -import time -import logging -import uuid -import datetime import copy import ctypes - +import datetime +import inspect +import logging +import random +import time +import uuid from functools import wraps -from itertools import islice, chain, count - from importlib import import_module +from itertools import chain, count, islice import django.apps -from django.conf import settings -from django.core.mail import EmailMessage -from django.http import HttpResponseRedirect, HttpResponse -from django.core.exceptions import ImproperlyConfigured -from django.http.request import QueryDict -from django.contrib.auth import ( - REDIRECT_FIELD_NAME, - login as auth_login, - authenticate as dj_authenticate, - get_user_model, -) from django import forms -from django.forms.utils import ErrorList, to_current_timezone -from django.utils import timezone -from django.utils import html, six -from django.utils.translation import ugettext as _, ungettext -from django.utils.six.moves.urllib import parse as urlparse -from django.shortcuts import resolve_url -from django.template.loader import render_to_string, TemplateDoesNotExist, select_template -from django.template.context import make_context -from django.core.mail import send_mail +from django.conf import settings +from django.contrib.auth import REDIRECT_FIELD_NAME +from django.contrib.auth import authenticate as dj_authenticate +from django.contrib.auth import get_user_model +from django.contrib.auth import login as auth_login from django.core import signing from django.core.cache import cache +from django.core.exceptions import ImproperlyConfigured +from django.core.mail import EmailMessage, send_mail +from django.forms.utils import ErrorList, to_current_timezone +from django.http import HttpResponse, HttpResponseRedirect +from django.http.request import QueryDict +from django.shortcuts import render, resolve_url +from django.template.context import make_context +from django.template.loader import TemplateDoesNotExist, render_to_string, select_template +from django.urls import reverse +from django.utils import html, six, timezone +from django.utils.encoding import force_bytes, iri_to_uri, uri_to_iri from django.utils.formats import localize from django.utils.http import urlsafe_base64_encode -from django.utils.encoding import iri_to_uri, force_bytes, uri_to_iri -from django.urls import reverse -from django.shortcuts import render +from django.utils.six.moves.urllib import parse as urlparse +from django.utils.translation import ugettext as _ +from django.utils.translation import ungettext try: from django.core.exceptions import FieldDoesNotExist @@ -66,7 +60,7 @@ except ImportError: from authentic2.saml.saml2utils import filter_attribute_private_key, filter_element_private_key -from .. import plugins, app_settings, constants, crypto +from .. import app_settings, constants, crypto, plugins from .service import set_service_ref @@ -579,6 +573,7 @@ def check_referer(request, skip_post=True): def check_session_key(session_key): '''Check that a session exists for a given session_key.''' from importlib import import_module + from django.conf import settings SessionStore = import_module(settings.SESSION_ENGINE).SessionStore @@ -590,9 +585,11 @@ def check_session_key(session_key): def get_user_from_session_key(session_key): '''Get the user logged in an active session''' from importlib import import_module + from django.conf import settings - from django.contrib.auth import load_backend, SESSION_KEY, BACKEND_SESSION_KEY + from django.contrib.auth import BACKEND_SESSION_KEY, SESSION_KEY, load_backend from django.contrib.auth.models import AnonymousUser + from authentic2.compat.misc import signature_parameters SessionStore = import_module(settings.SESSION_ENGINE).SessionStore @@ -912,9 +909,10 @@ def send_password_reset_mail( sign_next_url=True, **kwargs, ): - from .. import middleware from authentic2.journal import journal + from .. import middleware + if not user.email: raise ValueError('user must have an email') logger = logging.getLogger(__name__) diff --git a/src/authentic2/utils/evaluate.py b/src/authentic2/utils/evaluate.py index 6ea291dcc..7abe7a4ef 100644 --- a/src/authentic2/utils/evaluate.py +++ b/src/authentic2/utils/evaluate.py @@ -22,12 +22,12 @@ try: from functools import lru_cache except ImportError: from django.utils.lru_cache import lru_cache -from django.utils.translation import ugettext as _ -from django.utils import six - import ast +from django.utils import six +from django.utils.translation import ugettext as _ + class HTTPHeaders: def __init__(self, request): diff --git a/src/authentic2/utils/lazy.py b/src/authentic2/utils/lazy.py index 57ad39423..f57819c98 100644 --- a/src/authentic2/utils/lazy.py +++ b/src/authentic2/utils/lazy.py @@ -16,11 +16,10 @@ from __future__ import unicode_literals -from django.utils.encoding import force_text from django.utils import six -from django.utils.text import format_lazy - +from django.utils.encoding import force_text from django.utils.functional import keep_lazy +from django.utils.text import format_lazy def lazy_join(join, args): diff --git a/src/authentic2/utils/lookups.py b/src/authentic2/utils/lookups.py index a382578a4..27203cdfa 100644 --- a/src/authentic2/utils/lookups.py +++ b/src/authentic2/utils/lookups.py @@ -1,6 +1,7 @@ from django.contrib.postgres.lookups import Unaccent as PGUnaccent from django.db.models import Func -from django.db.models.functions import Concat, ConcatPair as DjConcatPair +from django.db.models.functions import Concat +from django.db.models.functions import ConcatPair as DjConcatPair class Unaccent(PGUnaccent): diff --git a/src/authentic2/utils/switch_user.py b/src/authentic2/utils/switch_user.py index 252e82d2a..ad735dab3 100644 --- a/src/authentic2/utils/switch_user.py +++ b/src/authentic2/utils/switch_user.py @@ -14,9 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from authentic2.models import Token from authentic2.custom_user.models import User - +from authentic2.models import Token from authentic2.utils import make_url diff --git a/src/authentic2/utils/template.py b/src/authentic2/utils/template.py index 5492ca323..dcfdbc4f9 100644 --- a/src/authentic2/utils/template.py +++ b/src/authentic2/utils/template.py @@ -14,9 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.template import VariableDoesNotExist -from django.template import engines -from django.template import TemplateSyntaxError +from django.template import TemplateSyntaxError, VariableDoesNotExist, engines from django.utils.encoding import force_str from django.utils.translation import ugettext_lazy as _ diff --git a/src/authentic2/validators.py b/src/authentic2/validators.py index ac9a2dd85..3ccbc9e67 100644 --- a/src/authentic2/validators.py +++ b/src/authentic2/validators.py @@ -19,13 +19,13 @@ from __future__ import unicode_literals import re import smtplib +import dns.exception +import dns.resolver +from django.core.exceptions import ValidationError +from django.core.validators import EmailValidator as DjangoEmailValidator +from django.core.validators import RegexValidator from django.utils.deconstruct import deconstructible from django.utils.translation import ugettext_lazy as _ -from django.core.exceptions import ValidationError -from django.core.validators import RegexValidator, EmailValidator as DjangoEmailValidator - -import dns.resolver -import dns.exception from . import app_settings diff --git a/src/authentic2/views.py b/src/authentic2/views.py index 6ac544251..18bc94c5d 100644 --- a/src/authentic2/views.py +++ b/src/authentic2/views.py @@ -15,50 +15,54 @@ # along with this program. If not, see . import collections -from email.utils import parseaddr import logging import re +from email.utils import parseaddr -from ratelimit.utils import is_ratelimited - -from django.conf import settings -from django.shortcuts import render, get_object_or_404 -from django.template.loader import render_to_string -from django.views.generic.edit import UpdateView, FormView -from django.views.generic import TemplateView -from django.views.generic.base import View from django import shortcuts +from django.conf import settings +from django.contrib import messages +from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model +from django.contrib.auth import logout as auth_logout +from django.contrib.auth.decorators import login_required +from django.contrib.auth.views import PasswordChangeView as DjPasswordChangeView from django.core import signing from django.core.exceptions import ValidationError -from django.contrib import messages -from django.utils import six, timezone -from django.utils.translation import ugettext as _ -from django.urls import reverse -from django.contrib.auth import logout as auth_logout -from django.contrib.auth import REDIRECT_FIELD_NAME -from django.contrib.auth.views import PasswordChangeView as DjPasswordChangeView -from django.http import HttpResponseRedirect, HttpResponseForbidden, HttpResponse -from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie -from django.views.decorators.cache import never_cache -from django.contrib.auth.decorators import login_required from django.db.models.fields import FieldDoesNotExist from django.db.models.query import Q -from django.contrib.auth import get_user_model -from django.http import Http404 -from django.utils.http import urlsafe_base64_decode -from django.views.generic.edit import CreateView from django.forms import CharField -from django.http import HttpResponseBadRequest +from django.http import ( + Http404, + HttpResponse, + HttpResponseBadRequest, + HttpResponseForbidden, + HttpResponseRedirect, +) +from django.shortcuts import get_object_or_404, render from django.template import loader +from django.template.loader import render_to_string +from django.urls import reverse +from django.utils import six, timezone +from django.utils.http import urlsafe_base64_decode +from django.utils.translation import ugettext as _ +from django.views.decorators.cache import never_cache +from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie +from django.views.generic import TemplateView +from django.views.generic.base import View +from django.views.generic.edit import CreateView, FormView, UpdateView +from ratelimit.utils import is_ratelimited from authentic2.custom_user.models import iter_attributes -from . import utils, app_settings, decorators, constants, models, cbv, hooks, validators, attribute_kinds -from .utils.service import get_service_from_request, get_service_from_token, set_service_ref -from .utils.evaluate import HTTPHeaders -from .utils import switch_user -from .a2_rbac.utils import get_default_ou + +from . import app_settings, attribute_kinds, cbv, constants, decorators, hooks, models, utils, validators from .a2_rbac.models import OrganizationalUnit as OU -from .forms import passwords as passwords_forms, registration as registration_forms, profile as profile_forms +from .a2_rbac.utils import get_default_ou +from .forms import passwords as passwords_forms +from .forms import profile as profile_forms +from .forms import registration as registration_forms +from .utils import switch_user +from .utils.evaluate import HTTPHeaders +from .utils.service import get_service_from_request, get_service_from_token, set_service_ref User = get_user_model() diff --git a/src/authentic2/wsgi.py b/src/authentic2/wsgi.py index 55b65a4c3..19ac0172f 100644 --- a/src/authentic2/wsgi.py +++ b/src/authentic2/wsgi.py @@ -31,9 +31,10 @@ framework. """ import os +from django.core.wsgi import get_wsgi_application + # XXX: monkeypatch logging from . import logger # noqa: F401 -from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "authentic2.settings") diff --git a/src/authentic2_auth_fc/api_views.py b/src/authentic2_auth_fc/api_views.py index f269104ac..df8922229 100644 --- a/src/authentic2_auth_fc/api_views.py +++ b/src/authentic2_auth_fc/api_views.py @@ -14,14 +14,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.shortcuts import get_object_or_404 from django.contrib.auth import get_user_model - -from rest_framework.response import Response +from django.shortcuts import get_object_or_404 from rest_framework import status -from authentic2.compat.drf import action +from rest_framework.response import Response from authentic2.api_views import DjangoPermission +from authentic2.compat.drf import action @action( diff --git a/src/authentic2_auth_fc/apps.py b/src/authentic2_auth_fc/apps.py index ebda6657c..e36df5ffa 100644 --- a/src/authentic2_auth_fc/apps.py +++ b/src/authentic2_auth_fc/apps.py @@ -14,16 +14,16 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from . import app_settings - - import django.apps from django import template +from . import app_settings + class Plugin(object): def redirect_logout_list(self, request, **kwargs): from django.urls import reverse + from . import utils url = utils.build_logout_url(request, next_url=reverse('auth_logout')) @@ -48,7 +48,9 @@ class AppConfig(django.apps.AppConfig): def a2_hook_api_modify_serializer(self, view, serializer): from rest_framework import serializers + from authentic2.utils import make_url + from . import app_settings if not app_settings.enable: @@ -97,12 +99,14 @@ class AppConfig(django.apps.AppConfig): return True def ready(self): - from .api_views import fc_unlink from authentic2.api_views import UsersAPI + from .api_views import fc_unlink + UsersAPI.fc_unlink = fc_unlink from django.db.models.signals import pre_save + from authentic2.custom_user.models import DeletedUser pre_save.connect(self.pre_save_deleted_user, sender=DeletedUser) diff --git a/src/authentic2_auth_fc/authenticators.py b/src/authentic2_auth_fc/authenticators.py index 64a645748..12005b5d2 100644 --- a/src/authentic2_auth_fc/authenticators.py +++ b/src/authentic2_auth_fc/authenticators.py @@ -14,11 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.utils.translation import gettext_noop from django.template.loader import render_to_string from django.template.response import TemplateResponse +from django.utils.translation import gettext_noop -from authentic2 import app_settings as a2_app_settings, utils as a2_utils +from authentic2 import app_settings as a2_app_settings +from authentic2 import utils as a2_utils from authentic2.authenticators import BaseAuthenticator from authentic2.utils import redirect_to_login diff --git a/src/authentic2_auth_fc/backends.py b/src/authentic2_auth_fc/backends.py index 04bba446a..28b8319ce 100644 --- a/src/authentic2_auth_fc/backends.py +++ b/src/authentic2_auth_fc/backends.py @@ -19,13 +19,13 @@ import logging from django.contrib.auth import get_user_model from django.contrib.auth.backends import ModelBackend -from django.core.exceptions import PermissionDenied, MultipleObjectsReturned +from django.core.exceptions import MultipleObjectsReturned, PermissionDenied from django.db import IntegrityError -from authentic2.a2_rbac.utils import get_default_ou from authentic2 import hooks +from authentic2.a2_rbac.utils import get_default_ou -from . import models, app_settings, utils +from . import app_settings, models, utils logger = logging.getLogger(__name__) diff --git a/src/authentic2_auth_fc/migrations/0001_initial.py b/src/authentic2_auth_fc/migrations/0001_initial.py index 5837df1d8..5db0738da 100644 --- a/src/authentic2_auth_fc/migrations/0001_initial.py +++ b/src/authentic2_auth_fc/migrations/0001_initial.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_auth_fc/migrations/0002_auto_20200416_1439.py b/src/authentic2_auth_fc/migrations/0002_auto_20200416_1439.py index 357c8586a..0cf18221b 100644 --- a/src/authentic2_auth_fc/migrations/0002_auto_20200416_1439.py +++ b/src/authentic2_auth_fc/migrations/0002_auto_20200416_1439.py @@ -2,8 +2,8 @@ # Generated by Django 1.11.29 on 2020-04-16 12:39 from __future__ import unicode_literals -from django.db import migrations, models import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_auth_fc/models.py b/src/authentic2_auth_fc/models.py index 81c923a02..9aecded45 100644 --- a/src/authentic2_auth_fc/models.py +++ b/src/authentic2_auth_fc/models.py @@ -15,17 +15,16 @@ # along with this program. If not, see . import base64 -import json -import hmac import hashlib +import hmac +import json -from django.db import models -from django.utils.encoding import force_bytes -from django.utils.encoding import force_text -from django.utils.six.moves.urllib import parse as urlparse -from django.utils.translation import ugettext_lazy as _ -from django.utils.timezone import now from django.conf import settings +from django.db import models +from django.utils.encoding import force_bytes, force_text +from django.utils.six.moves.urllib import parse as urlparse +from django.utils.timezone import now +from django.utils.translation import ugettext_lazy as _ from authentic2_auth_oidc.utils import parse_timestamp diff --git a/src/authentic2_auth_fc/urls.py b/src/authentic2_auth_fc/urls.py index 4b421f2a5..b0049fb94 100644 --- a/src/authentic2_auth_fc/urls.py +++ b/src/authentic2_auth_fc/urls.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.conf.urls import url, include +from django.conf.urls import include, url from . import views diff --git a/src/authentic2_auth_fc/utils.py b/src/authentic2_auth_fc/utils.py index 2ffee658d..b9602d48f 100644 --- a/src/authentic2_auth_fc/utils.py +++ b/src/authentic2_auth_fc/utils.py @@ -14,21 +14,20 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import datetime +import json import logging import os -import json -import datetime import uuid import requests -from requests.adapters import HTTPAdapter -from requests.packages.urllib3.util.retry import Retry - from django.conf import settings from django.shortcuts import resolve_url +from django.urls import reverse from django.utils.http import urlencode from django.utils.translation import ugettext_lazy as _ -from django.urls import reverse +from requests.adapters import HTTPAdapter +from requests.packages.urllib3.util.retry import Retry from . import app_settings diff --git a/src/authentic2_auth_fc/views.py b/src/authentic2_auth_fc/views.py index 9eef2fe9c..217501a8c 100644 --- a/src/authentic2_auth_fc/views.py +++ b/src/authentic2_auth_fc/views.py @@ -14,29 +14,27 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import uuid -import logging import json +import logging +import uuid + import requests - -from requests_oauthlib import OAuth2Session - - -from django.db import IntegrityError -from django.views.generic import View, FormView -from django.http import HttpResponseRedirect, Http404 -from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model -from django.contrib import messages -from django.shortcuts import resolve_url, render -from django.urls import reverse -from django.utils.six.moves.urllib import parse as urlparse -from django.utils.translation import ugettext as _ -from django.utils.http import is_safe_url, urlencode from django.conf import settings +from django.contrib import messages +from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model from django.core import signing from django.core.cache import InvalidCacheBackendError, caches from django.core.exceptions import PermissionDenied +from django.db import IntegrityError from django.forms import Form +from django.http import Http404, HttpResponseRedirect +from django.shortcuts import render, resolve_url +from django.urls import reverse +from django.utils.http import is_safe_url, urlencode +from django.utils.six.moves.urllib import parse as urlparse +from django.utils.translation import ugettext as _ +from django.views.generic import FormView, View +from requests_oauthlib import OAuth2Session try: from django.contrib.auth.views import update_session_auth_hash @@ -44,7 +42,8 @@ except ImportError: update_session_auth_hash = None from authentic2 import app_settings as a2_app_settings -from authentic2 import utils as a2_utils, hooks, constants +from authentic2 import constants, hooks +from authentic2 import utils as a2_utils from authentic2.a2_rbac.utils import get_default_ou from authentic2.forms.passwords import SetPasswordForm from authentic2.utils import views as views_utils diff --git a/src/authentic2_auth_oidc/admin.py b/src/authentic2_auth_oidc/admin.py index 95452861f..548d075c1 100644 --- a/src/authentic2_auth_oidc/admin.py +++ b/src/authentic2_auth_oidc/admin.py @@ -20,9 +20,9 @@ from django import forms from django.contrib import admin from django.utils.translation import ugettext as _ -from authentic2.models import Attribute from authentic2.custom_user.models import User from authentic2.forms.widgets import DatalistTextInput +from authentic2.models import Attribute from . import models diff --git a/src/authentic2_auth_oidc/apps.py b/src/authentic2_auth_oidc/apps.py index 13684f53c..b6792ef41 100644 --- a/src/authentic2_auth_oidc/apps.py +++ b/src/authentic2_auth_oidc/apps.py @@ -20,6 +20,7 @@ import django.apps class Plugin(object): def revoke_token(self, provider, access_token): import logging + import requests logger = logging.getLogger(__name__) @@ -50,7 +51,9 @@ class Plugin(object): def redirect_logout_list(self, request, next=None): from django.urls import reverse + from authentic2.utils import make_url + from .models import OIDCProvider tokens = request.session.get('auth_oidc', {}).get('tokens', []) @@ -80,6 +83,7 @@ class AppConfig(django.apps.AppConfig): def ready(self): from django.db.models.signals import pre_save + from authentic2.custom_user.models import DeletedUser pre_save.connect(self.pre_save_deleted_user, sender=DeletedUser) diff --git a/src/authentic2_auth_oidc/authenticators.py b/src/authentic2_auth_oidc/authenticators.py index cd798d93a..b9676b4e9 100644 --- a/src/authentic2_auth_oidc/authenticators.py +++ b/src/authentic2_auth_oidc/authenticators.py @@ -14,14 +14,14 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.utils.translation import gettext_noop from django.shortcuts import render +from django.utils.translation import gettext_noop + +from authentic2.authenticators import BaseAuthenticator +from authentic2.utils import make_url, redirect_to_login from . import app_settings, utils from .models import OIDCProvider -from authentic2.utils import make_url -from authentic2.utils import redirect_to_login -from authentic2.authenticators import BaseAuthenticator class OIDCAuthenticator(BaseAuthenticator): diff --git a/src/authentic2_auth_oidc/backends.py b/src/authentic2_auth_oidc/backends.py index 29a3d4e62..b346b6fec 100644 --- a/src/authentic2_auth_oidc/backends.py +++ b/src/authentic2_auth_oidc/backends.py @@ -14,24 +14,21 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import logging import datetime +import logging import requests - -from jwcrypto.jwt import JWT -from jwcrypto.jwk import JWK - -from django.utils import six -from django.utils.timezone import now from django.contrib.auth import get_user_model from django.contrib.auth.backends import ModelBackend +from django.utils import six +from django.utils.timezone import now +from jwcrypto.jwk import JWK +from jwcrypto.jwt import JWT -from django_rbac.utils import get_ou_model - -from authentic2.crypto import base64url_encode from authentic2 import app_settings, hooks +from authentic2.crypto import base64url_encode from authentic2.utils.template import Template +from django_rbac.utils import get_ou_model from . import models, utils diff --git a/src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py b/src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py index eb2a1a6aa..0ac6421d7 100644 --- a/src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py +++ b/src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py @@ -19,14 +19,12 @@ from __future__ import print_function import json import pprint - -from django.core.management.base import BaseCommand, CommandError from django.core.exceptions import ValidationError +from django.core.management.base import BaseCommand, CommandError from django.db.transaction import atomic - -from authentic2_auth_oidc.utils import register_issuer from authentic2_auth_oidc.models import OIDCClaimMapping, OIDCProvider +from authentic2_auth_oidc.utils import register_issuer from django_rbac.utils import get_ou_model diff --git a/src/authentic2_auth_oidc/migrations/0001_initial.py b/src/authentic2_auth_oidc/migrations/0001_initial.py index 8cb51d951..63b5d45b9 100644 --- a/src/authentic2_auth_oidc/migrations/0001_initial.py +++ b/src/authentic2_auth_oidc/migrations/0001_initial.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models -import authentic2.a2_rbac.utils -import authentic2_auth_oidc.models +import uuid + import django.contrib.postgres.fields.jsonb from django.conf import settings -import uuid +from django.db import migrations, models + +import authentic2.a2_rbac.utils +import authentic2_auth_oidc.models class Migration(migrations.Migration): diff --git a/src/authentic2_auth_oidc/migrations/0008_auto_20201102_1142.py b/src/authentic2_auth_oidc/migrations/0008_auto_20201102_1142.py index 8e99bce95..b66d57c01 100644 --- a/src/authentic2_auth_oidc/migrations/0008_auto_20201102_1142.py +++ b/src/authentic2_auth_oidc/migrations/0008_auto_20201102_1142.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.17 on 2020-11-02 10:42 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/src/authentic2_auth_oidc/models.py b/src/authentic2_auth_oidc/models.py index eb6a09916..669152f40 100644 --- a/src/authentic2_auth_oidc/models.py +++ b/src/authentic2_auth_oidc/models.py @@ -14,17 +14,15 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import uuid import json +import uuid +from django.conf import settings +from django.contrib.postgres.fields import JSONField +from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import ugettext_lazy as _ -from django.conf import settings -from django.core.exceptions import ValidationError - -from django.contrib.postgres.fields import JSONField - -from jwcrypto.jwk import JWKSet, InvalidJWKValue, JWK +from jwcrypto.jwk import JWK, InvalidJWKValue, JWKSet from django_rbac.utils import get_ou_model_name diff --git a/src/authentic2_auth_oidc/urls.py b/src/authentic2_auth_oidc/urls.py index 61b654288..c6a75bfc7 100644 --- a/src/authentic2_auth_oidc/urls.py +++ b/src/authentic2_auth_oidc/urls.py @@ -18,7 +18,6 @@ from django.conf.urls import url from . import views - urlpatterns = [ url(r'^accounts/oidc/login/(?P\d+)/$', views.oidc_login, name='oidc-login'), url(r'^accounts/oidc/login/$', views.login_initiate, name='oidc-login-initiate'), diff --git a/src/authentic2_auth_oidc/utils.py b/src/authentic2_auth_oidc/utils.py index ef480b14f..1feb8c76f 100644 --- a/src/authentic2_auth_oidc/utils.py +++ b/src/authentic2_auth_oidc/utils.py @@ -15,24 +15,21 @@ # along with this program. If not, see . import datetime + import requests - -from django.utils import six -from django.utils.timezone import utc from django.shortcuts import get_object_or_404 -from django.utils.translation import ugettext as _ +from django.utils import six from django.utils.six.moves.urllib import parse as urlparse - -from authentic2.decorators import GlobalCache -from authentic2.models import Attribute -from authentic2.a2_rbac.utils import get_default_ou - -from jwcrypto.common import base64url_encode -from jwcrypto.common import JWException -from jwcrypto.common import json_decode +from django.utils.timezone import utc +from django.utils.translation import ugettext as _ +from jwcrypto.common import JWException, base64url_encode, json_decode from jwcrypto.jwk import JWK from jwcrypto.jwt import JWT +from authentic2.a2_rbac.utils import get_default_ou +from authentic2.decorators import GlobalCache +from authentic2.models import Attribute + from . import models TIMEOUT = 1 diff --git a/src/authentic2_auth_oidc/views.py b/src/authentic2_auth_oidc/views.py index f025e2496..20f549508 100644 --- a/src/authentic2_auth_oidc/views.py +++ b/src/authentic2_auth_oidc/views.py @@ -19,22 +19,21 @@ import json import logging import uuid -import requests - import django +import requests from django.conf import settings -from django.core import signing -from django.urls import reverse -from django.utils.translation import get_language, ugettext as _ from django.contrib import messages from django.contrib.auth import REDIRECT_FIELD_NAME -from django.conf import settings -from django.views.generic.base import View +from django.core import signing from django.http import HttpResponseBadRequest +from django.urls import reverse +from django.utils.translation import get_language +from django.utils.translation import ugettext as _ +from django.views.generic.base import View import authentic2.compat.cookies # F401 from authentic2.decorators import setting_enabled -from authentic2.utils import redirect, login, good_next_url, authenticate +from authentic2.utils import authenticate, good_next_url, login, redirect from . import app_settings, models from .utils import get_provider, get_provider_by_issuer diff --git a/src/authentic2_auth_saml/adapters.py b/src/authentic2_auth_saml/adapters.py index 9ae18724b..ebf934f34 100644 --- a/src/authentic2_auth_saml/adapters.py +++ b/src/authentic2_auth_saml/adapters.py @@ -18,21 +18,20 @@ from __future__ import unicode_literals import logging -from django.utils import six from django.contrib import messages from django.core.exceptions import MultipleObjectsReturned from django.db.transaction import atomic +from django.utils import six from django.utils.translation import ugettext as _ - from mellon.adapters import DefaultAdapter, UserCreationError from mellon.utils import get_setting from authentic2 import utils +from authentic2.a2_rbac.models import OrganizationalUnit as OU +from authentic2.a2_rbac.models import Role +from authentic2.a2_rbac.utils import get_default_ou from authentic2.backends import get_user_queryset from authentic2.utils.evaluate import evaluate_condition -from authentic2.a2_rbac.models import Role, OrganizationalUnit as OU -from authentic2.a2_rbac.utils import get_default_ou - logger = logging.getLogger('authentic2.auth_saml') diff --git a/src/authentic2_auth_saml/apps.py b/src/authentic2_auth_saml/apps.py index 8113d5ca2..941c5be67 100644 --- a/src/authentic2_auth_saml/apps.py +++ b/src/authentic2_auth_saml/apps.py @@ -23,6 +23,7 @@ class AppConfig(django.apps.AppConfig): def ready(self): from django.db.models.signals import pre_save + from authentic2.custom_user.models import DeletedUser pre_save.connect(self.pre_save_deleted_user, sender=DeletedUser) diff --git a/src/authentic2_auth_saml/authenticators.py b/src/authentic2_auth_saml/authenticators.py index 98fec9a64..70015bff6 100644 --- a/src/authentic2_auth_saml/authenticators.py +++ b/src/authentic2_auth_saml/authenticators.py @@ -14,9 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.utils.translation import gettext_noop -from django.template.loader import render_to_string from django.shortcuts import render +from django.template.loader import render_to_string +from django.utils.translation import gettext_noop from mellon.utils import get_idp, get_idps from authentic2.authenticators import BaseAuthenticator diff --git a/src/authentic2_auth_saml/urls.py b/src/authentic2_auth_saml/urls.py index ae2079763..bfc3fc98f 100644 --- a/src/authentic2_auth_saml/urls.py +++ b/src/authentic2_auth_saml/urls.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.conf.urls import url, include +from django.conf.urls import include, url urlpatterns = [ url(r'^accounts/saml/', include('mellon.urls'), kwargs={'template_base': 'authentic/base.html'}) diff --git a/src/authentic2_idp_cas/admin.py b/src/authentic2_idp_cas/admin.py index a869539e8..ed4a1ea0c 100644 --- a/src/authentic2_idp_cas/admin.py +++ b/src/authentic2_idp_cas/admin.py @@ -18,10 +18,11 @@ from django import forms from django.contrib import admin from django.utils.translation import ugettext as _ +from authentic2.admin import CleanupAdminMixin + # Django < 1.7 compat from authentic2.attributes_ng.engine import get_attribute_names from authentic2.decorators import to_iter -from authentic2.admin import CleanupAdminMixin from . import models diff --git a/src/authentic2_idp_cas/managers.py b/src/authentic2_idp_cas/managers.py index 6182e3cfd..f40bf1d2b 100644 --- a/src/authentic2_idp_cas/managers.py +++ b/src/authentic2_idp_cas/managers.py @@ -18,8 +18,8 @@ from datetime import timedelta from django.db import models from django.db.models import query -from django.utils.timezone import now from django.utils.six.moves.urllib import parse as urlparse +from django.utils.timezone import now class TicketQuerySet(query.QuerySet): diff --git a/src/authentic2_idp_cas/migrations/0001_initial.py b/src/authentic2_idp_cas/migrations/0001_initial.py index a3fd517d7..0192043e2 100644 --- a/src/authentic2_idp_cas/migrations/0001_initial.py +++ b/src/authentic2_idp_cas/migrations/0001_initial.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models + import authentic2_idp_cas.models diff --git a/src/authentic2_idp_cas/migrations/0002_auto_20150410_1438.py b/src/authentic2_idp_cas/migrations/0002_auto_20150410_1438.py index cb5bf2ba8..0b92c7fe4 100644 --- a/src/authentic2_idp_cas/migrations/0002_auto_20150410_1438.py +++ b/src/authentic2_idp_cas/migrations/0002_auto_20150410_1438.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_idp_cas/migrations/0003_auto_20150415_2223.py b/src/authentic2_idp_cas/migrations/0003_auto_20150415_2223.py index 9ecbb6eab..0034b6e83 100644 --- a/src/authentic2_idp_cas/migrations/0003_auto_20150415_2223.py +++ b/src/authentic2_idp_cas/migrations/0003_auto_20150415_2223.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_idp_cas/migrations/0004_create_services.py b/src/authentic2_idp_cas/migrations/0004_create_services.py index 4d5fcb96f..5e6599aad 100644 --- a/src/authentic2_idp_cas/migrations/0004_create_services.py +++ b/src/authentic2_idp_cas/migrations/0004_create_services.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def create_services(apps, schema_editor): diff --git a/src/authentic2_idp_cas/migrations/0005_alter_field_service_ptr.py b/src/authentic2_idp_cas/migrations/0005_alter_field_service_ptr.py index 59fe2ce9a..d217c05b0 100644 --- a/src/authentic2_idp_cas/migrations/0005_alter_field_service_ptr.py +++ b/src/authentic2_idp_cas/migrations/0005_alter_field_service_ptr.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_idp_cas/migrations/0006_copy_proxy_m2m.py b/src/authentic2_idp_cas/migrations/0006_copy_proxy_m2m.py index 78d7bb53b..b9b772afe 100644 --- a/src/authentic2_idp_cas/migrations/0006_copy_proxy_m2m.py +++ b/src/authentic2_idp_cas/migrations/0006_copy_proxy_m2m.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def copy_proxy_m2m_to_service_proxy(apps, schema_editor): diff --git a/src/authentic2_idp_cas/migrations/0007_alter_service.py b/src/authentic2_idp_cas/migrations/0007_alter_service.py index b69edc23f..8a5e6d050 100644 --- a/src/authentic2_idp_cas/migrations/0007_alter_service.py +++ b/src/authentic2_idp_cas/migrations/0007_alter_service.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_idp_cas/migrations/0008_alter_foreign_keys.py b/src/authentic2_idp_cas/migrations/0008_alter_foreign_keys.py index 2bb5bf3e0..8bc7c6419 100644 --- a/src/authentic2_idp_cas/migrations/0008_alter_foreign_keys.py +++ b/src/authentic2_idp_cas/migrations/0008_alter_foreign_keys.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def alter_foreign_keys(apps, schema_editor): diff --git a/src/authentic2_idp_cas/migrations/0009_alter_related_models.py b/src/authentic2_idp_cas/migrations/0009_alter_related_models.py index 621ae47a2..3d5b6e6d1 100644 --- a/src/authentic2_idp_cas/migrations/0009_alter_related_models.py +++ b/src/authentic2_idp_cas/migrations/0009_alter_related_models.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_idp_cas/migrations/0010_copy_service_ptr_id_to_old_id.py b/src/authentic2_idp_cas/migrations/0010_copy_service_ptr_id_to_old_id.py index 78776a4e0..f525f4d36 100644 --- a/src/authentic2_idp_cas/migrations/0010_copy_service_ptr_id_to_old_id.py +++ b/src/authentic2_idp_cas/migrations/0010_copy_service_ptr_id_to_old_id.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def noop(apps, schema_editor): diff --git a/src/authentic2_idp_cas/migrations/0011_remove_old_id_restore_proxy.py b/src/authentic2_idp_cas/migrations/0011_remove_old_id_restore_proxy.py index ab55a45a6..cfb46e240 100644 --- a/src/authentic2_idp_cas/migrations/0011_remove_old_id_restore_proxy.py +++ b/src/authentic2_idp_cas/migrations/0011_remove_old_id_restore_proxy.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_idp_cas/migrations/0012_copy_service_proxy_to_m2m.py b/src/authentic2_idp_cas/migrations/0012_copy_service_proxy_to_m2m.py index 75bf9f5d5..6f5974d94 100644 --- a/src/authentic2_idp_cas/migrations/0012_copy_service_proxy_to_m2m.py +++ b/src/authentic2_idp_cas/migrations/0012_copy_service_proxy_to_m2m.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models def copy_proxy_m2m_to_service_proxy(apps, schema_editor): diff --git a/src/authentic2_idp_cas/migrations/0013_delete_model_service_proxy2.py b/src/authentic2_idp_cas/migrations/0013_delete_model_service_proxy2.py index ab1aba42e..6b7bce298 100644 --- a/src/authentic2_idp_cas/migrations/0013_delete_model_service_proxy2.py +++ b/src/authentic2_idp_cas/migrations/0013_delete_model_service_proxy2.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_idp_cas/migrations/0014_auto_20151204_1606.py b/src/authentic2_idp_cas/migrations/0014_auto_20151204_1606.py index f110d29d1..8de365f81 100644 --- a/src/authentic2_idp_cas/migrations/0014_auto_20151204_1606.py +++ b/src/authentic2_idp_cas/migrations/0014_auto_20151204_1606.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/authentic2_idp_cas/models.py b/src/authentic2_idp_cas/models.py index a57469146..ab59c7143 100644 --- a/src/authentic2_idp_cas/models.py +++ b/src/authentic2_idp_cas/models.py @@ -14,16 +14,16 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from django.db import models -from django.utils.translation import ugettext_lazy as _ -from django.utils.timezone import now -from django.core.validators import URLValidator from django.core.exceptions import ValidationError +from django.core.validators import URLValidator +from django.db import models +from django.utils.timezone import now +from django.utils.translation import ugettext_lazy as _ from authentic2.models import LogoutUrlAbstract, Service from authentic2.utils import check_session_key -from . import managers, utils, constants +from . import constants, managers, utils url_validator = URLValidator( schemes=['http', 'https', 'ftp', 'ftps', 'imap', 'imaps', 'sieve', 'smtp', 'smtps', 'ssh'] diff --git a/src/authentic2_idp_cas/views.py b/src/authentic2_idp_cas/views.py index a8535f4cc..0c6216423 100644 --- a/src/authentic2_idp_cas/views.py +++ b/src/authentic2_idp_cas/views.py @@ -15,72 +15,71 @@ # along with this program. If not, see . import logging +from collections import defaultdict from datetime import timedelta from xml.etree import ElementTree as ET -from collections import defaultdict import requests - -from django.http import HttpResponseBadRequest, HttpResponse -from django.views.generic.base import View +from django.http import HttpResponse, HttpResponseBadRequest from django.utils import six from django.utils.timezone import now +from django.views.generic.base import View -from authentic2.utils import ( - get_user_from_session_key, - make_url, - login_require, - find_authentication_event, - redirect, - normalize_attribute_values, - attribute_values_to_identifier, -) +from authentic2 import hooks from authentic2.attributes_ng.engine import get_attributes from authentic2.constants import NONCE_FIELD_NAME +from authentic2.utils import ( + attribute_values_to_identifier, + find_authentication_event, + get_user_from_session_key, + login_require, + make_url, + normalize_attribute_values, + redirect, +) from authentic2.views import logout as logout_view -from authentic2 import hooks - -from authentic2_idp_cas.models import Ticket, Service -from authentic2_idp_cas.utils import make_id from authentic2_idp_cas.constants import ( - SERVICE_PARAM, - RENEW_PARAM, - GATEWAY_PARAM, - TICKET_PARAM, - CANCEL_PARAM, - SERVICE_TICKET_PREFIX, - INVALID_REQUEST_ERROR, - INVALID_TICKET_SPEC_ERROR, - INVALID_SERVICE_ERROR, - INVALID_TICKET_ERROR, - CAS10_VALIDATION_FAILURE, - CAS20_VALIDATION_FAILURE, - SERVICE_RESPONSE_ELT, + ATTRIBUTES_ELT, AUTHENTICATION_SUCCESS_ELT, - USER_ELT, - PGT_URL_PARAM, - PGT_IOU_PARAM, - SESSION_CAS_LOGOUTS, + BAD_PGT_ERROR, + CANCEL_PARAM, + CAS10_VALIDATION_FAILURE, CAS10_VALIDATION_SUCCESS, + CAS20_PROXY_FAILURE, + CAS20_VALIDATION_FAILURE, + CAS_NAMESPACE, + GATEWAY_PARAM, + INTERNAL_ERROR, + INVALID_REQUEST_ERROR, + INVALID_SERVICE_ERROR, + INVALID_TARGET_SERVICE_ERROR, + INVALID_TICKET_ERROR, + INVALID_TICKET_SPEC_ERROR, PGT_ELT, + PGT_ID_PARAM, + PGT_IOU_PARAM, + PGT_IOU_PREFIX, + PGT_PARAM, + PGT_PREFIX, + PGT_URL_PARAM, PROXIES_ELT, PROXY_ELT, - PGT_PREFIX, - PGT_IOU_PREFIX, - PT_PREFIX, - TARGET_SERVICE_PARAM, - BAD_PGT_ERROR, - INVALID_TARGET_SERVICE_ERROR, - PROXY_UNAUTHORIZED_ERROR, - PGT_PARAM, - PGT_ID_PARAM, - CAS20_PROXY_FAILURE, PROXY_SUCCESS_ELT, PROXY_TICKET_ELT, - INTERNAL_ERROR, - CAS_NAMESPACE, - ATTRIBUTES_ELT, + PROXY_UNAUTHORIZED_ERROR, + PT_PREFIX, + RENEW_PARAM, + SERVICE_PARAM, + SERVICE_RESPONSE_ELT, + SERVICE_TICKET_PREFIX, + SESSION_CAS_LOGOUTS, + TARGET_SERVICE_PARAM, + TICKET_PARAM, + USER_ELT, ) +from authentic2_idp_cas.models import Service, Ticket +from authentic2_idp_cas.utils import make_id + from . import app_settings try: diff --git a/src/authentic2_idp_oidc/admin.py b/src/authentic2_idp_oidc/admin.py index 5d39fdece..2f8c4bbeb 100644 --- a/src/authentic2_idp_oidc/admin.py +++ b/src/authentic2_idp_oidc/admin.py @@ -21,7 +21,7 @@ from django.utils.functional import curry from authentic2.attributes_ng.engine import get_service_attributes from authentic2.forms.widgets import DatalistTextInput -from . import models, app_settings +from . import app_settings, models class OIDCClaimInlineForm(forms.ModelForm): @@ -80,6 +80,7 @@ class OIDCAuthorizationAdmin(admin.ModelAdmin): def get_search_results(self, request, queryset, search_term): from django.contrib.contenttypes.models import ContentType + from authentic2.a2_rbac.models import OrganizationalUnit as OU queryset, use_distinct = super(OIDCAuthorizationAdmin, self).get_search_results( diff --git a/src/authentic2_idp_oidc/apps.py b/src/authentic2_idp_oidc/apps.py index 8b6673d42..d8642c46c 100644 --- a/src/authentic2_idp_oidc/apps.py +++ b/src/authentic2_idp_oidc/apps.py @@ -21,8 +21,8 @@ from django.utils.encoding import smart_bytes class Plugin(object): def logout_list(self, request): - from .utils import get_oidc_sessions from . import app_settings + from .utils import get_oidc_sessions fragments = [] @@ -49,9 +49,10 @@ class AppConfig(django.apps.AppConfig): # implement translation of encrypted pairwise identifiers when and OIDC Client is using the # A2 API def a2_hook_api_modify_serializer(self, view, serializer): - from . import utils from rest_framework import serializers + from . import utils + if hasattr(view.request.user, 'oidc_client'): client = view.request.user.oidc_client if client.identifier_policy == client.POLICY_PAIRWISE_REVERSIBLE: @@ -72,6 +73,7 @@ class AppConfig(django.apps.AppConfig): def a2_hook_api_modify_view_before_get_object(self, view): '''Decrypt sub used as pk argument in URL.''' import uuid + from . import utils client = self.get_oidc_client(view) @@ -90,6 +92,7 @@ class AppConfig(django.apps.AppConfig): def a2_hook_api_modify_serializer_after_validation(self, view, serializer): import uuid + from . import utils if view.__class__.__name__ != 'UsersAPI': diff --git a/src/authentic2_idp_oidc/migrations/0001_initial.py b/src/authentic2_idp_oidc/migrations/0001_initial.py index 15ef26ead..9d7446766 100644 --- a/src/authentic2_idp_oidc/migrations/0001_initial.py +++ b/src/authentic2_idp_oidc/migrations/0001_initial.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models from django.conf import settings +from django.db import migrations, models + import authentic2_idp_oidc.models diff --git a/src/authentic2_idp_oidc/migrations/0002_auto_20170121_2346.py b/src/authentic2_idp_oidc/migrations/0002_auto_20170121_2346.py index 141c27ee4..ca40159aa 100644 --- a/src/authentic2_idp_oidc/migrations/0002_auto_20170121_2346.py +++ b/src/authentic2_idp_oidc/migrations/0002_auto_20170121_2346.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations, models + import authentic2_idp_oidc.models diff --git a/src/authentic2_idp_oidc/migrations/0003_auto_20170329_1259.py b/src/authentic2_idp_oidc/migrations/0003_auto_20170329_1259.py index 52361dedd..698a00333 100644 --- a/src/authentic2_idp_oidc/migrations/0003_auto_20170329_1259.py +++ b/src/authentic2_idp_oidc/migrations/0003_auto_20170329_1259.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations, models + import authentic2_idp_oidc.models diff --git a/src/authentic2_idp_oidc/migrations/0011_auto_20180808_1546.py b/src/authentic2_idp_oidc/migrations/0011_auto_20180808_1546.py index 8121a24be..20eab7e78 100644 --- a/src/authentic2_idp_oidc/migrations/0011_auto_20180808_1546.py +++ b/src/authentic2_idp_oidc/migrations/0011_auto_20180808_1546.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals from django.db import migrations - OLD_DEFAULT_CLAIMS_MAPPING = { 'email': 'django_user_email', 'email_verified': 'django_user_email_verified', diff --git a/src/authentic2_idp_oidc/models.py b/src/authentic2_idp_oidc/models.py index 96236459a..f8e4bef98 100644 --- a/src/authentic2_idp_oidc/models.py +++ b/src/authentic2_idp_oidc/models.py @@ -17,22 +17,21 @@ import uuid from importlib import import_module - -from django.db import models -from django.core.validators import URLValidator -from django.core.exceptions import ValidationError, ImproperlyConfigured -from django.utils.translation import ugettext_lazy as _ from django.conf import settings +from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation +from django.core.exceptions import ImproperlyConfigured, ValidationError +from django.core.validators import URLValidator +from django.db import models from django.utils import six from django.utils.functional import cached_property -from django.utils.timezone import now from django.utils.six.moves.urllib import parse as urlparse -from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation +from django.utils.timezone import now +from django.utils.translation import ugettext_lazy as _ from authentic2.a2_rbac.models import OrganizationalUnit from authentic2.models import Service -from . import utils, managers, app_settings +from . import app_settings, managers, utils def generate_uuid(): diff --git a/src/authentic2_idp_oidc/urls.py b/src/authentic2_idp_oidc/urls.py index 8abcfd390..19427aa27 100644 --- a/src/authentic2_idp_oidc/urls.py +++ b/src/authentic2_idp_oidc/urls.py @@ -18,7 +18,6 @@ from django.conf.urls import url from . import views - urlpatterns = [ url(r'^.well-known/openid-configuration$', views.openid_configuration, name='oidc-openid-configuration'), url(r'^idp/oidc/certs/?$', views.certs, name='oidc-certs'), diff --git a/src/authentic2_idp_oidc/utils.py b/src/authentic2_idp_oidc/utils.py index 28d4cca1a..1a00a4f87 100644 --- a/src/authentic2_idp_oidc/utils.py +++ b/src/authentic2_idp_oidc/utils.py @@ -14,24 +14,23 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import json -import hashlib import base64 +import hashlib +import json import uuid -from jwcrypto.jwk import JWK, JWKSet, InvalidJWKValue -from jwcrypto.jwt import JWT - -from django.core.exceptions import ImproperlyConfigured from django.conf import settings +from django.core.exceptions import ImproperlyConfigured from django.utils import six from django.utils.encoding import force_bytes, force_text from django.utils.six.moves.urllib import parse as urlparse +from jwcrypto.jwk import JWK, InvalidJWKValue, JWKSet +from jwcrypto.jwt import JWT -from authentic2 import hooks, crypto +from authentic2 import crypto, hooks from authentic2.attributes_ng.engine import get_attributes -from authentic2.utils.template import Template from authentic2.decorators import GlobalCache +from authentic2.utils.template import Template from . import app_settings @@ -266,6 +265,7 @@ def add_oidc_session(request, client): @GlobalCache(timeout=60) def good_next_url(next_url): from authentic2.utils import same_origin + from .models import OIDCClient for oidc_client in OIDCClient.objects.all(): diff --git a/src/authentic2_idp_oidc/views.py b/src/authentic2_idp_oidc/views.py index 9b969a8d9..131a16085 100644 --- a/src/authentic2_idp_oidc/views.py +++ b/src/authentic2_idp_oidc/views.py @@ -14,10 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import base64 +import datetime import logging import math -import datetime -import base64 try: from secrets import compare_digest @@ -29,27 +29,27 @@ except ImportError: import time +from django.conf import settings +from django.contrib import messages +from django.contrib.auth import authenticate from django.http import HttpResponse, HttpResponseNotAllowed, JsonResponse +from django.shortcuts import render from django.urls import reverse from django.utils import six from django.utils.encoding import force_text -from django.utils.timezone import now, utc from django.utils.http import urlencode -from django.shortcuts import render -from django.views.decorators.csrf import csrf_exempt -from django.contrib import messages -from django.contrib.auth import authenticate -from django.conf import settings +from django.utils.timezone import now, utc from django.utils.translation import ugettext as _ +from django.views.decorators.csrf import csrf_exempt from ratelimit.utils import is_ratelimited from authentic2 import app_settings as a2_app_settings +from authentic2 import hooks from authentic2.compat.misc import Base64Error from authentic2.decorators import setting_enabled from authentic2.exponential_retry_timeout import ExponentialRetryTimeout -from authentic2.utils import login_require, redirect, last_authentication_event, make_url +from authentic2.utils import last_authentication_event, login_require, make_url, redirect from authentic2.views import logout as a2_logout -from authentic2 import hooks from django_rbac.utils import get_ou_model from . import app_settings, models, utils diff --git a/src/django_rbac/apps.py b/src/django_rbac/apps.py index 86e0e16cc..511b9da69 100644 --- a/src/django_rbac/apps.py +++ b/src/django_rbac/apps.py @@ -6,8 +6,9 @@ class DjangoRBACConfig(AppConfig): verbose_name = 'RBAC engine for Django' def ready(self): + from django.db.models.signals import post_delete, post_migrate, post_save + from . import signal_handlers, utils - from django.db.models.signals import post_save, post_delete, post_migrate # update role parenting when new role parenting is created post_save.connect(signal_handlers.role_parenting_post_save, sender=utils.get_role_parenting_model()) diff --git a/src/django_rbac/managers.py b/src/django_rbac/managers.py index 767ee4253..ce1fdc8de 100644 --- a/src/django_rbac/managers.py +++ b/src/django_rbac/managers.py @@ -1,11 +1,11 @@ import contextlib import threading +from django.contrib.auth import get_user_model +from django.contrib.contenttypes.models import ContentType from django.db import models from django.db.models import query -from django.contrib.contenttypes.models import ContentType -from django.db.models.query import Q, Prefetch -from django.contrib.auth import get_user_model +from django.db.models.query import Prefetch, Q from django.utils import six from . import utils diff --git a/src/django_rbac/migrations/0001_initial.py b/src/django_rbac/migrations/0001_initial.py index 13d709801..bd825cda8 100644 --- a/src/django_rbac/migrations/0001_initial.py +++ b/src/django_rbac/migrations/0001_initial.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models + import authentic2.utils diff --git a/src/django_rbac/migrations/0002_organizationalunit_permission_role_roleparenting.py b/src/django_rbac/migrations/0002_organizationalunit_permission_role_roleparenting.py index fef33cd27..43c29af7a 100644 --- a/src/django_rbac/migrations/0002_organizationalunit_permission_role_roleparenting.py +++ b/src/django_rbac/migrations/0002_organizationalunit_permission_role_roleparenting.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models import django_rbac diff --git a/src/django_rbac/migrations/0004_auto_20150708_1337.py b/src/django_rbac/migrations/0004_auto_20150708_1337.py index 17f32bdd0..f56b99add 100644 --- a/src/django_rbac/migrations/0004_auto_20150708_1337.py +++ b/src/django_rbac/migrations/0004_auto_20150708_1337.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/src/django_rbac/models.py b/src/django_rbac/models.py index 92c91c587..fb1e86e90 100644 --- a/src/django_rbac/models.py +++ b/src/django_rbac/models.py @@ -1,30 +1,27 @@ -import operator import hashlib +import operator +from django.conf import settings +from django.db import models +from django.db.models.query import Prefetch, Q from django.utils import six from django.utils.text import slugify from django.utils.translation import ugettext_lazy as _ -from django.db import models -from django.conf import settings -from django.db.models.query import Q, Prefetch try: from django.contrib.contenttypes.fields import GenericForeignKey except ImportError: # Django < 1.8 from django.contrib.contenttypes.generic import GenericForeignKey -from django.contrib.contenttypes.models import ContentType -from django.contrib.auth import get_user_model -from django.contrib.auth.models import ( - Group, - _user_get_all_permissions, - _user_has_perm, - _user_has_module_perms, - Permission as AuthPermission, -) -from django.contrib import auth -from . import utils, constants, managers, backends +from django.contrib import auth +from django.contrib.auth import get_user_model +from django.contrib.auth.models import Group +from django.contrib.auth.models import Permission as AuthPermission +from django.contrib.auth.models import _user_get_all_permissions, _user_has_module_perms, _user_has_perm +from django.contrib.contenttypes.models import ContentType + +from . import backends, constants, managers, utils class AbstractBase(models.Model): diff --git a/src/django_rbac/utils.py b/src/django_rbac/utils.py index 26d01b257..7aba5934b 100644 --- a/src/django_rbac/utils.py +++ b/src/django_rbac/utils.py @@ -1,7 +1,7 @@ import uuid -from django.conf import settings from django.apps import apps +from django.conf import settings from django.utils import six from . import constants diff --git a/tests/auth_fc/conftest.py b/tests/auth_fc/conftest.py index fab54962d..511d6e007 100644 --- a/tests/auth_fc/conftest.py +++ b/tests/auth_fc/conftest.py @@ -21,15 +21,13 @@ import json import urllib.parse as urlparse import uuid -from jwcrypto import jwk, jwt import httmock import pytest - from django.http import QueryDict from django.urls import reverse from django.utils.http import urlencode from django.utils.timezone import now - +from jwcrypto import jwk, jwt from authentic2.models import Service from authentic2.utils import make_url diff --git a/tests/auth_fc/test_auth_fc.py b/tests/auth_fc/test_auth_fc.py index 41ebd3fd6..b3334a1e8 100644 --- a/tests/auth_fc/test_auth_fc.py +++ b/tests/auth_fc/test_auth_fc.py @@ -16,22 +16,19 @@ # along with this program. If not, see . import datetime + import mock - import requests - from django.contrib.auth import get_user_model from django.urls import reverse from django.utils.six.moves.urllib import parse as urlparse from django.utils.timezone import now from authentic2.custom_user.models import DeletedUser - from authentic2_auth_fc import models from authentic2_auth_fc.utils import requests_retry_session -from ..utils import login, get_link_from_mail - +from ..utils import get_link_from_mail, login User = get_user_model() diff --git a/tests/cache_urls.py b/tests/cache_urls.py index a40678739..bdee29168 100644 --- a/tests/cache_urls.py +++ b/tests/cache_urls.py @@ -17,7 +17,7 @@ from django.conf.urls import url from django.http import HttpResponse -from authentic2.decorators import SessionCache, DjangoCache +from authentic2.decorators import DjangoCache, SessionCache @DjangoCache diff --git a/tests/conftest.py b/tests/conftest.py index d5568a402..ca3cf1c04 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,32 +16,27 @@ # along with this program. If not, see . -import pytest -import mock - -import django_webtest - import django +import django_webtest +import mock +import pytest from django.contrib.auth import get_user_model from django.core.cache import cache -from django_rbac.utils import get_ou_model, get_role_model -from django.utils.six.moves.urllib import parse as urlparse -from django.db.migrations.executor import MigrationExecutor -from django.db import connection from django.core.management import call_command - +from django.db import connection +from django.db.migrations.executor import MigrationExecutor +from django.utils.six.moves.urllib import parse as urlparse from pytest_django.migrations import DisableMigrations from authentic2 import hooks as a2_hooks +from authentic2.a2_rbac.utils import get_default_ou +from authentic2.authentication import OIDCUser +from authentic2.manager.utils import get_ou_count from authentic2.models import Service from authentic2.utils.evaluate import BaseExpressionValidator -from authentic2.a2_rbac.utils import get_default_ou -from authentic2.manager.utils import get_ou_count -from authentic2_auth_oidc.utils import get_providers -from authentic2_auth_oidc.utils import get_provider_by_issuer -from authentic2_auth_oidc.utils import has_providers +from authentic2_auth_oidc.utils import get_provider_by_issuer, get_providers, has_providers from authentic2_idp_oidc.models import OIDCClient -from authentic2.authentication import OIDCUser +from django_rbac.utils import get_ou_model, get_role_model from . import utils diff --git a/tests/test_a2_rbac.py b/tests/test_a2_rbac.py index c3cf38183..8e55e5bc9 100644 --- a/tests/test_a2_rbac.py +++ b/tests/test_a2_rbac.py @@ -15,28 +15,19 @@ # along with this program. If not, see . import pytest - +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError from django.core.management import call_command -from django.contrib.contenttypes.models import ContentType - -from django_rbac.utils import get_permission_model -from django_rbac.models import Operation, CHANGE_OP +from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP +from authentic2.a2_rbac.models import OrganizationalUnit as OU +from authentic2.a2_rbac.models import Permission, Role, RoleAttribute +from authentic2.a2_rbac.utils import get_default_ou, get_view_user_perm from authentic2.custom_user.models import User from authentic2.models import Service -from django.core.management import call_command - -from authentic2.a2_rbac.utils import get_default_ou, get_view_user_perm -from authentic2.a2_rbac.models import ( - Role, - Permission, - OrganizationalUnit as OU, - RoleAttribute, - MANAGE_MEMBERS_OP, -) from authentic2.utils import get_hex_uuid - +from django_rbac.models import CHANGE_OP, Operation +from django_rbac.utils import get_permission_model from .utils import login, request_select2 diff --git a/tests/test_admin.py b/tests/test_admin.py index 04e4a6cc7..8a5dd0410 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -17,9 +17,10 @@ from __future__ import unicode_literals +from django.utils.six.moves.urllib.parse import urlparse + from authentic2.custom_user.models import User from authentic2.models import Attribute -from django.utils.six.moves.urllib.parse import urlparse from . import utils diff --git a/tests/test_all.py b/tests/test_all.py index 77d39d360..29d257db7 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -15,41 +15,39 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import json import base64 +import json import pytest - -from django.core import mail -from django.test import TestCase -from django.test.client import Client -from django.test.utils import override_settings -from django.core.serializers.json import DjangoJSONEncoder from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.contrib.sessions.backends.cache import SessionStore +from django.core import mail +from django.core.serializers.json import DjangoJSONEncoder +from django.test import TestCase +from django.test.client import Client +from django.test.utils import override_settings from django.urls import reverse from django.utils.encoding import force_text -from django.utils.translation import ugettext as _ from django.utils.six import text_type from django.utils.six.moves.urllib import parse as urlparse +from django.utils.translation import ugettext as _ +from rest_framework import status, test -from rest_framework import test -from rest_framework import status +from authentic2 import attribute_kinds, models, utils +from django_rbac.utils import get_ou_model, get_role_model -from django_rbac.utils import get_role_model, get_ou_model - -from authentic2 import utils, models, attribute_kinds - -from .utils import Authentic2TestCase, get_response_form, get_link_from_mail, assert_event +from .utils import Authentic2TestCase, assert_event, get_link_from_mail, get_response_form class SerializerTests(TestCase): def test_generic_foreign_key_natural_key(self): import json - from authentic2.models import Attribute, AttributeValue + from django.core import serializers + from authentic2.models import Attribute, AttributeValue + User = get_user_model() ucount = User.objects.count() acount = Attribute.objects.count() @@ -154,9 +152,10 @@ class UtilsTests(Authentic2TestCase): ) def test_redirect(self): - from authentic2.utils import redirect from django.test.client import RequestFactory + from authentic2.utils import redirect + rf = RequestFactory() request = rf.get('/coin', data={'next': '..'}) request2 = rf.get('/coin', data={'next': '..', 'token': 'xxx'}) @@ -174,27 +173,30 @@ class UtilsTests(Authentic2TestCase): self.assertEqualsURL(response['Location'], '/boob/?token=uuu&next=..') def test_redirect_to_login(self): - from authentic2.utils import redirect_to_login from django.test.client import RequestFactory + from authentic2.utils import redirect_to_login + rf = RequestFactory() request = rf.get('/coin', data={'next': '..'}) response = redirect_to_login(request) self.assertEqualsURL(response['Location'], '/login/?next=..') def test_continue_to_next_url(self): - from authentic2.utils import continue_to_next_url from django.test.client import RequestFactory + from authentic2.utils import continue_to_next_url + rf = RequestFactory() request = rf.get('/coin', data={'next': '/zob/', 'nonce': 'xxx'}) response = continue_to_next_url(request) self.assertEqualsURL(response['Location'], '/zob/?nonce=xxx') def test_login_require(self): - from authentic2.utils import login_require from django.test.client import RequestFactory + from authentic2.utils import login_require + rf = RequestFactory() request = rf.get('/coin', data={'next': '/zob/', 'nonce': 'xxx'}) request.session = SessionStore() @@ -282,6 +284,7 @@ class CacheTests(TestCase): @override_settings(ROOT_URLCONF='tests.cache_urls') def test_cache_decorator_base(self): import random + from authentic2.decorators import CacheDecoratorBase class GlobalCache(CacheDecoratorBase): @@ -351,8 +354,8 @@ class CacheTests(TestCase): class AttributeKindsTest(TestCase): def test_simple(self): - from django.core.exceptions import ValidationError from django import forms + from django.core.exceptions import ValidationError with self.settings( A2_ATTRIBUTE_KINDS=[ @@ -435,8 +438,7 @@ class APITest(TestCase): @override_settings(A2_REQUIRED_FIELDS=['username']) def register_with_user(self, user, cred): from django.contrib.auth import get_user_model - from rest_framework import test - from rest_framework import status + from rest_framework import status, test # disable existing attributes models.Attribute.objects.update(disabled=True) @@ -543,8 +545,7 @@ class APITest(TestCase): @override_settings(A2_REQUIRED_FIELDS=['username']) def test_email_is_unique_double_registration(self): from django.contrib.auth import get_user_model - from rest_framework import test - from rest_framework import status + from rest_framework import status, test # disable existing attributes models.Attribute.objects.update(disabled=True) @@ -634,8 +635,7 @@ class APITest(TestCase): @override_settings(A2_REQUIRED_FIELDS=['username']) def test_email_username_is_unique_double_registration(self): from django.contrib.auth import get_user_model - from rest_framework import test - from rest_framework import status + from rest_framework import status, test # disable existing attributes models.Attribute.objects.update(disabled=True) diff --git a/tests/test_api.py b/tests/test_api.py index df3f130c7..d75485858 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -18,35 +18,33 @@ import datetime import json -import mock -import pytest import random import uuid - import django -from django.contrib.auth.hashers import check_password +import mock +import pytest from django.contrib.auth import get_user_model +from django.contrib.auth.hashers import check_password from django.contrib.contenttypes.models import ContentType from django.core import mail from django.urls import reverse from django.utils.encoding import force_text +from django.utils.http import urlencode from django.utils.text import slugify from django.utils.timezone import now -from django.utils.http import urlencode - -from rest_framework import VERSION as drf_version -from django_rbac.models import SEARCH_OP -from django_rbac.utils import get_role_model, get_ou_model from requests.models import Response +from rest_framework import VERSION as drf_version from authentic2.a2_rbac.models import Role from authentic2.a2_rbac.utils import get_default_ou -from authentic2.apps.journal.models import EventType, Event -from authentic2.models import Service, Attribute, AttributeValue, AuthorizedRole +from authentic2.apps.journal.models import Event, EventType +from authentic2.models import Attribute, AttributeValue, AuthorizedRole, Service from authentic2.utils import good_next_url +from django_rbac.models import SEARCH_OP +from django_rbac.utils import get_ou_model, get_role_model -from .utils import login, basic_authorization_header, get_link_from_mail +from .utils import basic_authorization_header, get_link_from_mail, login pytestmark = pytest.mark.django_db diff --git a/tests/test_attribute_kinds.py b/tests/test_attribute_kinds.py index 65d0efdc4..5fc7e5518 100644 --- a/tests/test_attribute_kinds.py +++ b/tests/test_attribute_kinds.py @@ -19,14 +19,13 @@ import datetime import os import PIL.Image - from django.conf import settings +from webtest import Upload from authentic2.custom_user.models import User from authentic2.models import Attribute from .utils import get_link_from_mail -from webtest import Upload def test_string(db, app, admin, mailoutbox): diff --git a/tests/test_auth_oidc.py b/tests/test_auth_oidc.py index c9a8d72d8..b27fb36db 100644 --- a/tests/test_auth_oidc.py +++ b/tests/test_auth_oidc.py @@ -18,43 +18,38 @@ import datetime import json import os -import pytest import random import re import time -from jwcrypto.common import base64url_encode, base64url_decode, json_encode -from jwcrypto.jwk import JWKSet, JWK +import pytest +from django.contrib.auth import get_user_model +from django.db import IntegrityError, transaction +from django.http import QueryDict +from django.urls import reverse +from django.utils.encoding import force_str, force_text +from django.utils.six.moves.urllib import parse as urlparse +from django.utils.timezone import now, utc +from httmock import HTTMock, urlmatch +from jwcrypto.common import base64url_decode, base64url_encode, json_encode +from jwcrypto.jwk import JWK, JWKSet from jwcrypto.jws import JWS, InvalidJWSObject from jwcrypto.jwt import JWT -from httmock import urlmatch, HTTMock - -from django.contrib.auth import get_user_model -from django.db import IntegrityError, transaction -from django.urls import reverse -from django.utils.encoding import force_text, force_str -from django.http import QueryDict -from django.utils.six.moves.urllib import parse as urlparse -from django.utils.timezone import now -from django.utils.timezone import utc - -from django_rbac.utils import get_ou_model - -from authentic2_auth_oidc.utils import ( - parse_id_token, - IDToken, - get_providers, - has_providers, - register_issuer, - IDTokenError, -) -from authentic2_auth_oidc.models import OIDCProvider, OIDCClaimMapping, OIDCAccount -from authentic2.models import Attribute -from authentic2.models import AttributeValue -from authentic2.utils import last_authentication_event from authentic2.a2_rbac.utils import get_default_ou from authentic2.custom_user.models import DeletedUser +from authentic2.models import Attribute, AttributeValue +from authentic2.utils import last_authentication_event +from authentic2_auth_oidc.models import OIDCAccount, OIDCClaimMapping, OIDCProvider +from authentic2_auth_oidc.utils import ( + IDToken, + IDTokenError, + get_providers, + has_providers, + parse_id_token, + register_issuer, +) +from django_rbac.utils import get_ou_model from . import utils diff --git a/tests/test_auth_saml.py b/tests/test_auth_saml.py index f6834d58c..c57be706e 100644 --- a/tests/test_auth_saml.py +++ b/tests/test_auth_saml.py @@ -18,17 +18,14 @@ import datetime import os import re -import pytest - import lasso - +import pytest from django.contrib.auth import get_user_model from django.utils.timezone import now - from mellon.models import UserSAMLIdentifier -from authentic2.models import Attribute from authentic2.custom_user.models import DeletedUser +from authentic2.models import Attribute from authentic2_auth_saml.adapters import AuthenticAdapter, MappingError User = get_user_model() diff --git a/tests/test_backends.py b/tests/test_backends.py index 587aba53a..6d94412d0 100644 --- a/tests/test_backends.py +++ b/tests/test_backends.py @@ -14,8 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from authentic2.utils import authenticate from authentic2.backends import is_user_authenticable +from authentic2.utils import authenticate def test_user_filters(settings, db, simple_user, user_ou1, ou1): diff --git a/tests/test_commands.py b/tests/test_commands.py index 72f03bee8..9125e1c9c 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -18,34 +18,29 @@ import datetime import importlib import json +import py import pytest - +from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.utils import six from django.utils.timezone import now -import py from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP, VIEW_OP from authentic2.a2_rbac.utils import get_default_ou -from authentic2.models import UserExternalId from authentic2.custom_user.models import DeletedUser -from authentic2_auth_oidc.models import OIDCProvider, OIDCAccount -from django_rbac.models import ADMIN_OP -from django_rbac.models import Operation -from django_rbac.utils import get_operation -from django_rbac.utils import get_ou_model -from django_rbac.utils import get_permission_model -from django_rbac.utils import get_role_model -from django.contrib.auth import get_user_model +from authentic2.models import UserExternalId +from authentic2_auth_oidc.models import OIDCAccount, OIDCProvider +from django_rbac.models import ADMIN_OP, Operation +from django_rbac.utils import get_operation, get_ou_model, get_permission_model, get_role_model -from .utils import login, call_command +from .utils import call_command, login User = get_user_model() if six.PY2: FileType = file # noqa: F821 else: - from io import TextIOWrapper, BufferedReader, BufferedWriter + from io import BufferedReader, BufferedWriter, TextIOWrapper FileType = (TextIOWrapper, BufferedReader, BufferedWriter) diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index 6874d53fb..959583473 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -17,7 +17,6 @@ import threading import pytest - from django.db import connection from authentic2.models import Attribute, AttributeValue diff --git a/tests/test_crypto.py b/tests/test_crypto.py index b3aaf7aeb..cd83c1747 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -16,11 +16,10 @@ # along with this program. If not, see . import random -import uuid import time +import uuid import pytest - from django.utils.encoding import force_bytes from authentic2 import crypto diff --git a/tests/test_csv_import.py b/tests/test_csv_import.py index c3764920b..235487cd0 100644 --- a/tests/test_csv_import.py +++ b/tests/test_csv_import.py @@ -17,21 +17,18 @@ from __future__ import unicode_literals -import pytest - -import io import codecs +import io -from django.contrib.auth.hashers import make_password, check_password +import pytest +from django.contrib.auth.hashers import check_password, make_password from django.core import mail -from django_rbac.utils import get_role_model - +from authentic2.a2_rbac.utils import get_default_ou +from authentic2.csv_import import CsvHeader, CsvImporter, Error, LineError, UserCsvImporter from authentic2.custom_user.models import User from authentic2.models import Attribute -from authentic2.a2_rbac.utils import get_default_ou - -from authentic2.csv_import import CsvImporter, UserCsvImporter, CsvHeader, Error, LineError +from django_rbac.utils import get_role_model Role = get_role_model() diff --git a/tests/test_custom_user.py b/tests/test_custom_user.py index 00af792c0..8750a85ff 100644 --- a/tests/test_custom_user.py +++ b/tests/test_custom_user.py @@ -16,14 +16,13 @@ from datetime import date +import pytest from django.contrib.auth import get_user_model +from authentic2.custom_user.models import DeletedUser, User from authentic2.models import Attribute -from authentic2.custom_user.models import User, DeletedUser from django_rbac.utils import get_permission_model, get_role_model -import pytest - Permission = get_permission_model() Role = get_role_model() diff --git a/tests/test_customfields.py b/tests/test_customfields.py index 91c9137e9..dd589acc9 100644 --- a/tests/test_customfields.py +++ b/tests/test_customfields.py @@ -16,7 +16,7 @@ import pytest -from authentic2.saml.models import KeyValue, NAME_ID_FORMATS_CHOICES, SPOptionsIdPPolicy +from authentic2.saml.models import NAME_ID_FORMATS_CHOICES, KeyValue, SPOptionsIdPPolicy # Adaptation of http://djangosnippets.org/snippets/513/ diff --git a/tests/test_data_transfer.py b/tests/test_data_transfer.py index 1ee2b0fd8..aa46e49de 100644 --- a/tests/test_data_transfer.py +++ b/tests/test_data_transfer.py @@ -15,25 +15,22 @@ # along with this program. If not, see . import pytest - from django.core.exceptions import ValidationError -from django_rbac.utils import get_role_model, get_ou_model - from authentic2.a2_rbac.models import RoleParenting from authentic2.data_transfer import ( - export_site, ExportContext, - export_roles, - import_site, - export_ous, ImportContext, RoleDeserializer, - search_role, + export_ous, + export_roles, + export_site, import_ou, + import_site, + search_role, ) from authentic2.utils import get_hex_uuid - +from django_rbac.utils import get_ou_model, get_role_model Role = get_role_model() OU = get_ou_model() diff --git a/tests/test_fields.py b/tests/test_fields.py index beb6f2099..c04e36ac0 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -17,7 +17,6 @@ from __future__ import unicode_literals import pytest - from django.core.exceptions import ValidationError from authentic2.attribute_kinds import PhoneNumberField diff --git a/tests/test_idp_cas.py b/tests/test_idp_cas.py index 0e684d348..7dad7f4c2 100644 --- a/tests/test_idp_cas.py +++ b/tests/test_idp_cas.py @@ -15,16 +15,15 @@ # along with this program. If not, see . from django.contrib.auth import get_user_model -from django.test.client import RequestFactory, Client +from django.test.client import Client, RequestFactory from django.test.utils import override_settings from django.utils.encoding import force_text from django.utils.six.moves.urllib import parse as urlparse - -from authentic2_idp_cas.models import Ticket, Service, Attribute -from authentic2_idp_cas import constants -from authentic2.constants import AUTHENTICATION_EVENTS_SESSION_KEY, NONCE_FIELD_NAME from authentic2.a2_rbac.utils import get_default_ou +from authentic2.constants import AUTHENTICATION_EVENTS_SESSION_KEY, NONCE_FIELD_NAME +from authentic2_idp_cas import constants +from authentic2_idp_cas.models import Attribute, Service, Ticket from django_rbac.utils import get_role_model from .utils import Authentic2TestCase diff --git a/tests/test_idp_oidc.py b/tests/test_idp_oidc.py index 7ffb0a027..7e2dd057a 100644 --- a/tests/test_idp_oidc.py +++ b/tests/test_idp_oidc.py @@ -17,39 +17,32 @@ import base64 import datetime import functools -from importlib import import_module import json +from importlib import import_module import pytest - -from jwcrypto.jwt import JWT -from jwcrypto.jwk import JWKSet, JWK - -from . import utils - +from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.core.files import File from django.http import QueryDict from django.test.utils import override_settings from django.urls import reverse from django.utils.encoding import force_text -from django.utils.timezone import now -from django.contrib.auth import get_user_model from django.utils.six.moves.urllib import parse as urlparse +from django.utils.timezone import now +from jwcrypto.jwk import JWK, JWKSet +from jwcrypto.jwt import JWT - -from authentic2.models import Attribute, AuthorizedRole -from authentic2_idp_oidc.models import OIDCClient, OIDCAuthorization, OIDCCode, OIDCAccessToken, OIDCClaim -from authentic2_idp_oidc.utils import base64url -from authentic2_idp_oidc.utils import get_first_rsa_sig_key -from authentic2_idp_oidc.utils import get_first_ec_sig_key -from authentic2_idp_oidc.utils import make_sub -from authentic2_idp_oidc import app_settings from authentic2.a2_rbac.utils import get_default_ou -from authentic2.utils import make_url, good_next_url +from authentic2.models import Attribute, AuthorizedRole +from authentic2.utils import good_next_url, make_url from authentic2_auth_oidc.utils import parse_timestamp -from django_rbac.utils import get_ou_model -from django_rbac.utils import get_role_model +from authentic2_idp_oidc import app_settings +from authentic2_idp_oidc.models import OIDCAccessToken, OIDCAuthorization, OIDCClaim, OIDCClient, OIDCCode +from authentic2_idp_oidc.utils import base64url, get_first_ec_sig_key, get_first_rsa_sig_key, make_sub +from django_rbac.utils import get_ou_model, get_role_model + +from . import utils User = get_user_model() diff --git a/tests/test_idp_saml2.py b/tests/test_idp_saml2.py index 98931c387..9c2c25c4f 100644 --- a/tests/test_idp_saml2.py +++ b/tests/test_idp_saml2.py @@ -17,35 +17,33 @@ from __future__ import unicode_literals -import re -import datetime import base64 +import datetime import hashlib - +import re import xml.etree.ElementTree as ET -import pytest +import lasso import mock - +import pytest from django.contrib.auth import REDIRECT_FIELD_NAME from django.core.files import File -from django.template import Template, Context +from django.template import Context, Template from django.urls import reverse -from django.utils.translation import gettext as _ -from django.utils.encoding import force_text, force_str, force_bytes +from django.utils.encoding import force_bytes, force_str, force_text from django.utils.six.moves.urllib import parse as urlparse +from django.utils.translation import gettext as _ -from authentic2.saml import models as saml_models -from authentic2.a2_rbac.models import Role, OrganizationalUnit, RoleAttribute -from authentic2.utils import make_url +from authentic2.a2_rbac.models import OrganizationalUnit, Role, RoleAttribute from authentic2.constants import NONCE_FIELD_NAME, SERVICE_FIELD_NAME -from authentic2.models import Attribute, Service from authentic2.custom_user.models import User from authentic2.idp.saml import saml2_endpoints -from authentic2.saml.models import LibertyProvider, SAMLAttribute from authentic2.idp.saml.saml2_endpoints import get_extensions, get_login_hints_extension +from authentic2.models import Attribute, Service +from authentic2.saml import models as saml_models +from authentic2.saml.models import LibertyProvider, SAMLAttribute +from authentic2.utils import make_url -import lasso from . import utils diff --git a/tests/test_import_export_site_cmd.py b/tests/test_import_export_site_cmd.py index 14bf1fe19..030f4ad11 100644 --- a/tests/test_import_export_site_cmd.py +++ b/tests/test_import_export_site_cmd.py @@ -14,16 +14,15 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import random import json +import random +import pytest from django import VERSION +from django.core import management from django.core.exceptions import ValidationError - from django.utils import six from django.utils.six.moves import builtins as __builtin__ -from django.core import management -import pytest from django_rbac.utils import get_role_model diff --git a/tests/test_journal.py b/tests/test_journal.py index 7c79661c6..169c13f60 100644 --- a/tests/test_journal.py +++ b/tests/test_journal.py @@ -14,13 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from datetime import datetime, timedelta import random +from datetime import datetime, timedelta import mock import pytest import pytz - from django.contrib.auth import get_user_model from django.core.management import call_command from django.utils.timezone import make_aware, make_naive @@ -29,7 +28,7 @@ from authentic2.a2_rbac.models import OrganizationalUnit as OU from authentic2.a2_rbac.utils import get_default_ou from authentic2.apps.journal.forms import JournalForm from authentic2.apps.journal.journal import Journal -from authentic2.apps.journal.models import EventTypeDefinition, EventType, Event, clean_registry +from authentic2.apps.journal.models import Event, EventType, EventTypeDefinition, clean_registry from authentic2.models import Service User = get_user_model() diff --git a/tests/test_journal_app/views.py b/tests/test_journal_app/views.py index 72e33f206..9998bc893 100644 --- a/tests/test_journal_app/views.py +++ b/tests/test_journal_app/views.py @@ -15,7 +15,7 @@ # along with this program. If not, see . -from django.contrib.auth import get_user_model, login, authenticate +from django.contrib.auth import authenticate, get_user_model, login from django.http import HttpResponse from authentic2.apps.journal.journal import journal diff --git a/tests/test_large_userbase.py b/tests/test_large_userbase.py index c6c54bf54..daefabaa5 100644 --- a/tests/test_large_userbase.py +++ b/tests/test_large_userbase.py @@ -18,13 +18,11 @@ import faker import pytest - from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from authentic2.models import Attribute, AttributeValue - User = get_user_model() pytestmark = pytest.mark.slow diff --git a/tests/test_ldap.py b/tests/test_ldap.py index fb2d5524f..a4c1d75cc 100644 --- a/tests/test_ldap.py +++ b/tests/test_ldap.py @@ -17,31 +17,27 @@ import json import os - -import pytest -import mock import time import ldap -from ldap.dn import escape_dn_chars - -from ldaptools.slapd import Slapd, has_slapd +import mock +import pytest from django.contrib.auth import get_user_model +from django.core import mail, management from django.core.exceptions import ImproperlyConfigured -from django.core import management -from django.core import mail -from django.utils.encoding import force_bytes -from django.utils.encoding import force_text from django.utils import timezone +from django.utils.encoding import force_bytes, force_text from django.utils.six.moves.urllib import parse as urlparse +from ldap.dn import escape_dn_chars +from ldaptools.slapd import Slapd, has_slapd -from authentic2.models import Service +from authentic2 import crypto, models from authentic2.a2_rbac.models import Role from authentic2.a2_rbac.utils import get_default_ou -from django_rbac.utils import get_ou_model from authentic2.backends import ldap_backend +from authentic2.models import Service from authentic2.utils import authenticate -from authentic2 import crypto, models +from django_rbac.utils import get_ou_model from . import utils @@ -610,8 +606,9 @@ def test_group_staff(slapd, settings, client, db): def test_get_users(slapd, settings, db, monkeypatch, caplog): - import django.db.models.base from types import MethodType + + import django.db.models.base from django.contrib.auth.models import Group settings.LDAP_AUTH_SETTINGS = [ diff --git a/tests/test_login.py b/tests/test_login.py index 7addbe2e1..b4b8326c7 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -15,13 +15,12 @@ # along with this program. If not, see . import pytest - -from django.utils.six.moves.urllib.parse import quote from django.contrib.auth import get_user_model +from django.utils.six.moves.urllib.parse import quote from authentic2 import models -from .utils import login, check_log, assert_event +from .utils import assert_event, check_log, login User = get_user_model() diff --git a/tests/test_manager.py b/tests/test_manager.py index a03fe4201..ff67fb0b0 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -17,27 +17,24 @@ from __future__ import unicode_literals -import pytest import json +import pytest +from django.contrib.auth import get_user_model +from django.contrib.contenttypes.models import ContentType from django.core import mail from django.urls import reverse -from django.utils.encoding import force_str - +from django.utils.encoding import force_bytes, force_str +from django.utils.six.moves.urllib.parse import urlparse from webtest import Upload from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP from authentic2.a2_rbac.utils import get_default_ou from authentic2.validators import EmailValidator - -from django_rbac.utils import get_ou_model, get_role_model, get_permission_model, get_operation from django_rbac.models import VIEW_OP -from django.contrib.auth import get_user_model -from django.contrib.contenttypes.models import ContentType -from django.utils.encoding import force_bytes -from django.utils.six.moves.urllib.parse import urlparse -from .utils import login, get_link_from_mail, request_select2 +from django_rbac.utils import get_operation, get_ou_model, get_permission_model, get_role_model +from .utils import get_link_from_mail, login, request_select2 pytestmark = pytest.mark.django_db @@ -1003,12 +1000,12 @@ def test_manager_permission_inheritance(app, simple_user, admin, simple_role): def test_manager_widget_fields_validation(app, simple_user, simple_role): '''Verify that fields corresponding to widget implement queryset restrictions.''' from authentic2.manager.forms import ( - ChooseUserForm, ChooseRoleForm, - UsersForm, - RolesForm, + ChooseUserForm, ChooseUserRoleForm, RoleParentsForm, + RolesForm, + UsersForm, ) error_message = 'Select a valid choice' diff --git a/tests/test_manager_journal.py b/tests/test_manager_journal.py index b5a896d2e..9c992691d 100644 --- a/tests/test_manager_journal.py +++ b/tests/test_manager_journal.py @@ -15,19 +15,18 @@ # along with this program. If not, see . import datetime + import mock - -from authentic2.custom_user.models import User -from authentic2.a2_rbac.utils import get_default_ou -from authentic2.a2_rbac.models import Role -from authentic2.models import Service -from authentic2.apps.journal.models import Event, _registry -from authentic2.journal import journal - +import pytest from django.contrib.sessions.models import Session from django.utils.timezone import make_aware -import pytest +from authentic2.a2_rbac.models import Role +from authentic2.a2_rbac.utils import get_default_ou +from authentic2.apps.journal.models import Event, _registry +from authentic2.custom_user.models import User +from authentic2.journal import journal +from authentic2.models import Service from .utils import login, text_content diff --git a/tests/test_manager_user_import.py b/tests/test_manager_user_import.py index 80f62eda1..3f962d7f1 100644 --- a/tests/test_manager_user_import.py +++ b/tests/test_manager_user_import.py @@ -22,7 +22,7 @@ import operator import pytest -from authentic2.manager.user_import import UserImport, Report +from authentic2.manager.user_import import Report, UserImport from authentic2.models import Attribute diff --git a/tests/test_migrations.py b/tests/test_migrations.py index d55edec69..ed49e3d94 100644 --- a/tests/test_migrations.py +++ b/tests/test_migrations.py @@ -15,7 +15,6 @@ # along with this program. If not, see . import mock - from django.contrib.auth.models import AbstractUser from django.db.utils import ProgrammingError from django.utils.timezone import now diff --git a/tests/test_models.py b/tests/test_models.py index a2ac3fb21..850812a4a 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -19,8 +19,8 @@ from __future__ import unicode_literals import pytest -from authentic2.models import Attribute from authentic2.custom_user.models import User +from authentic2.models import Attribute def test_attribute_disabled(db): diff --git a/tests/test_natural_key.py b/tests/test_natural_key.py index f136f73d5..bd075df76 100644 --- a/tests/test_natural_key.py +++ b/tests/test_natural_key.py @@ -14,9 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . import pytest - from django.contrib.contenttypes.models import ContentType -from authentic2.a2_rbac.models import Role, OrganizationalUnit as OU, Permission + +from authentic2.a2_rbac.models import OrganizationalUnit as OU +from authentic2.a2_rbac.models import Permission, Role def test_natural_key_json(db, ou1): diff --git a/tests/test_profile.py b/tests/test_profile.py index c46aa79a2..0dc742103 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -19,7 +19,6 @@ from __future__ import unicode_literals import pytest - from django.urls import reverse from authentic2.a2_rbac.utils import get_default_ou diff --git a/tests/test_registration.py b/tests/test_registration.py index a0b5a39af..7107e3c60 100644 --- a/tests/test_registration.py +++ b/tests/test_registration.py @@ -17,17 +17,16 @@ from datetime import date -from django.contrib.auth import get_user_model, REDIRECT_FIELD_NAME +from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model from django.urls import reverse from django.utils.http import urlquote from django.utils.six.moves.urllib.parse import urlparse -from authentic2 import utils, models +from authentic2 import models, utils from authentic2.apps.journal.models import Event from authentic2.validators import EmailValidator -from .utils import get_link_from_mail, assert_event - +from .utils import assert_event, get_link_from_mail User = get_user_model() diff --git a/tests/test_role_manager.py b/tests/test_role_manager.py index 749a726ec..f85330264 100644 --- a/tests/test_role_manager.py +++ b/tests/test_role_manager.py @@ -16,13 +16,12 @@ import json +from django.utils.encoding import force_bytes, force_text from webtest import Upload -from django.utils.encoding import force_bytes, force_text - -from authentic2.custom_user.models import User -from authentic2.a2_rbac.models import Role, OrganizationalUnit +from authentic2.a2_rbac.models import OrganizationalUnit, Role from authentic2.a2_rbac.utils import get_default_ou +from authentic2.custom_user.models import User from .utils import login, text_content diff --git a/tests/test_saml_x509utils.py b/tests/test_saml_x509utils.py index f2cce460c..d44c06a22 100644 --- a/tests/test_saml_x509utils.py +++ b/tests/test_saml_x509utils.py @@ -17,12 +17,12 @@ from authentic2.saml.x509utils import ( can_generate_rsa_key_pair, - generate_rsa_keypair, check_key_pair_consistency, - get_xmldsig_rsa_key_value, - get_rsa_public_key_modulus, - get_rsa_public_key_exponent, decapsulate_pem_file, + generate_rsa_keypair, + get_rsa_public_key_exponent, + get_rsa_public_key_modulus, + get_xmldsig_rsa_key_value, ) diff --git a/tests/test_template.py b/tests/test_template.py index cbdbbc4e7..bad278dae 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -15,7 +15,6 @@ # along with this program. If not, see . import pytest - from django.urls import reverse from authentic2.a2_rbac.utils import get_default_ou diff --git a/tests/test_user_manager.py b/tests/test_user_manager.py index 30558a225..069aea8fc 100644 --- a/tests/test_user_manager.py +++ b/tests/test_user_manager.py @@ -24,31 +24,22 @@ import time from urllib.parse import urlparse import pytest -from webtest import Upload - from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.urls import reverse from django.utils.six import text_type +from webtest import Upload -from django_rbac.models import VIEW_OP -from django_rbac.utils import ( - get_operation, - get_ou_model, - get_permission_model, - get_role_model, -) - -from authentic2.custom_user.models import User -from authentic2.models import Attribute, AttributeValue -from authentic2.a2_rbac.utils import get_default_ou -from authentic2.a2_rbac.utils import get_view_user_perm -from authentic2.manager import user_import -from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient +from authentic2.a2_rbac.utils import get_default_ou, get_view_user_perm from authentic2.apps.journal.models import Event +from authentic2.custom_user.models import User +from authentic2.manager import user_import +from authentic2.models import Attribute, AttributeValue +from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient +from django_rbac.models import VIEW_OP +from django_rbac.utils import get_operation, get_ou_model, get_permission_model, get_role_model - -from .utils import login, get_link_from_mail, logout +from .utils import get_link_from_mail, login, logout OU = get_ou_model() @@ -1025,9 +1016,9 @@ def test_manager_user_authorizations(app, superuser, simple_user): * access user service consents page * try to remove a service consent """ - from django_rbac.utils import get_role_model, get_operation, get_permission_model - from django_rbac.models import VIEW_OP from authentic2.a2_rbac.models import MANAGE_AUTHORIZATIONS_OP + from django_rbac.models import VIEW_OP + from django_rbac.utils import get_operation, get_permission_model, get_role_model from tests.conftest import create_user Role = get_role_model() diff --git a/tests/test_user_model.py b/tests/test_user_model.py index a6f268081..27287d910 100644 --- a/tests/test_user_model.py +++ b/tests/test_user_model.py @@ -15,14 +15,14 @@ # along with this program. If not, see . # authentic2 -import pytest import datetime -from django.core.exceptions import ValidationError +import pytest from django.core import management +from django.core.exceptions import ValidationError from django.utils.timezone import now -from authentic2.custom_user.models import User, DeletedUser +from authentic2.custom_user.models import DeletedUser, User from authentic2.models import Attribute, AttributeValue, UserExternalId diff --git a/tests/test_utils.py b/tests/test_utils.py index a7e5d68bd..cc4d21264 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -16,25 +16,24 @@ # authentic2 from django.contrib.auth.middleware import AuthenticationMiddleware -from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.messages.middleware import MessageMiddleware +from django.contrib.sessions.middleware import SessionMiddleware from django.core import mail from django.utils.functional import lazy -from django_rbac.utils import get_ou_model - from authentic2.journal import Journal from authentic2.utils import ( + authenticate, + get_authentication_events, good_next_url, + login, same_origin, select_next_url, - user_can_change_password, - login, - get_authentication_events, - authenticate, send_templated_mail, + user_can_change_password, ) from authentic2.utils.lazy import lazy_join +from django_rbac.utils import get_ou_model def test_good_next_url(db, rf, settings): @@ -105,9 +104,10 @@ def test_get_authentication_events_hows(rf, simple_user): def test_remember_cookie(rf): - from authentic2.utils import get_remember_cookie, prepend_remember_cookie from django.http import HttpResponse + from authentic2.utils import get_remember_cookie, prepend_remember_cookie + request = rf.get('/') request.COOKIES['preferrence'] = '1 2' assert get_remember_cookie(request, 'preferrence') == [1, 2] diff --git a/tests/test_utils_evaluate.py b/tests/test_utils_evaluate.py index 4101dbb97..e6b9e1bcd 100644 --- a/tests/test_utils_evaluate.py +++ b/tests/test_utils_evaluate.py @@ -23,8 +23,8 @@ from authentic2.utils.evaluate import ( BaseExpressionValidator, ConditionValidator, ExpressionError, - evaluate_condition, HTTPHeaders, + evaluate_condition, ) diff --git a/tests/test_utils_lazy.py b/tests/test_utils_lazy.py index b326c4d8e..6f99eddbb 100644 --- a/tests/test_utils_lazy.py +++ b/tests/test_utils_lazy.py @@ -17,7 +17,6 @@ from __future__ import unicode_literals import pytest - from django.utils import six from authentic2.utils.lazy import lazy_join diff --git a/tests/test_validators.py b/tests/test_validators.py index 2f978b2b1..6c20e92f2 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -21,10 +21,9 @@ import smtplib import mock import pytest - from django.core.exceptions import ValidationError -from authentic2.validators import validate_password, EmailValidator +from authentic2.validators import EmailValidator, validate_password def test_validate_password(): diff --git a/tests/test_views.py b/tests/test_views.py index 9b90e2713..2bb31e963 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -16,14 +16,15 @@ # authentic2 import datetime -from .utils import login, logout, get_link_from_mail, assert_event -import pytest +import pytest from django.urls import reverse from django.utils.html import escape from django.utils.six.moves.urllib.parse import urlparse -from authentic2.custom_user.models import User, DeletedUser +from authentic2.custom_user.models import DeletedUser, User + +from .utils import assert_event, get_link_from_mail, login, logout pytestmark = pytest.mark.django_db diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 04acd48da..c495a9820 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -17,8 +17,7 @@ from pyquery import PyQuery -from authentic2.widgets import DateTimeWidget, DateWidget, TimeWidget -from authentic2.widgets import DatalistTextInput +from authentic2.widgets import DatalistTextInput, DateTimeWidget, DateWidget, TimeWidget def test_datetimepicker_init_and_render_no_locale(): diff --git a/tests/utils.py b/tests/utils.py index a48ae357c..a4a73b9bc 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -15,23 +15,22 @@ # along with this program. If not, see . # authentic2 -import re import base64 +import re import socket -from contextlib import contextmanager, closing +from contextlib import closing, contextmanager import httmock -from lxml import etree - from django.core.management import call_command as django_call_command +from django.shortcuts import resolve_url from django.test import TestCase from django.urls import reverse -from django.utils.encoding import iri_to_uri, force_text -from django.shortcuts import resolve_url from django.utils import six +from django.utils.encoding import force_text, iri_to_uri from django.utils.six.moves.urllib import parse as urlparse +from lxml import etree -from authentic2 import utils, models +from authentic2 import models, utils from authentic2.apps.journal.models import Event diff --git a/tests_rbac/test_rbac.py b/tests_rbac/test_rbac.py index f954b3e75..9a0032a34 100644 --- a/tests_rbac/test_rbac.py +++ b/tests_rbac/test_rbac.py @@ -16,14 +16,13 @@ import time +import pytest from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType -from django.test.utils import CaptureQueriesContext from django.db import connection +from django.test.utils import CaptureQueriesContext -from django_rbac import utils, models, backends - -import pytest +from django_rbac import backends, models, utils def test_role_parenting(db):