Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import GroupAdmin, UserAdmin | ||
from django.contrib.auth.models import Group, User | ||
from django.shortcuts import redirect | ||
from django.urls import reverse | ||
|
||
from accounts.settings import accounts_settings | ||
|
||
|
||
class LabsAdminSite(admin.AdminSite): | ||
|
||
def login(self, request, extra_context=None): | ||
if not request.user.is_authenticated: | ||
return redirect(reverse('accounts:login') + '?next=' + request.GET.get('next')) | ||
return super().login(request, extra_context) | ||
|
||
|
||
if accounts_settings.CUSTOM_ADMIN: | ||
admin.site = LabsAdminSite() | ||
admin.site.register(Group, GroupAdmin) | ||
admin.site.register(User, UserAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
|
||
class AppsTestCase(TestCase): | ||
def test_admin_not_logged_in(self): | ||
response = self.client.get(reverse('admin:login') + '?next=/admin/') | ||
redirect = '/accounts/login/?next=/admin/' | ||
self.assertRedirects(response, redirect, fetch_redirect_response=False) | ||
|
||
def test_admin_logged_in(self): | ||
get_user_model().objects.create_user(username='user', password='password', is_staff=True) | ||
self.client.login(username='user', password='password') | ||
response = self.client.get(reverse('admin:login') + '?next=/admin/') | ||
redirect = '/admin/' | ||
self.assertRedirects(response, redirect, fetch_redirect_response=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
|
||
|
||
urlpatterns = [path('accounts/', include('accounts.urls', namespace='accounts'))] | ||
urlpatterns = [ | ||
path('accounts/', include('accounts.urls', namespace='accounts')), | ||
path('admin/', admin.site.urls), | ||
] |