Skip to content

Commit

Permalink
[deps] Added support for Django 3.2 and Django 4.0a #280
Browse files Browse the repository at this point in the history
- Bumped django-allauth to 0.45.0
- Bumped django-reversion to use latest master branch

Closes #280
  • Loading branch information
pandafy committed Oct 27, 2021
1 parent 1c23395 commit f0b1a06
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 61 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ jobs:
django-version:
- django~=3.0.0
- django~=3.1.0
- django~=3.2.0
include:
- django-version: django~=4.0a1
python-version: 3.8
experimental: true

steps:
- uses: actions/checkout@v2
Expand Down
53 changes: 26 additions & 27 deletions openwisp_users/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,60 @@
from allauth import app_settings
from allauth.account import views
from allauth.socialaccount import providers
from django.conf.urls import include, url
from django.urls import reverse_lazy
from django.urls import include, path, re_path, reverse_lazy
from django.views.generic import RedirectView
from django.views.generic.base import TemplateView

redirect_view = RedirectView.as_view(url=reverse_lazy('admin:index'))


urlpatterns = [
url(r"^signup/$", redirect_view, name="account_signup"),
url(r"^login/$", views.login, name="account_login"),
url(r"^logout/$", views.logout, name="account_logout"),
url(r"^inactive/$", views.account_inactive, name="account_inactive"),
path('signup/', redirect_view, name='account_signup'),
path('login/', views.login, name='account_login'),
path('logout/', views.logout, name='account_logout'),
path('inactive/', views.account_inactive, name='account_inactive'),
# E-mail
url(
r"^confirm-email/$",
path(
'confirm-email/',
views.email_verification_sent,
name="account_email_verification_sent",
name='account_email_verification_sent',
),
url(
r"^confirm-email/(?P<key>[-:\w]+)/$",
re_path(
r'^confirm-email/(?P<key>[-:\w]+)/$',
views.confirm_email,
name="account_confirm_email",
name='account_confirm_email',
),
# password reset
url(r"^password/reset/$", views.password_reset, name="account_reset_password"),
url(
r"^password/reset/done/$",
path('password/reset/', views.password_reset, name='account_reset_password'),
path(
'password/reset/done/',
views.password_reset_done,
name="account_reset_password_done",
name='account_reset_password_done',
),
url(
r"^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$",
re_path(
r'^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$',
views.password_reset_from_key,
name="account_reset_password_from_key",
name='account_reset_password_from_key',
),
url(
r"^password/reset/key/done/$",
path(
'password/reset/key/done/',
views.password_reset_from_key_done,
name="account_reset_password_from_key_done",
name='account_reset_password_from_key_done',
),
url(
r"^email-verification-success/",
path(
'email-verification-success/',
TemplateView.as_view(template_name='account/email_verification_success.html'),
name='email_confirmation_success',
),
url(
r"^logout-success/",
path(
'logout-success/',
TemplateView.as_view(template_name='account/logout_success.html'),
name='logout_success',
),
]

if app_settings.SOCIALACCOUNT_ENABLED:
urlpatterns += [url(r'^social/', include('allauth.socialaccount.urls'))]
urlpatterns += [path('social/', include('allauth.socialaccount.urls'))]

for provider in providers.registry.get_list():
try:
Expand Down
2 changes: 1 addition & 1 deletion openwisp_users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext
from django.utils.translation import ugettext_lazy as _
from openwisp_utils.admin import UUIDAdmin
from organizations.base_admin import (
BaseOrganizationAdmin,
Expand Down
3 changes: 1 addition & 2 deletions openwisp_users/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.conf.urls import url
from django.urls import path

from openwisp_users import settings as app_settings
Expand Down Expand Up @@ -35,7 +34,7 @@ def get_api_urls(api_views=None):
]
if app_settings.USERS_AUTH_API:
urlpatterns += [
url(r'^user/token/', views.obtain_auth_token, name='user_auth_token')
path('user/token/', views.obtain_auth_token, name='user_auth_token')
]
return urlpatterns

Expand Down
3 changes: 2 additions & 1 deletion openwisp_users/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.core.exceptions import ValidationError
from django.db import IntegrityError, transaction
from django.db.models.signals import post_delete, post_save
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from openwisp_utils import settings as utils_settings
from openwisp_utils.admin_theme.menu import register_menu_group
from swapper import get_model_name, load_model
Expand All @@ -20,6 +20,7 @@ class OpenwispUsersConfig(AppConfig):
name = 'openwisp_users'
app_label = 'openwisp_users'
verbose_name = _('Users and Organizations')
default_auto_field = 'django.db.models.AutoField'

def ready(self):
self.register_menu_group()
Expand Down
2 changes: 1 addition & 1 deletion openwisp_users/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from phonenumber_field.modelfields import PhoneNumberField
from swapper import load_model

Expand Down
2 changes: 1 addition & 1 deletion openwisp_users/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from swapper import get_model_name


Expand Down
14 changes: 7 additions & 7 deletions openwisp_users/multitenancy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from swapper import load_model

User = get_user_model()
Expand Down Expand Up @@ -104,13 +104,13 @@ def multitenant_behaviour_for_user_admin(self, request):
"""
user = request.user
if not user.is_superuser:
org_users = OrganizationUser.objects.filter(user=user).select_related(
'organization'
qs = User.objects.filter(
**{
(
f'{User._meta.app_label}_organizationuser__organization__in'
): user.organizations_managed
}
)
qs = User.objects.none()
for org_user in org_users:
if org_user.is_admin:
qs = qs | org_user.organization.users.all().distinct()
# hide superusers from organization operators
# so they can't edit nor delete them
qs = qs.filter(is_superuser=False)
Expand Down
28 changes: 18 additions & 10 deletions openwisp_users/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def test_admin_change_user_auto_email(self):
params = user.__dict__
params['email'] = 'new@mail.com'
params.pop('phone_number')
params.pop('_password')
params.pop('password', None)
params.pop('_password', None)
params.pop('last_login')
params = self._additional_params_pop(params)
# inline emails
Expand Down Expand Up @@ -496,7 +497,8 @@ def test_update_user_no_validation_error(self):
params['username'] = 'user2'
params.pop('last_login')
params.pop('phone_number')
params.pop('_password')
params.pop('password', None)
params.pop('_password', None)
params = self._additional_params_pop(params)
params.update(self.add_user_inline_params)
params.update(
Expand Down Expand Up @@ -531,7 +533,8 @@ def test_edit_user_email_exists(self):
params = user.__dict__
params['email'] = 'test@tester.com'
params.pop('phone_number')
params.pop('_password')
params.pop('password', None)
params.pop('_password', None)
params.pop('last_login')
params = self._additional_params_pop(params)
params.update(self.add_user_inline_params)
Expand Down Expand Up @@ -560,7 +563,8 @@ def test_change_staff_without_group(self):
user = self._create_operator()
self._create_org_user(user=user)
params = user.__dict__
params.pop('_password')
params.pop('password', None)
params.pop('_password', None)
params.pop('last_login')
params.pop('phone_number')
params.update(self.add_user_inline_params)
Expand All @@ -584,7 +588,8 @@ def test_change_staff_with_group(self):
params = user.__dict__
params['groups'] = str(group.pk)
params.pop('phone_number')
params.pop('_password')
params.pop('password', None)
params.pop('_password', None)
params.pop('last_login')
params.update(self.add_user_inline_params)
params.update(self._additional_params_add())
Expand Down Expand Up @@ -648,7 +653,8 @@ def _test_change(self, options):
params['username'] = 'newuser1'
params['groups'] = str(group.pk)
params.pop('phone_number')
params.pop('_password')
params.pop('password', None)
params.pop('_password', None)
params.pop('last_login')
params.update(self.add_user_inline_params)
params.update(self._additional_params_add())
Expand Down Expand Up @@ -951,7 +957,7 @@ def test_organzation_change_inline_owner_present(self):
reverse(f'admin:{self.app_label}_organization_change', args=[org.pk])
)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Organization owners')
self.assertContains(response, 'Organization owner')

@patch.object(
OrganizationOwner, 'full_clean', side_effect=ValidationError('invalid')
Expand Down Expand Up @@ -1542,7 +1548,8 @@ def test_change_user(self):
params = user.__dict__
params['bio'] = 'Test change'
params.pop('phone_number')
params.pop('_password')
params.pop('password', None)
params.pop('_password', None)
params.pop('last_login')
params['birth_date'] = user.date_joined.date()
params = self._additional_params_pop(params)
Expand All @@ -1566,7 +1573,8 @@ def _delete_inline_org_user(self, is_admin=False):
self.client.force_login(admin)
params = user.__dict__
params.pop('phone_number')
params.pop('_password')
params.pop('password', None)
params.pop('_password', None)
params.pop('last_login')
params = self._additional_params_pop(params)
params.update(self._get_user_edit_form_inline_params(user, org))
Expand Down Expand Up @@ -1597,7 +1605,7 @@ def test_login_page(self):

with self.subTest('Test forgot password link'):
self.assertContains(
r, '<a href="/accounts/password/reset/">Forgot Password?</a>'
r, '<a href="/accounts/password/reset/">Forgot Password?</a'
)

with self.subTest('Test username label'):
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ openwisp-utils[qa]
mock>=2.0.0
redis>=3.4.1,<4.0.0
django-redis>=4.11.0,<5.0
django-reversion<=3.0.9
django-reversion @ https://github.com/etianen/django-reversion/tarball/c55c0ebb6333c6fb241cdcbd733b924e74ee4138
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
django-organizations>=1.0.0,<1.2.0
django-organizations @ https://github.com/pandafy/django-organizations/tarball/tag/1.1.2
django-extensions~=3.1.0
django-allauth~=0.44.0
django-allauth~=0.45.0
django-phonenumber-field>=4.0,<5.2
phonenumbers>=8.11.0,<8.13.0
# TODO: change this when next point version of openwisp-utils is released
openwisp-utils[rest] @ https://github.com/openwisp/openwisp-utils/tarball/master
packaging
swapper~=1.1.0
django~=3.1.0
5 changes: 5 additions & 0 deletions tests/openwisp2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,8 @@
from .local_settings import *
except ImportError:
pass

# Added for silencing warnings raised by django-all-auth
# on Django 3.2 and above. Remove when new version of
# django-all-auth is released
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
12 changes: 6 additions & 6 deletions tests/openwisp2/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os

from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import include, path

from openwisp_users.api.urls import get_api_urls

Expand All @@ -15,12 +15,12 @@
from .sample_users import views as api_views

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^accounts/', include('openwisp_users.accounts.urls')),
url(r'^api/v1/', include((get_api_urls(api_views), 'users'), namespace='users')),
url(r'^api/v1/', include('openwisp_utils.api.urls')),
path('admin/', admin.site.urls),
path('accounts/', include('openwisp_users.accounts.urls')),
path('api/v1/', include((get_api_urls(api_views), 'users'), namespace='users')),
path('api/v1/', include('openwisp_utils.api.urls')),
# Only for testing 'testapp'
url(r'^testing', include('testapp.urls')),
path('testing/', include('testapp.urls')),
]

urlpatterns += staticfiles_urlpatterns()
1 change: 1 addition & 0 deletions tests/testapp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
class TestAppConfig(AppConfig):
name = 'testapp'
label = 'testapp'
default_auto_field = 'django.db.models.AutoField'
2 changes: 1 addition & 1 deletion tests/testapp/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from openwisp_utils.base import TimeStampedEditableModel

from openwisp_users.mixins import OrgMixin, ShareableOrgMixin
Expand Down

0 comments on commit f0b1a06

Please sign in to comment.