Skip to content

Add ability to configure sharing domain via Django settings - #78

Merged
chosak merged 5 commits into
mainfrom
feature/settings-config
Aug 1, 2025
Merged

Add ability to configure sharing domain via Django settings#78
chosak merged 5 commits into
mainfrom
feature/settings-config

Conversation

@chosak

@chosak chosak commented Jul 11, 2025

Copy link
Copy Markdown
Member

Currently wagtail-sharing requires that the Wagtail sharing domain be configured in the Wagtail admin UI or via the SharingSite database table. This requires code to be run per environment to configure the sharing domain.

This PR introduces an alternate way of configuring the sharing domain via Django settings.

This is implemented in a new configurable routing system that allows users to plugin different routers that determine how wagtail-sharing works. The new WAGTAILSHARING_ROUTER setting can be used to select which router is used.

The default approach continues to be database-based routing:

WAGTAILSHARING_ROUTER = "wagtailsharing.routers.db.DatabaseHostRouter" # default

Alternatively, users can now specify settings-based routing:

WAGTAILSHARING_ROUTER = "wagtailsharing.routers.settings.SettingsHostRouter"
WAGTAILSHARING_HOST = "http://sharing.localhost:8000"

Custom routers are now also supported, which should allow for different implementations such as token-based routing proposed in #47 (ping @zerolab).

All changes should be backwards compatible with existing deployments.

Please see the changes to the README for what should hopefully be comprehensive documentation of the new approach.

@chosak
chosak requested review from willbarton and wpears July 11, 2025 16:52
Comment on lines +38 to +40
if get_router_cls() == ".".join(
[DatabaseHostRouter.__module__, DatabaseHostRouter.__qualname__]
):

@wpears wpears Jul 21, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for the indirection with __module__ and __qualname__?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is checking to see if the router class has been configured as "wagtailsharing.routers.db.DatabaseHostRouter". We could hardcode that string here, but if this code is ever moved to another file, that would break. Using __module__ + __qualname__ generates the same string but does it dynamically so it'll work wherever the code lives.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! Yeah I suppose that makes sense. It would still require changes in __init__.py and the readme, but reducing the places that require changes makes sense.

@wpears wpears left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All aspects of this work as advertised. I played around with making a custom router and it seems like a nice feature!

@willbarton willbarton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @wpears, this all looks great to me!

@chosak
chosak merged commit c902e39 into main Aug 1, 2025
@chosak
chosak deleted the feature/settings-config branch August 1, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants