diff --git a/tildes/alembic/versions/347859b0355e_added_account_default_theme_setting.py b/tildes/alembic/versions/347859b0355e_added_account_default_theme_setting.py new file mode 100644 index 0000000..1495b25 --- /dev/null +++ b/tildes/alembic/versions/347859b0355e_added_account_default_theme_setting.py @@ -0,0 +1,24 @@ +"""Added account default theme setting + +Revision ID: 347859b0355e +Revises: 3fbddcba0e3b +Create Date: 2018-08-11 16:23:13.297883 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "347859b0355e" +down_revision = "3fbddcba0e3b" +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column("users", sa.Column("theme_default", sa.Text())) + + +def downgrade(): + op.drop_column("users", "theme_default") diff --git a/tildes/scss/modules/_form.scss b/tildes/scss/modules/_form.scss index c179059..876bda3 100644 --- a/tildes/scss/modules/_form.scss +++ b/tildes/scss/modules/_form.scss @@ -38,6 +38,10 @@ select.form-select:not([multiple]) { } } +.form-buttons.no-reverse { + flex-direction: row; +} + textarea.form-input { height: 8rem; line-height: 1.5; @@ -74,6 +78,20 @@ textarea.form-input { } } +.form-oneline { + display: flex; + font-size: 0.6rem; + margin-bottom: 0.4rem; + + .form-oneline-item { + flex: 2; + } + + .form-oneline-item-double { + flex: 4; + } +} + .form-search .form-input { margin-right: 0.4rem; } diff --git a/tildes/static/js/behaviors/theme-selector.js b/tildes/static/js/behaviors/theme-selector.js index 33f1501..d1c8383 100644 --- a/tildes/static/js/behaviors/theme-selector.js +++ b/tildes/static/js/behaviors/theme-selector.js @@ -2,7 +2,13 @@ $.onmount('[data-js-theme-selector]', function() { $(this).change(function(event) { event.preventDefault(); + // hide any IC change message + $(this).parent().find('.form-status').hide(); + var new_theme = $(this).val(); + var selected_text = $(this).find('option:selected').text(); + var $setDefaultLink = $('#button-set-default-theme'); + var $formDefaultValue = $('#input-set-default-theme'); // persist the new theme for the user in their cookie document.cookie = 'theme=' + new_theme + ';' + @@ -22,5 +28,15 @@ $.onmount('[data-js-theme-selector]', function() { if (new_theme) { $body.addClass('theme-' + new_theme); } + + // set the IC hidden input with the new value + $formDefaultValue.val(new_theme); + + // set visibility of 'Set as account default' link + if (selected_text.indexOf('(account default)') !== -1) { + $setDefaultLink.css('visibility', 'hidden'); + } else { + $setDefaultLink.css('visibility', 'visible'); + } }); }); diff --git a/tildes/tests/conftest.py b/tildes/tests/conftest.py index ea6da3d..ddc1d9c 100644 --- a/tildes/tests/conftest.py +++ b/tildes/tests/conftest.py @@ -199,7 +199,15 @@ def webtest(base_app): # create the TestApp - note that specifying wsgi.url_scheme is necessary so that the # secure cookies from the session library will work app = TestApp( - base_app, extra_environ={"wsgi.url_scheme": "https"}, cookiejar=CookieJar() + base_app, + # This "tm.active" is a temporary fix around this fixture failing to rollback + # data after the tests are complete (it effectively deactivates pyramid_tm). + extra_environ={ + "wsgi.url_scheme": "https", + "tm.active": True, + "REMOTE_ADDR": "0.0.0.0", + }, + cookiejar=CookieJar(), ) # fetch the login page, fill in the form, and submit it (sets the cookie) diff --git a/tildes/tests/webtests/test_user_settings.py b/tildes/tests/webtests/test_user_settings.py new file mode 100644 index 0000000..6e61358 --- /dev/null +++ b/tildes/tests/webtests/test_user_settings.py @@ -0,0 +1,7 @@ +def test_render_theme_options(webtest): + """Test that theme settings are being rendered.""" + settings = webtest.get("/settings") + assert settings.status_int == 200 + assert settings.text.count("(site and account default)") == 1 + assert "(site default)" not in settings.text + assert "(account default)" not in settings.text diff --git a/tildes/tildes/models/user/user.py b/tildes/tildes/models/user/user.py index a18b24f..683a245 100644 --- a/tildes/tildes/models/user/user.py +++ b/tildes/tildes/models/user/user.py @@ -87,6 +87,7 @@ class User(DatabaseModel): Boolean, nullable=False, server_default="false" ) open_new_tab_text: bool = Column(Boolean, nullable=False, server_default="false") + theme_default: str = Column(Text) is_banned: bool = Column(Boolean, nullable=False, server_default="false") permissions: Any = Column(JSONB) home_default_order: Optional[TopicSortOption] = Column(ENUM(TopicSortOption)) diff --git a/tildes/tildes/templates/base.jinja2 b/tildes/tildes/templates/base.jinja2 index e299d41..274fd56 100644 --- a/tildes/tildes/templates/base.jinja2 +++ b/tildes/tildes/templates/base.jinja2 @@ -38,6 +38,8 @@ {% block body_tag %} {% if request.cookies.get('theme', '') %} + {% elif request.user and request.user.theme_default %} + {% else %} {% endif %} diff --git a/tildes/tildes/templates/base_no_sidebar.jinja2 b/tildes/tildes/templates/base_no_sidebar.jinja2 index 728a98a..8d98d78 100644 --- a/tildes/tildes/templates/base_no_sidebar.jinja2 +++ b/tildes/tildes/templates/base_no_sidebar.jinja2 @@ -3,6 +3,8 @@ {% block body_tag %} {% if request.cookies.get('theme', '') %} + {% elif request.user and request.user.theme_default %} + {% else %} {% endif %} diff --git a/tildes/tildes/templates/settings.jinja2 b/tildes/tildes/templates/settings.jinja2 index fbdc4a6..bfe4b5d 100644 --- a/tildes/tildes/templates/settings.jinja2 +++ b/tildes/tildes/templates/settings.jinja2 @@ -8,14 +8,37 @@