Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch Us Up to Upstream #57

Merged
merged 174 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
da4214a
feat: add OAuth authentication
SMillerDev Nov 14, 2023
e144ce1
fix: add include import from django.urls
SMillerDev Nov 16, 2023
b7ba6f1
urls.py: fix style
SMillerDev Nov 30, 2023
5d09c54
Merge branch 'main' into feat/api/oauth
SMillerDev Dec 7, 2023
eb13eb9
Invalidate `active_shelf` when switching editions
dato Jan 13, 2024
cbd0812
initial work on fixing user exports with s3
hughrun Jan 14, 2024
62cc6c2
oops
hughrun Jan 14, 2024
d4d2734
ignore exports dir
hughrun Jan 14, 2024
833f26f
Merge branch 'main' into user-export
hughrun Jan 18, 2024
4691729
cleanup and linting
hughrun Jan 18, 2024
26c37de
linting
hughrun Jan 19, 2024
accb327
When determining privacy, check for unlisted early
dato Jan 26, 2024
629acba
add series number on posts in the feed
bSolt Jan 27, 2024
6add81c
move outside of authors "if"
bSolt Jan 27, 2024
2bb9a85
various fixes
hughrun Jan 28, 2024
0d619f7
Merge branch 'main' into user-export
hughrun Jan 28, 2024
582e97e
Merge branch 'image-serialize' into user-export
hughrun Jan 28, 2024
a3e0525
fix avatar import path
hughrun Jan 28, 2024
2c231ac
linting and tests
hughrun Jan 28, 2024
c106b2a
Subclass boto3.Session to use AWS_S3_ENDPOINT_URL
dato Jan 29, 2024
765fc1e
fix tests
hughrun Jan 29, 2024
adff3c4
allow user exports with s3
hughrun Jan 29, 2024
f96ddaa
Merge pull request #3 from dato/export_job_inject_aws_endpoint_setting
hughrun Jan 29, 2024
5f7be84
subclass boto3 session instead of adding new env value
hughrun Jan 29, 2024
3675a4c
disable user exports if using azure
hughrun Jan 29, 2024
6ac3856
Add wikidata field for authors
ccamara Feb 3, 2024
71f527e
Merge branch 'main' into wikidata
ccamara Feb 4, 2024
89d8537
Add wikidata field to author's template
ccamara Feb 5, 2024
0282e20
Merge branch 'main' into book-series-3256
BartSchuurmans Mar 16, 2024
1b9e054
Bracket-wrap calls to `patch()` for better readability
dato Mar 17, 2024
4b9fe0a
Remove nesting in several with..patch calls
dato Mar 17, 2024
e2c9ea3
Fix instances of `bad-classmethod-argument` in recently edited files
dato Mar 17, 2024
90bd893
Fix remaining instances of `bad-classmethod-argument`
dato Mar 18, 2024
518da3b
Merge from main into 'user-export'
dato Mar 18, 2024
a6dc5bd
Make `get_file_size` robust against typing errors
dato Mar 18, 2024
7484185
docker-compose.yml: mount static_volume for flower
BartSchuurmans Mar 18, 2024
3367b20
Font download: destination dir is allowed to exist
BartSchuurmans Mar 18, 2024
7690247
Font download: log the exact error
BartSchuurmans Mar 18, 2024
864304f
docker-compose.yml: make all bind mounts read only
BartSchuurmans Mar 18, 2024
68cb94d
docker-compose.yml: don't automatically start dev-tools by assigning …
BartSchuurmans Mar 18, 2024
4d23edd
Make sure /images/ and /static/ exist now that the bind mount is read…
BartSchuurmans Mar 18, 2024
e13e423
black: specify required-version
BartSchuurmans Mar 20, 2024
ab430e0
requirements.txt: add black
BartSchuurmans Mar 20, 2024
b5b9edd
CI: relax black version constraints
BartSchuurmans Mar 20, 2024
682bb3b
dev-tools: relax black version constraint
BartSchuurmans Mar 21, 2024
3cde6db
Merge pull request #3326 from Minnozz/black-required-version
BartSchuurmans Mar 21, 2024
c3d25c5
Escape search query in generated URLs
BartSchuurmans Mar 21, 2024
20db968
Merge pull request #3322 from Minnozz/fix-font-download
mouse-reeve Mar 23, 2024
21f75da
Merge pull request #3328 from Minnozz/escape-query-in-link
mouse-reeve Mar 23, 2024
886d6ec
Merge branch 'main' into docker-bind-ro
mouse-reeve Mar 23, 2024
b508b4c
Merge pull request #3323 from Minnozz/docker-bind-ro
mouse-reeve Mar 23, 2024
8e088a6
Merge branch 'main' into switch_edition_invalidate_active_shelves
mouse-reeve Mar 23, 2024
a914a44
Removes unnecessary redeclaration of wikidata model field in Author
mouse-reeve Mar 23, 2024
5b71e94
Merge branch 'main' into user-export
mouse-reeve Mar 23, 2024
8bbac45
Merge pull request #3217 from dato/switch_edition_invalidate_active_s…
mouse-reeve Mar 23, 2024
bac52ee
Merge pull request #3275 from ccamara/wikidata
mouse-reeve Mar 23, 2024
2de35f3
Calculate Author search vector with name and aliases
BartSchuurmans Mar 20, 2024
0795b4d
Include Author aliases in Book search vector
BartSchuurmans Mar 20, 2024
36222af
Switch author search from TrigramSimilarity to SearchQuery
BartSchuurmans Mar 19, 2024
769d972
Add book search test cases for author aliases
BartSchuurmans Mar 22, 2024
b8995bd
Add tests for author search
BartSchuurmans Mar 22, 2024
b3753ab
Add MergedBookDataModel
BartSchuurmans Feb 28, 2024
5e12397
BookDataModel: implement merge_into method
BartSchuurmans Feb 22, 2024
e04cd79
Redirect to new URL when a merged object is requested
BartSchuurmans Mar 1, 2024
7066e28
BookDataModel.merge_into: return and log absorbed fields
BartSchuurmans Mar 2, 2024
7fb079c
PartialDate: fix __eq__ method
BartSchuurmans Mar 5, 2024
6f191ac
BookDataModel: fix absorbing data from array and partial date fields
BartSchuurmans Mar 5, 2024
fb82c7a
Add test for merging authors
BartSchuurmans Mar 5, 2024
4a690e6
BookDataModel: add dry_run argument to merge_into
BartSchuurmans Mar 5, 2024
2d2ccd5
Factor out book series info into separate template
BartSchuurmans Mar 23, 2024
2915133
Merge branch 'main' into book-series-3256
BartSchuurmans Mar 23, 2024
592914d
Render series number with comma and outside of link on book page
BartSchuurmans Mar 23, 2024
caebebe
Merge pull request #3261 from bSolt/book-series-3256
BartSchuurmans Mar 23, 2024
dd27684
set signed s3 url expiry with env value
hughrun Mar 24, 2024
03587df
migrations
hughrun Mar 24, 2024
7c2fa74
Revert "docker-compose.yml: make all bind mounts read only"
BartSchuurmans Mar 24, 2024
f11c801
Merge pull request #3331 from Minnozz/revert-docker-mount-ro
BartSchuurmans Mar 24, 2024
69f4644
Remove problematic migration
BartSchuurmans Mar 24, 2024
a770689
Merge branch 'main' into user-export
BartSchuurmans Mar 24, 2024
073f62d
Add exports_volume to docker-compose.yml
BartSchuurmans Mar 24, 2024
471233c
Use different export job fields for the different storage backends
BartSchuurmans Mar 24, 2024
ab7b089
User exports: handle files that no longer exist on file storage
BartSchuurmans Mar 24, 2024
5bd66cb
Only generate signed S3 link to user export when user clicks download
BartSchuurmans Mar 24, 2024
aee8dc1
Fix pylint warning
BartSchuurmans Mar 24, 2024
e0decbf
Fix urlescaped relative path to cover image in export
BartSchuurmans Mar 25, 2024
a514022
Refactor creation of user export archive
BartSchuurmans Mar 25, 2024
f721289
Simplify logic for rendering user exports
BartSchuurmans Mar 25, 2024
bd95bcd
Add test for special character in cover filename
BartSchuurmans Mar 25, 2024
d9bf848
Fix pylint warnings
BartSchuurmans Mar 25, 2024
7192449
Merge pull request #3325 from Minnozz/author-search-vector
mouse-reeve Mar 25, 2024
011e4a2
Updates locales and adds missing trimmed on blocktrans
mouse-reeve Mar 25, 2024
bf52eea
Bump version to 0.7.3.
mouse-reeve Mar 25, 2024
9dfa218
Merge pull request #3333 from bookwyrm-social/locales
mouse-reeve Mar 25, 2024
6a67943
Merge branch 'main' into user-export
BartSchuurmans Mar 26, 2024
145c67d
Merge BookwyrmExportJob export_data field back into one with dynamic …
BartSchuurmans Mar 26, 2024
ef57c0b
Check last user export too in post handler
BartSchuurmans Mar 26, 2024
ed2e9e5
Merge migration
BartSchuurmans Mar 26, 2024
9860044
Remove twitter from README.md
ccamara Mar 26, 2024
9685ae5
Consolidate BookwyrmExportJob into two tasks
BartSchuurmans Mar 26, 2024
9afd0eb
Update migrations
BartSchuurmans Mar 27, 2024
699d637
Fix detection of `unlisted` posts (#3258)
dato Mar 27, 2024
797d5cb
Update BookwyrmExportJob tests
BartSchuurmans Mar 27, 2024
c6ca547
Fix migration formatting
BartSchuurmans Mar 27, 2024
3133a47
Merge from main into 'better-fmt-patch-calls'
dato Mar 27, 2024
cdbc1d1
Fix double exports subdir in S3 user export
BartSchuurmans Mar 27, 2024
dabf7c6
User export testing fixes
BartSchuurmans Mar 28, 2024
bb5d815
Fix mypy error
BartSchuurmans Mar 28, 2024
2bbe3d4
Test user export archive contents
BartSchuurmans Mar 28, 2024
2272e7a
flower 2.0.1 fixes a few link bugs (particularly for favicon)
Mar 29, 2024
1464d09
Merge pull request #3320 from dato/better-fmt-patch-calls
BartSchuurmans Mar 29, 2024
e74de94
Merge pull request #3334 from ccamara/patch-1
BartSchuurmans Mar 29, 2024
0ac9d12
Merge branch 'main' into user-export
BartSchuurmans Mar 29, 2024
5d597f1
Use new "with ()" style
BartSchuurmans Mar 29, 2024
e7ae0fd
Merge pull request #3337 from prolibre/apport-perso
BartSchuurmans Mar 29, 2024
75bc4f8
Make nginx config safer
BartSchuurmans Mar 29, 2024
ffee29d
Fix resource leaks
BartSchuurmans Mar 29, 2024
fcd0087
[FIX] make sure to get Pillow>=10 compatible pilkit
hbrunn Mar 30, 2024
f666951
Update CodeQL workflows to v3
BartSchuurmans Mar 30, 2024
72ed878
Merge pull request #3343 from Minnozz/update-codeql
BartSchuurmans Mar 30, 2024
cb3fd0c
Merge branch 'main' into feat/api/oauth
mouse-reeve Mar 31, 2024
f28800a
Merge pull request #3339 from Minnozz/fix-file-leaks
mouse-reeve Mar 31, 2024
d5fb21f
Merge branch 'main' into feat/api/oauth
SMillerDev Apr 1, 2024
4bbdd0b
Add index on Status.remote_id
BartSchuurmans Apr 2, 2024
f085d3d
Merge pull request #3346 from Minnozz/status-remote-id-index
mouse-reeve Apr 2, 2024
ea0ade9
Bump pillow from 10.2.0 to 10.3.0
dependabot[bot] Apr 3, 2024
d1d91f0
Merge pull request #3347 from bookwyrm-social/dependabot/pip/pillow-1…
mouse-reeve Apr 3, 2024
5082806
Merge pull request #3338 from Minnozz/fix-nginx-location
BartSchuurmans Apr 3, 2024
5cfe7ec
Add index for finding all statuses in a thread
BartSchuurmans Apr 3, 2024
4d5a30d
Add index for looking up KeyPair by remote id
BartSchuurmans Apr 3, 2024
0501ce3
Add index for looking up User by username
BartSchuurmans Apr 3, 2024
464a029
Add index for finding active (and local) users
BartSchuurmans Apr 3, 2024
321397a
Specify which column DISTINCT should apply to
BartSchuurmans Apr 3, 2024
439cb3c
Remove unnecessary conversions between list and set
BartSchuurmans Apr 4, 2024
e1c54b2
Remove optimizations with adverse effects
BartSchuurmans Apr 4, 2024
ca6dbcb
Merge pull request #3348 from Minnozz/more-indexes
mouse-reeve Apr 4, 2024
7363033
Merge pull request #3299 from Minnozz/absorb
mouse-reeve Apr 9, 2024
af0bd90
Adds merge migration
mouse-reeve Apr 9, 2024
3ffbb24
Black
mouse-reeve Apr 9, 2024
b6aba44
Merge pull request #3355 from bookwyrm-social/merge-migration
mouse-reeve Apr 9, 2024
9d9e643
Install same version of eslint in CI as in dev-tools
BartSchuurmans Apr 10, 2024
5686c5a
Merge pull request #3356 from Minnozz/quick-fix-frontend-ci
BartSchuurmans Apr 10, 2024
26f92db
Merge branch 'main' into main-pilkit
BartSchuurmans Apr 11, 2024
d5a536a
Change pilkit constraint to the version that does work
BartSchuurmans Apr 11, 2024
7d58175
Merge pull request #3342 from hbrunn/main-pilkit
BartSchuurmans Apr 11, 2024
501fb45
export avatars to own directory
hughrun Apr 13, 2024
d48d312
Merge branch 'main' into user-export
hughrun Apr 13, 2024
c3c4614
add merge migration
hughrun Apr 13, 2024
21a39f8
Merge pull request #3228 from hughrun/user-export
BartSchuurmans Apr 13, 2024
f844abc
test_quotation_page_serialization: use strings for page numbers
dato Apr 8, 2024
df78cc6
Quotation._format_position: do not treat page numbers as integers
dato Apr 8, 2024
8733369
test_quotation_page_serialization: add test with no position
dato Apr 8, 2024
4304cd4
use re.escape
dato Apr 9, 2024
70f803a
Merge pull request #3353 from dato/fix_quotation_str_pagenum
BartSchuurmans Apr 15, 2024
be872ed
Support AWS_S3_URL_PROTOCOL
BartSchuurmans Mar 27, 2024
bf5c08d
Add docker-compose.override.yml to .gitignore
BartSchuurmans Mar 27, 2024
cca5802
Bump aiohttp from 3.9.2 to 3.9.4
dependabot[bot] Apr 18, 2024
6684d60
refactor Move for more redundancy
hughrun Apr 22, 2024
0312231
Clarify AWS_S3_URL_PROTOCOL in .env.example
BartSchuurmans Apr 24, 2024
637f19b
Merge pull request #3336 from Minnozz/s3-url-protocol
BartSchuurmans Apr 24, 2024
839ab2f
Merge branch 'main' into move-fix
BartSchuurmans Apr 24, 2024
f24fdf7
Update to match newer code style
BartSchuurmans Apr 24, 2024
3d183a3
Merge pull request #3360 from hughrun/move-fix
BartSchuurmans Apr 24, 2024
c73d1ff
Remove unnecessary exceptions from validate_url_domain
BartSchuurmans Apr 2, 2024
baea105
pytest.ini env values should be unquoted
BartSchuurmans Apr 2, 2024
3aefbb5
Allow serving BookWyrm on a non-standard port
BartSchuurmans Apr 7, 2024
c42db40
Construct absolute URLs with the correct protocol and port
BartSchuurmans Apr 7, 2024
609bc15
Support http:// protocol in BookWyrm connector
BartSchuurmans Apr 7, 2024
4f58b11
Include the correct protocol and port in remote IDs
BartSchuurmans Apr 7, 2024
366c647
Merge pull request #3359 from bookwyrm-social/dependabot/pip/aiohttp-…
mouse-reeve Apr 24, 2024
ad830dd
Merge pull request #3350 from Minnozz/custom-port
mouse-reeve Apr 24, 2024
c4b21ee
Merge pull request #3114 from SMillerDev/feat/api/oauth
mouse-reeve Apr 24, 2024
33b67ba
Add privileges to codeql-analysis.yml
MaggieFero Aug 16, 2023
4c20182
Bump versions on libraries (#10)
phildini Aug 17, 2023
0371cef
Merge branch 'main' into bookwyrm-social-main
MaggieFero May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ DEFAULT_LANGUAGE="English"
## Leave unset to allow all hosts
# ALLOWED_HOSTS="localhost,127.0.0.1,[::1]"

# Specify when the site is served from a port that is not the default
# for the protocol (80 for HTTP or 443 for HTTPS).
# Probably only necessary in development.
# PORT=1333

MEDIA_ROOT=images/

# Database configuration
Expand Down Expand Up @@ -71,14 +76,20 @@ ENABLE_THUMBNAIL_GENERATION=true
USE_S3=false
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
# seconds for signed S3 urls to expire
# this is currently only used for user export files
S3_SIGNED_URL_EXPIRY=900

# Commented are example values if you use a non-AWS, S3-compatible service
# AWS S3 should work with only AWS_STORAGE_BUCKET_NAME and AWS_S3_REGION_NAME
# non-AWS S3-compatible services will need AWS_STORAGE_BUCKET_NAME,
# along with both AWS_S3_CUSTOM_DOMAIN and AWS_S3_ENDPOINT_URL
# along with both AWS_S3_CUSTOM_DOMAIN and AWS_S3_ENDPOINT_URL.
# AWS_S3_URL_PROTOCOL must end in ":" and defaults to the same protocol as
# the BookWyrm instance ("http:" or "https:", based on USE_SSL).

# AWS_STORAGE_BUCKET_NAME= # "example-bucket-name"
# AWS_S3_CUSTOM_DOMAIN=None # "example-bucket-name.s3.fr-par.scw.cloud"
# AWS_S3_URL_PROTOCOL=None # "http:"
# AWS_S3_REGION_NAME=None # "fr-par"
# AWS_S3_ENDPOINT_URL=None # "https://s3.fr-par.scw.cloud"

Expand Down Expand Up @@ -133,9 +144,9 @@ HTTP_X_FORWARDED_PROTO=false
TWO_FACTOR_LOGIN_VALIDITY_WINDOW=2
TWO_FACTOR_LOGIN_MAX_SECONDS=60

# Additional hosts to allow in the Content-Security-Policy, "self" (should be DOMAIN)
# and AWS_S3_CUSTOM_DOMAIN (if used) are added by default.
# Value should be a comma-separated list of host names.
# Additional hosts to allow in the Content-Security-Policy, "self" (should be
# DOMAIN with optionally ":" + PORT) and AWS_S3_CUSTOM_DOMAIN (if used) are
# added by default. Value should be a comma-separated list of host names.
CSP_ADDITIONAL_HOSTS=

# Time before being logged out (in seconds)
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,7 +54,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +68,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
3 changes: 2 additions & 1 deletion .github/workflows/lint-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
- uses: actions/checkout@v4

- name: Install modules
run: npm install stylelint stylelint-config-recommended stylelint-config-standard stylelint-order eslint
# run: npm install stylelint stylelint-config-recommended stylelint-config-standard stylelint-order eslint
run: npm install eslint@^8.9.0

# See .stylelintignore for files that are not linted.
# - name: Run stylelint
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: psf/black@22.12.0
- uses: psf/black@stable
with:
version: 22.12.0
version: "22.*"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# BookWyrm
.env
/images/
/exports/
/static/
bookwyrm/static/css/bookwyrm.css
bookwyrm/static/css/themes/
!bookwyrm/static/css/themes/bookwyrm-*.scss
Expand All @@ -36,3 +38,6 @@ nginx/default.conf

#macOS
**/.DS_Store

# Docker
docker-compose.override.yml
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ BookWyrm is a social network for tracking your reading, talking about books, wri
## Links

[![Mastodon Follow](https://img.shields.io/mastodon/follow/000146121?domain=https%3A%2F%2Ftech.lgbt&style=social)](https://tech.lgbt/@bookwyrm)
[![Twitter Follow](https://img.shields.io/twitter/follow/BookWyrmSocial?style=social)](https://twitter.com/BookWyrmSocial)

- [Project homepage](https://joinbookwyrm.com/)
- [Support](https://patreon.com/bookwyrm)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.2
0.7.3
14 changes: 5 additions & 9 deletions bookwyrm/activitystreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ def _get_audience(self, status): # pylint: disable=no-self-use
| (
Q(following=status.user) & Q(following=status.reply_parent.user)
) # if the user is following both authors
).distinct()
)

# only visible to the poster's followers and tagged users
elif status.privacy == "followers":
audience = audience.filter(
Q(following=status.user) # if the user is following the author
)
return audience.distinct()
return audience.distinct("id")

@tracer.start_as_current_span("ActivityStream.get_audience")
def get_audience(self, status):
Expand All @@ -156,7 +156,7 @@ def get_audience(self, status):
status_author = models.User.objects.filter(
is_active=True, local=True, id=status.user.id
).values_list("id", flat=True)
return list(set(list(audience) + list(status_author)))
return list(set(audience) | set(status_author))

def get_stores_for_users(self, user_ids):
"""convert a list of user ids into redis store ids"""
Expand All @@ -183,15 +183,13 @@ class HomeStream(ActivityStream):
def get_audience(self, status):
trace.get_current_span().set_attribute("stream_id", self.key)
audience = super()._get_audience(status)
if not audience:
return []
# if the user is following the author
audience = audience.filter(following=status.user).values_list("id", flat=True)
# if the user is the post's author
status_author = models.User.objects.filter(
is_active=True, local=True, id=status.user.id
).values_list("id", flat=True)
return list(set(list(audience) + list(status_author)))
return list(set(audience) | set(status_author))

def get_statuses_for_user(self, user):
return models.Status.privacy_filter(
Expand Down Expand Up @@ -239,9 +237,7 @@ def _get_audience(self, status):
)

audience = super()._get_audience(status)
if not audience:
return models.User.objects.none()
return audience.filter(shelfbook__book__parent_work=work).distinct()
return audience.filter(shelfbook__book__parent_work=work)

def get_audience(self, status):
# only show public statuses on the books feed,
Expand Down
15 changes: 8 additions & 7 deletions bookwyrm/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Do further startup configuration and initialization"""

import os
import urllib
import logging
Expand All @@ -14,16 +15,16 @@ def download_file(url, destination):
"""Downloads a file to the given path"""
try:
# Ensure our destination directory exists
os.makedirs(os.path.dirname(destination))
os.makedirs(os.path.dirname(destination), exist_ok=True)
with urllib.request.urlopen(url) as stream:
with open(destination, "b+w") as outfile:
outfile.write(stream.read())
except (urllib.error.HTTPError, urllib.error.URLError):
logger.info("Failed to download file %s", url)
except OSError:
logger.info("Couldn't open font file %s for writing", destination)
except: # pylint: disable=bare-except
logger.info("Unknown error in file download")
except (urllib.error.HTTPError, urllib.error.URLError) as err:
logger.error("Failed to download file %s: %s", url, err)
except OSError as err:
logger.error("Couldn't open font file %s for writing: %s", destination, err)
except Exception as err: # pylint:disable=broad-except
logger.error("Unknown error in file download: %s", err)


class BookwyrmConfig(AppConfig):
Expand Down
19 changes: 12 additions & 7 deletions bookwyrm/connectors/connector_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,22 @@ def get_connectors() -> Iterator[abstract_connector.AbstractConnector]:
def get_or_create_connector(remote_id: str) -> abstract_connector.AbstractConnector:
"""get the connector related to the object's server"""
url = urlparse(remote_id)
identifier = url.netloc
identifier = url.hostname
if not identifier:
raise ValueError("Invalid remote id")
raise ValueError(f"Invalid remote id: {remote_id}")

base_url = f"{url.scheme}://{url.netloc}"

try:
connector_info = models.Connector.objects.get(identifier=identifier)
except models.Connector.DoesNotExist:
connector_info = models.Connector.objects.create(
identifier=identifier,
connector_file="bookwyrm_connector",
base_url=f"https://{identifier}",
books_url=f"https://{identifier}/book",
covers_url=f"https://{identifier}/images/covers",
search_url=f"https://{identifier}/search?q=",
base_url=base_url,
books_url=f"{base_url}/book",
covers_url=f"{base_url}/images/covers",
search_url=f"{base_url}/search?q=",
priority=2,
)

Expand Down Expand Up @@ -188,8 +190,11 @@ def raise_not_valid_url(url: str) -> None:
if not parsed.scheme in ["http", "https"]:
raise ConnectorException("Invalid scheme: ", url)

if not parsed.hostname:
raise ConnectorException("Hostname missing: ", url)

try:
ipaddress.ip_address(parsed.netloc)
ipaddress.ip_address(parsed.hostname)
raise ConnectorException("Provided url is an IP address: ", url)
except ValueError:
# it's not an IP address, which is good
Expand Down
3 changes: 2 additions & 1 deletion bookwyrm/emailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from bookwyrm import models, settings
from bookwyrm.tasks import app, EMAIL
from bookwyrm.settings import DOMAIN
from bookwyrm.settings import DOMAIN, BASE_URL


def email_data():
Expand All @@ -14,6 +14,7 @@ def email_data():
"site_name": site.name,
"logo": site.logo_small_url,
"domain": DOMAIN,
"base_url": BASE_URL,
"user": None,
}

Expand Down
2 changes: 2 additions & 0 deletions bookwyrm/forms/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Meta:
"aliases",
"bio",
"wikipedia_link",
"wikidata",
"website",
"born",
"died",
Expand All @@ -32,6 +33,7 @@ class Meta:
"wikipedia_link": forms.TextInput(
attrs={"aria-describedby": "desc_wikipedia_link"}
),
"wikidata": forms.TextInput(attrs={"aria-describedby": "desc_wikidata"}),
"website": forms.TextInput(attrs={"aria-describedby": "desc_website"}),
"born": forms.SelectDateWidget(attrs={"aria-describedby": "desc_born"}),
"died": forms.SelectDateWidget(attrs={"aria-describedby": "desc_died"}),
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/forms/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def clean(self):
url = cleaned_data.get("url")
filetype = cleaned_data.get("filetype")
book = cleaned_data.get("book")
domain = urlparse(url).netloc
domain = urlparse(url).hostname
if models.LinkDomain.objects.filter(domain=domain).exists():
status = models.LinkDomain.objects.get(domain=domain).status
if status == "blocked":
Expand Down
37 changes: 25 additions & 12 deletions bookwyrm/management/commands/deduplicate_book_data.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
""" PROCEED WITH CAUTION: uses deduplication fields to permanently
merge book data objects """

from django.core.management.base import BaseCommand
from django.db.models import Count
from bookwyrm import models
from bookwyrm.management.merge import merge_objects


def dedupe_model(model):
def dedupe_model(model, dry_run=False):
"""combine duplicate editions and update related models"""
print(f"deduplicating {model.__name__}:")
fields = model._meta.get_fields()
dedupe_fields = [
f for f in fields if hasattr(f, "deduplication_field") and f.deduplication_field
Expand All @@ -16,30 +17,42 @@ def dedupe_model(model):
dupes = (
model.objects.values(field.name)
.annotate(Count(field.name))
.filter(**{"%s__count__gt" % field.name: 1})
.filter(**{f"{field.name}__count__gt": 1})
.exclude(**{field.name: ""})
.exclude(**{f"{field.name}__isnull": True})
)

for dupe in dupes:
value = dupe[field.name]
if not value or value == "":
continue
print("----------")
print(dupe)
objs = model.objects.filter(**{field.name: value}).order_by("id")
canonical = objs.first()
print("keeping", canonical.remote_id)
action = "would merge" if dry_run else "merging"
print(
f"{action} into {model.__name__} {canonical.remote_id} based on {field.name} {value}:"
)
for obj in objs[1:]:
print(obj.remote_id)
merge_objects(canonical, obj)
print(f"- {obj.remote_id}")
absorbed_fields = obj.merge_into(canonical, dry_run=dry_run)
print(f" absorbed fields: {absorbed_fields}")


class Command(BaseCommand):
"""deduplicate allllll the book data models"""

help = "merges duplicate book data"

def add_arguments(self, parser):
"""add the arguments for this command"""
parser.add_argument(
"--dry_run",
action="store_true",
help="don't actually merge, only print what would happen",
)

# pylint: disable=no-self-use,unused-argument
def handle(self, *args, **options):
"""run deduplications"""
dedupe_model(models.Edition)
dedupe_model(models.Work)
dedupe_model(models.Author)
dedupe_model(models.Edition, dry_run=options["dry_run"])
dedupe_model(models.Work, dry_run=options["dry_run"])
dedupe_model(models.Author, dry_run=options["dry_run"])
Loading
Loading