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

Allow an instance to disable federation #3421

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

mouse-reeve
Copy link
Member

Description

This allows an instance to turn off all contact with other ActivityPub services. The instance would still be able to connect to OpenLibrary and Inventaire. If there's existing federated data, there can be some odd behavior (like blocking an existing remote user will "work" but not propagate the block to the other server, and following that user would fail silently), but since I expect this to either be used from the outset or as a stopgap for some unforeseen issue, I didn't bother to clarify those situations in the UI (besides putting up a banner on the user page).

  • Related Issue #
  • Closes #

What type of Pull Request is this?

  • Bug Fix
  • Enhancement
  • Plumbing / Internals / Dependencies
  • Refactor

Does this PR change settings or dependencies, or break something?

  • This PR changes or adds default settings, configuration, or .env values
  • This PR changes or adds dependencies
  • This PR introduces other breaking changes

Details of breaking or configuration changes (if any of above checked)

Documentation

  • New or amended documentation will be required if this PR is merged
  • I have created a matching pull request in the Documentation repository
  • I intend to create a matching pull request in the Documentation repository after this PR is merged

Tests

  • My changes do not need new tests
  • All tests I have added are passing
  • I have written tests but need help to make them pass
  • I have not written tests and need help to write them

@mouse-reeve mouse-reeve force-pushed the disable-federation branch 2 times, most recently from 04ab58e to ebc60ab Compare August 27, 2024 22:55
Did I do this right?
@Flameborn
Copy link
Contributor

Thank you for implementing this. If federation also includes book edits from remote instances, this might be a partial solution for #2841

@mouse-reeve
Copy link
Member Author

It does prevent book data federation, but it’s not granular at all

@mouse-reeve
Copy link
Member Author

@bookwyrm-social/code-review It would be great to get a check-over on this one

Copy link
Contributor

@hughrun hughrun left a comment

Choose a reason for hiding this comment

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

This seems to work as advertised.

I take your point about following of external users probably being an unusual case, but it feels like something that might be reasonably easily fixable. e.g. you could just add this to snippets/follow_button.html:

{% if request.user == user or not request.user.is_authenticated %}
{# nothing to see here -- either it's yourself or your logged out #}
{% elif site.disable_federation and not user.local %}
{# can't follow remote users without federation #}
{% else %}

In line with your comment about following external users silently failing, I also noticed that the get-started flow still includes external users when federation is turned off. This doesn't provide any indication that following will fail, so it's not ideal.

We could fix this fairly easily by adjusting the signature for get_suggestions, something like this but ideally a little less verbose:

def get_suggestions(self, user, local=models.SiteSettings.get().disable_federation):

We only have the local arg because I needed it to be False for groups (which still don't federate 🙁) - so aligning this with the value of disable_federation makes sense to me.

def host_meta(request):
"""meta of the host"""
return TemplateResponse(request, "host_meta.xml", {"DOMAIN": DOMAIN})


@require_GET
@require_federation
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not clear about why this requires federation. e.g. maybe I want to add an instance to my "search engines" in my browser.

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