From f4cde843c045784a1eecc154279f138767c16ae0 Mon Sep 17 00:00:00 2001 From: Dustin Steiner Date: Mon, 30 Jan 2023 14:40:33 +0000 Subject: [PATCH 01/22] chore: larger dropdown size for mobile devices --- .../snippets/shelve_button/shelve_button_dropdown.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html index 6ea30fadf..6187b2038 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html @@ -7,5 +7,5 @@ {% endblock %} {% block dropdown-list %} -{% include 'snippets/shelve_button/shelve_button_dropdown_options.html' with active_shelf=active_shelf shelves=user_shelves dropdown=True class="shelf-option is-fullwidth is-small is-radiusless has-background-body" %} +{% include 'snippets/shelve_button/shelve_button_dropdown_options.html' with active_shelf=active_shelf shelves=user_shelves dropdown=True class="shelf-option is-fullwidth is-small is-size-6-mobile is-radiusless has-background-body" %} {% endblock %} From f085315d70d7cbb7f772b51ef6cb8cce8d6f42a2 Mon Sep 17 00:00:00 2001 From: Giebisch Date: Mon, 30 Jan 2023 16:12:14 +0100 Subject: [PATCH 02/22] Added Backend Part --- bookwyrm/forms/status.py | 1 + .../migrations/0174_auto_20230130_1240.py | 26 +++++++++++++++++++ bookwyrm/models/status.py | 3 +++ .../snippets/create_status/quotation.html | 13 ++++++++++ .../snippets/status/content_status.html | 4 +-- 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 bookwyrm/migrations/0174_auto_20230130_1240.py diff --git a/bookwyrm/forms/status.py b/bookwyrm/forms/status.py index 0800166bf..b562595ee 100644 --- a/bookwyrm/forms/status.py +++ b/bookwyrm/forms/status.py @@ -53,6 +53,7 @@ class QuotationForm(CustomForm): "sensitive", "privacy", "position", + "endposition", "position_mode", ] diff --git a/bookwyrm/migrations/0174_auto_20230130_1240.py b/bookwyrm/migrations/0174_auto_20230130_1240.py new file mode 100644 index 000000000..1b81c2087 --- /dev/null +++ b/bookwyrm/migrations/0174_auto_20230130_1240.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.16 on 2023-01-30 12:40 + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ('bookwyrm', '0173_default_user_auth_group_setting'), + ] + + operations = [ + migrations.AddField( + model_name='quotation', + name='endposition', + field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)]), + ), + migrations.AlterField( + model_name='sitesettings', + name='default_user_auth_group', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='auth.group'), + ), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 19eab584d..d5dc8e9c1 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -329,6 +329,9 @@ class Quotation(BookStatus): position = models.IntegerField( validators=[MinValueValidator(0)], null=True, blank=True ) + endposition = models.IntegerField( + validators=[MinValueValidator(0)], null=True, blank=True + ) position_mode = models.CharField( max_length=3, choices=ProgressMode.choices, diff --git a/bookwyrm/templates/snippets/create_status/quotation.html b/bookwyrm/templates/snippets/create_status/quotation.html index a9ddb17f4..9cc76d5a9 100644 --- a/bookwyrm/templates/snippets/create_status/quotation.html +++ b/bookwyrm/templates/snippets/create_status/quotation.html @@ -65,6 +65,19 @@ uuid: a unique identifier used to make html "id" attributes unique and clarify j {% if not draft %}data-cache-draft="id_position_{{ book.id }}_{{ type }}"{% endif %} > +
+ +
{% endblock %} diff --git a/bookwyrm/templates/snippets/status/content_status.html b/bookwyrm/templates/snippets/status/content_status.html index e39284fcf..4c4d89341 100644 --- a/bookwyrm/templates/snippets/status/content_status.html +++ b/bookwyrm/templates/snippets/status/content_status.html @@ -99,9 +99,9 @@ — {% include 'snippets/book_titleby.html' with book=status.book %} {% if status.position %} {% if status.position_mode == 'PG' %} - {% blocktrans with page=status.position|intcomma %}(Page {{ page }}){% endblocktrans %} + {% blocktrans with page=status.position|intcomma %}(Page {{ page }}{% endblocktrans%}{% if status.endposition%} - {% blocktrans with endpage=status.endposition|intcomma %}{{ endpage }}{% endblocktrans %}{% endif%}) {% else %} - {% blocktrans with percent=status.position %}({{ percent }}%){% endblocktrans %} + {% blocktrans with percent=status.position %}({{ percent }}%{% endblocktrans %}{% if status.endposition%}{% blocktrans with endpercent=status.endposition|intcomma %} - {{ endpercent }}%{% endblocktrans %}{% endif %}) {% endif %} {% endif %}

From f30a0ae7143c0a9ededbd2454fe1aeaaaacb7771 Mon Sep 17 00:00:00 2001 From: Dustin Steiner Date: Tue, 31 Jan 2023 08:12:57 +0000 Subject: [PATCH 03/22] chore: more dropdown resizes --- bookwyrm/templates/snippets/report_button.html | 2 +- bookwyrm/templates/snippets/shelf_selector.html | 6 +++--- bookwyrm/templates/snippets/status/status_options.html | 10 +++++----- bookwyrm/templates/snippets/user_options.html | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bookwyrm/templates/snippets/report_button.html b/bookwyrm/templates/snippets/report_button.html index 60b542f43..92d70699c 100644 --- a/bookwyrm/templates/snippets/report_button.html +++ b/bookwyrm/templates/snippets/report_button.html @@ -5,7 +5,7 @@ {% join "report" report_uuid as modal_id %} @@ -91,7 +91,7 @@ {% csrf_token %} - + {% endif %} diff --git a/bookwyrm/templates/snippets/status/status_options.html b/bookwyrm/templates/snippets/status/status_options.html index f47967551..e12d6e1d6 100644 --- a/bookwyrm/templates/snippets/status/status_options.html +++ b/bookwyrm/templates/snippets/status/status_options.html @@ -13,7 +13,7 @@ {% endif %} {% endblock %} diff --git a/bookwyrm/templates/snippets/user_options.html b/bookwyrm/templates/snippets/user_options.html index 35abc98c2..7923e3d27 100644 --- a/bookwyrm/templates/snippets/user_options.html +++ b/bookwyrm/templates/snippets/user_options.html @@ -11,13 +11,13 @@ {% block dropdown-list %}
  • - {% include 'snippets/report_button.html' with user=user class="is-fullwidth" %} + {% include 'snippets/report_button.html' with user=user class="is-fullwidth is-size-6-mobile" %}
  • - {% include 'snippets/block_button.html' with user=user class="is-fullwidth" blocks=False %} + {% include 'snippets/block_button.html' with user=user class="is-fullwidth is-size-6-mobile" blocks=False %}
  • {% endblock %} From 96097f3b583f48189d5aaa16e53cd030461d83f9 Mon Sep 17 00:00:00 2001 From: Dustin Steiner Date: Tue, 31 Jan 2023 18:33:44 +0000 Subject: [PATCH 04/22] chore: use bulma override for mobile dropdown instead of classes --- .../bookwyrm/overrides/_bulma_overrides.scss | 120 +++++++++--------- .../templates/snippets/shelf_selector.html | 6 +- .../shelve_button/shelve_button_dropdown.html | 2 +- .../snippets/status/status_options.html | 10 +- bookwyrm/templates/snippets/user_options.html | 6 +- 5 files changed, 75 insertions(+), 69 deletions(-) diff --git a/bookwyrm/static/css/bookwyrm/overrides/_bulma_overrides.scss b/bookwyrm/static/css/bookwyrm/overrides/_bulma_overrides.scss index cdcd74202..a8768328e 100644 --- a/bookwyrm/static/css/bookwyrm/overrides/_bulma_overrides.scss +++ b/bookwyrm/static/css/bookwyrm/overrides/_bulma_overrides.scss @@ -1,111 +1,117 @@ .summary-on-open { - display: none; + display: none; } @media only screen and (max-width: 768px) { - .navbar-menu { - text-align: right; - padding-right: 1rem; + .navbar-menu { + text-align: right; + padding-right: 1rem; - .tags { - justify-content: flex-end; - } + .tags { + justify-content: flex-end; + } - #navbar-dropdown { - &[open] { - .summary-on-open { - display: initial; - position: fixed; - top: 0; - left: 0; - right: 0; - height: 3rem; - z-index: 31; - background-color: $dropdown-content-background-color; - padding: 1rem 1.75rem; - line-height: 1; - } - } + #navbar-dropdown { + &[open] { + .summary-on-open { + display: initial; + position: fixed; + top: 0; + left: 0; + right: 0; + height: 3rem; + z-index: 31; + background-color: $dropdown-content-background-color; + padding: 1rem 1.75rem; + line-height: 1; + } + } - .dropdown-menu { - padding-top: 0; - top: 3rem; - } + .dropdown-menu { + padding-top: 0; + top: 3rem; + } - .dropdown-content { - padding-top: 0; - box-shadow: none; - border-top-left-radius: 0; - border-top-right-radius: 0; - } + .dropdown-content { + padding-top: 0; + box-shadow: none; + border-top-left-radius: 0; + border-top-right-radius: 0; + } - .navbar-item { - // see ../components/_details.scss :: Navbar details - padding-right: 1.75rem; - font-size: 1rem; - } - } - } + .navbar-item { + // see ../components/_details.scss :: Navbar details + padding-right: 1.75rem; + font-size: 1rem; + } + } + } } .image { - overflow: hidden; + overflow: hidden; } .navbar .logo { - max-height: 50px; + max-height: 50px; } .card { - overflow: visible; + overflow: visible; } .card.has-border { - border: 1px solid $border; + border: 1px solid $border; } .scroll-x { - overflow: hidden; - overflow-x: auto; + overflow: hidden; + overflow-x: auto; } .modal-card { - pointer-events: none; + pointer-events: none; } .modal-card > * { - pointer-events: all; + pointer-events: all; } /* stylelint-disable no-descending-specificity */ .modal-card:focus { - outline-style: auto; + outline-style: auto; } .modal-card:focus:not(:focus-visible) { - outline-style: initial; + outline-style: initial; } .modal-card:focus-visible { - outline-style: auto; + outline-style: auto; } /* stylelint-enable no-descending-specificity */ .modal-card.is-fullwidth { - min-width: 75% !important; + min-width: 75% !important; } @media only screen and (min-width: 769px) { - .modal-card.is-thin { - width: 350px !important; - } + .modal-card.is-thin { + width: 350px !important; + } } .modal-card-body { - max-height: 70vh; + max-height: 70vh; } .clip-text { - max-height: 35em; - overflow: hidden; + max-height: 35em; + overflow: hidden; +} + +@include mobile { + .dropdown-menu .button { + font-size: $size-6; + } } diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html index 2a17e7d58..902a66196 100644 --- a/bookwyrm/templates/snippets/shelf_selector.html +++ b/bookwyrm/templates/snippets/shelf_selector.html @@ -31,7 +31,7 @@ {% else%} {% comparison_bool shelf.identifier active_shelf.shelf.identifier as is_current %} -{% with button_class="is-fullwidth is-small is-size-6-mobile shelf-option is-radiusless has-background-body" %} +{% with button_class="is-fullwidth is-small shelf-option is-radiusless has-background-body" %} {% endif %} diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html index 6187b2038..6ea30fadf 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html @@ -7,5 +7,5 @@ {% endblock %} {% block dropdown-list %} -{% include 'snippets/shelve_button/shelve_button_dropdown_options.html' with active_shelf=active_shelf shelves=user_shelves dropdown=True class="shelf-option is-fullwidth is-small is-size-6-mobile is-radiusless has-background-body" %} +{% include 'snippets/shelve_button/shelve_button_dropdown_options.html' with active_shelf=active_shelf shelves=user_shelves dropdown=True class="shelf-option is-fullwidth is-small is-radiusless has-background-body" %} {% endblock %} diff --git a/bookwyrm/templates/snippets/status/status_options.html b/bookwyrm/templates/snippets/status/status_options.html index e12d6e1d6..f47967551 100644 --- a/bookwyrm/templates/snippets/status/status_options.html +++ b/bookwyrm/templates/snippets/status/status_options.html @@ -13,7 +13,7 @@ {% endif %} {% endblock %} diff --git a/bookwyrm/templates/snippets/user_options.html b/bookwyrm/templates/snippets/user_options.html index 7923e3d27..35abc98c2 100644 --- a/bookwyrm/templates/snippets/user_options.html +++ b/bookwyrm/templates/snippets/user_options.html @@ -11,13 +11,13 @@ {% block dropdown-list %}
  • - {% include 'snippets/report_button.html' with user=user class="is-fullwidth is-size-6-mobile" %} + {% include 'snippets/report_button.html' with user=user class="is-fullwidth" %}
  • - {% include 'snippets/block_button.html' with user=user class="is-fullwidth is-size-6-mobile" blocks=False %} + {% include 'snippets/block_button.html' with user=user class="is-fullwidth" blocks=False %}
  • {% endblock %} From 610a4e8a66447d542262c871334340ee09223422 Mon Sep 17 00:00:00 2001 From: Dustin Steiner Date: Tue, 31 Jan 2023 18:44:09 +0000 Subject: [PATCH 05/22] chore: run styling --- .../bookwyrm/overrides/_bulma_overrides.scss | 122 +++++++++--------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/bookwyrm/static/css/bookwyrm/overrides/_bulma_overrides.scss b/bookwyrm/static/css/bookwyrm/overrides/_bulma_overrides.scss index a8768328e..9ab44f89d 100644 --- a/bookwyrm/static/css/bookwyrm/overrides/_bulma_overrides.scss +++ b/bookwyrm/static/css/bookwyrm/overrides/_bulma_overrides.scss @@ -1,117 +1,117 @@ .summary-on-open { - display: none; + display: none; } @media only screen and (max-width: 768px) { - .navbar-menu { - text-align: right; - padding-right: 1rem; + .navbar-menu { + text-align: right; + padding-right: 1rem; - .tags { - justify-content: flex-end; - } + .tags { + justify-content: flex-end; + } - #navbar-dropdown { - &[open] { - .summary-on-open { - display: initial; - position: fixed; - top: 0; - left: 0; - right: 0; - height: 3rem; - z-index: 31; - background-color: $dropdown-content-background-color; - padding: 1rem 1.75rem; - line-height: 1; - } - } + #navbar-dropdown { + &[open] { + .summary-on-open { + display: initial; + position: fixed; + top: 0; + left: 0; + right: 0; + height: 3rem; + z-index: 31; + background-color: $dropdown-content-background-color; + padding: 1rem 1.75rem; + line-height: 1; + } + } - .dropdown-menu { - padding-top: 0; - top: 3rem; - } + .dropdown-menu { + padding-top: 0; + top: 3rem; + } - .dropdown-content { - padding-top: 0; - box-shadow: none; - border-top-left-radius: 0; - border-top-right-radius: 0; - } + .dropdown-content { + padding-top: 0; + box-shadow: none; + border-top-left-radius: 0; + border-top-right-radius: 0; + } - .navbar-item { - // see ../components/_details.scss :: Navbar details - padding-right: 1.75rem; - font-size: 1rem; - } - } - } + .navbar-item { + /* see ../components/_details.scss :: Navbar details */ + padding-right: 1.75rem; + font-size: 1rem; + } + } + } } .image { - overflow: hidden; + overflow: hidden; } .navbar .logo { - max-height: 50px; + max-height: 50px; } .card { - overflow: visible; + overflow: visible; } .card.has-border { - border: 1px solid $border; + border: 1px solid $border; } .scroll-x { - overflow: hidden; - overflow-x: auto; + overflow: hidden; + overflow-x: auto; } .modal-card { - pointer-events: none; + pointer-events: none; } .modal-card > * { - pointer-events: all; + pointer-events: all; } /* stylelint-disable no-descending-specificity */ .modal-card:focus { - outline-style: auto; + outline-style: auto; } .modal-card:focus:not(:focus-visible) { - outline-style: initial; + outline-style: initial; } .modal-card:focus-visible { - outline-style: auto; + outline-style: auto; } /* stylelint-enable no-descending-specificity */ .modal-card.is-fullwidth { - min-width: 75% !important; + min-width: 75% !important; } @media only screen and (min-width: 769px) { - .modal-card.is-thin { - width: 350px !important; - } + .modal-card.is-thin { + width: 350px !important; + } } .modal-card-body { - max-height: 70vh; + max-height: 70vh; } .clip-text { - max-height: 35em; - overflow: hidden; + max-height: 35em; + overflow: hidden; } -@include mobile { - .dropdown-menu .button { - font-size: $size-6; - } +.dropdown-menu .button { + @include mobile { + font-size: $size-6; + } } From 36605efd206610fdd64283b5caec3f5662195ada Mon Sep 17 00:00:00 2001 From: Robert George Date: Wed, 1 Feb 2023 12:59:10 -0800 Subject: [PATCH 06/22] Added support for secure cookies and django-csp --- bookwyrm/settings.py | 9 +++++++++ bookwyrm/templates/guided_tour/book.html | 2 +- bookwyrm/templates/guided_tour/group.html | 2 +- bookwyrm/templates/guided_tour/home.html | 2 +- bookwyrm/templates/guided_tour/lists.html | 2 +- bookwyrm/templates/guided_tour/search.html | 2 +- bookwyrm/templates/guided_tour/user_books.html | 2 +- bookwyrm/templates/guided_tour/user_groups.html | 2 +- bookwyrm/templates/guided_tour/user_profile.html | 2 +- bookwyrm/templates/layout.html | 2 +- bookwyrm/templates/ostatus/template.html | 4 ++-- .../templates/settings/dashboard/registration_chart.html | 2 +- bookwyrm/templates/settings/dashboard/status_chart.html | 2 +- bookwyrm/templates/settings/dashboard/user_chart.html | 2 +- bookwyrm/templates/settings/dashboard/works_chart.html | 2 +- bookwyrm/views/admin/dashboard.py | 3 +++ requirements.txt | 1 + 17 files changed, 28 insertions(+), 15 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 61240dbfa..abd71b2dd 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -101,6 +101,7 @@ MIDDLEWARE = [ "django.middleware.locale.LocaleMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", + "csp.middleware.CSPMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "bookwyrm.middleware.TimezoneMiddleware", "bookwyrm.middleware.IPBlocklistMiddleware", @@ -335,6 +336,8 @@ PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) PROTOCOL = "http" if USE_HTTPS: PROTOCOL = "https" + SESSION_COOKIE_SECURE = True + CSRF_COOKIE_SECURE = True USE_S3 = env.bool("USE_S3", False) @@ -358,11 +361,17 @@ if USE_S3: MEDIA_FULL_URL = MEDIA_URL STATIC_FULL_URL = STATIC_URL DEFAULT_FILE_STORAGE = "bookwyrm.storage_backends.ImagesStorage" + CSP_DEFAULT_SRC = ("'self'", AWS_S3_CUSTOM_DOMAIN) + CSP_SCRIPT_SRC = ("'self'", AWS_S3_CUSTOM_DOMAIN) else: STATIC_URL = "/static/" MEDIA_URL = "/images/" MEDIA_FULL_URL = f"{PROTOCOL}://{DOMAIN}{MEDIA_URL}" STATIC_FULL_URL = f"{PROTOCOL}://{DOMAIN}{STATIC_URL}" + CSP_DEFAULT_SRC = ("'self'") + CSP_SCRIPT_SRC = ("'self'") + +CSP_INCLUDE_NONCE_IN=['script-src'] OTEL_EXPORTER_OTLP_ENDPOINT = env("OTEL_EXPORTER_OTLP_ENDPOINT", None) OTEL_EXPORTER_OTLP_HEADERS = env("OTEL_EXPORTER_OTLP_HEADERS", None) diff --git a/bookwyrm/templates/guided_tour/book.html b/bookwyrm/templates/guided_tour/book.html index 44a37f65e..a0d60e831 100644 --- a/bookwyrm/templates/guided_tour/book.html +++ b/bookwyrm/templates/guided_tour/book.html @@ -1,6 +1,6 @@ {% load i18n %} - diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index eb904a693..25d2430c0 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -11,7 +11,7 @@ {% block title %}{% endblock %} - diff --git a/bookwyrm/templates/settings/dashboard/registration_chart.html b/bookwyrm/templates/settings/dashboard/registration_chart.html index 3b258fec8..bb51ed8bc 100644 --- a/bookwyrm/templates/settings/dashboard/registration_chart.html +++ b/bookwyrm/templates/settings/dashboard/registration_chart.html @@ -1,5 +1,5 @@ {% load i18n %} -