-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuring landing page for unauthenticated users (#808)
* allow configuring landing page * add tests
- Loading branch information
1 parent
36749c3
commit 5eadb3e
Showing
12 changed files
with
261 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 5.0.8 on 2024-08-31 12:39 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("bookmarks", "0036_userprofile_auto_tagging_rules"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="GlobalSettings", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"landing_page", | ||
models.CharField( | ||
choices=[ | ||
("login", "Login"), | ||
("shared_bookmarks", "Shared Bookmarks"), | ||
], | ||
default="login", | ||
max_length=50, | ||
), | ||
), | ||
], | ||
), | ||
] |
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
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
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from bookmarks.models import GlobalSettings | ||
from bookmarks.tests.helpers import BookmarkFactoryMixin | ||
|
||
|
||
class AnonymousViewTestCase(TestCase, BookmarkFactoryMixin): | ||
def test_unauthenticated_user_redirect_to_login_by_default(self): | ||
response = self.client.get(reverse("bookmarks:root")) | ||
self.assertRedirects(response, reverse("login")) | ||
|
||
def test_unauthenticated_redirect_to_shared_bookmarks_if_configured_in_global_settings( | ||
self, | ||
): | ||
settings = GlobalSettings.get() | ||
settings.landing_page = GlobalSettings.LANDING_PAGE_SHARED_BOOKMARKS | ||
settings.save() | ||
|
||
response = self.client.get(reverse("bookmarks:root")) | ||
self.assertRedirects(response, reverse("bookmarks:shared")) | ||
|
||
def test_authenticated_user_always_redirected_to_bookmarks(self): | ||
self.client.force_login(self.get_or_create_test_user()) | ||
|
||
response = self.client.get(reverse("bookmarks:root")) | ||
self.assertRedirects(response, reverse("bookmarks:index")) | ||
|
||
settings = GlobalSettings.get() | ||
settings.landing_page = GlobalSettings.LANDING_PAGE_SHARED_BOOKMARKS | ||
settings.save() | ||
|
||
response = self.client.get(reverse("bookmarks:root")) | ||
self.assertRedirects(response, reverse("bookmarks:index")) | ||
|
||
settings.landing_page = GlobalSettings.LANDING_PAGE_LOGIN | ||
settings.save() | ||
|
||
response = self.client.get(reverse("bookmarks:root")) | ||
self.assertRedirects(response, reverse("bookmarks:index")) |
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
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
from .toasts import * | ||
from .health import health | ||
from .manifest import manifest | ||
from .root import root |
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,18 @@ | ||
from django.http import HttpResponseRedirect | ||
from django.urls import reverse | ||
|
||
from bookmarks.models import GlobalSettings | ||
|
||
|
||
def root(request): | ||
# Redirect unauthenticated users to the configured landing page | ||
if not request.user.is_authenticated: | ||
settings = GlobalSettings.get() | ||
|
||
if settings.landing_page == GlobalSettings.LANDING_PAGE_SHARED_BOOKMARKS: | ||
return HttpResponseRedirect(reverse("bookmarks:shared")) | ||
else: | ||
return HttpResponseRedirect(reverse("login")) | ||
|
||
# Redirect authenticated users to the bookmarks page | ||
return HttpResponseRedirect(reverse("bookmarks:index")) |
Oops, something went wrong.