From 610bcefd250dcb5a4ece4ff9af40465ab377421a Mon Sep 17 00:00:00 2001 From: Deimos Date: Thu, 14 Feb 2019 15:43:22 -0700 Subject: [PATCH] Allow logged-out users to browse the site This is messy in a few ways and needs some reworking, but should be fine for testing and initial enabling public visibility. An invite is still required for registration, and the registration page isn't even currently linked anywhere since people should usually get a registration link as the invite. May roll this back and/or do follow-up commits if it makes the site break. --- tildes/scss/modules/_site-footer.scss | 12 +++ tildes/scss/themes/_theme_base.scss | 13 +--- tildes/tildes/auth.py | 27 +------ tildes/tildes/templates/base.jinja2 | 20 +++++ tildes/tildes/templates/error_403.jinja2 | 36 ++------- tildes/tildes/templates/home.jinja2 | 76 +++++++++++-------- .../tildes/templates/macros/comments.jinja2 | 11 +++ tildes/tildes/templates/macros/user.jinja2 | 42 +++++----- .../templates/notifications_unread.jinja2 | 2 +- tildes/tildes/templates/topic.jinja2 | 2 +- tildes/tildes/templates/topic_listing.jinja2 | 2 +- tildes/tildes/templates/user.jinja2 | 2 +- tildes/tildes/views/topic.py | 37 +++++---- tildes/tildes/views/user.py | 2 +- 14 files changed, 150 insertions(+), 134 deletions(-) diff --git a/tildes/scss/modules/_site-footer.scss b/tildes/scss/modules/_site-footer.scss index d9c6924..a421d06 100644 --- a/tildes/scss/modules/_site-footer.scss +++ b/tildes/scss/modules/_site-footer.scss @@ -37,3 +37,15 @@ margin-left: 1rem; } } + +.site-footer-theme-selection { + font-style: normal; + margin-bottom: 1rem; + + select { + width: auto; + font-size: 0.6rem; + height: 1.4rem; + padding: 0 0 0 0.2rem; + } +} diff --git a/tildes/scss/themes/_theme_base.scss b/tildes/scss/themes/_theme_base.scss index 2ea6f7e..3095190 100644 --- a/tildes/scss/themes/_theme_base.scss +++ b/tildes/scss/themes/_theme_base.scss @@ -61,12 +61,6 @@ } } - a.logged-in-user-username:visited, - a.site-header-context:visited, - a.site-header-logo:visited { - color: unset; - } - @include syntax-highlighting($is-light); blockquote { @@ -299,7 +293,7 @@ @include theme-special-label(map-get($theme, "topic-tag-spoiler"), $is-light); } - .logged-in-user-username { + .logged-in-user-username, .logged-in-user-username:visited { color: map-get($theme, "foreground-primary"); } @@ -346,12 +340,11 @@ background-color: map-get($theme, "background-primary"); } - .site-header-context, - .site-header-username { + .site-header-context, .site-header-context:visited { color: map-get($theme, "foreground-primary"); } - .site-header-logo { + .site-header-logo, .site-header-logo:visited { color: map-get($theme, "foreground-highlight"); } diff --git a/tildes/tildes/auth.py b/tildes/tildes/auth.py index 226c2e2..e5d4766 100644 --- a/tildes/tildes/auth.py +++ b/tildes/tildes/auth.py @@ -10,7 +10,7 @@ from pyramid.authorization import ACLAuthorizationPolicy from pyramid.config import Configurator from pyramid.httpexceptions import HTTPFound from pyramid.request import Request -from pyramid.security import ACLDenied, ACLPermitsResult, Allow, Authenticated, Everyone +from pyramid.security import Allow, Everyone from tildes.models.user import User @@ -72,11 +72,7 @@ def includeme(config: Configurator) -> None: # default permission config.set_root_factory(DefaultRootFactory) - # Set the authorization policy to a custom one that always returns a "denied" result - # if the user isn't logged in. When overall site access is no longer being - # restricted, the AuthorizedOnlyPolicy class can just be replaced with the standard - # ACLAuthorizationPolicy - config.set_authorization_policy(AuthorizedOnlyPolicy()) + config.set_authorization_policy(ACLAuthorizationPolicy()) config.set_authentication_policy( SessionAuthenticationPolicy(callback=auth_callback) @@ -92,25 +88,6 @@ def includeme(config: Configurator) -> None: config.add_request_method(has_any_permission, "has_any_permission") -class AuthorizedOnlyPolicy(ACLAuthorizationPolicy): - """ACLAuthorizationPolicy override that always denies logged-out users.""" - - def permits( - self, context: Any, principals: Sequence[Any], permission: str - ) -> ACLPermitsResult: - """Deny logged-out users, otherwise pass up to normal policy.""" - if Authenticated not in principals: - return ACLDenied( - "", - "", - permission, - principals, - context, - ) - - return super().permits(context, principals, permission) - - def has_any_permission( request: Request, permissions: Sequence[str], context: Any ) -> bool: diff --git a/tildes/tildes/templates/base.jinja2 b/tildes/tildes/templates/base.jinja2 index f947771..22d16a5 100644 --- a/tildes/tildes/templates/base.jinja2 +++ b/tildes/tildes/templates/base.jinja2 @@ -90,6 +90,26 @@