Skip to content

Implementing Django User Model with Source and Destination ActivityPub Actors #105

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

Merged
merged 2 commits into from
May 27, 2025

Conversation

aaronjae22
Copy link
Collaborator

This PR enhances the user registration process by working with the existing django-allauth features (implemented by @alexbainter ) with a custom account adapter. Now, whenever a user signs up, two associated Actor instances are automatically created: one as a Source Service (fully initialized) and one as a Destination Service (empty for future use).

Custom Allauth Adapter:

A custom adaptar was created (TestbedAccountAdapter) that extends allauth’s default behavior. This adapter is now responsible for both creating the user and immediately creating the two associated Actor objects.

Actor and User Relationship:

  • The Actor model is now directly related to Django’s built-in User model via a foreign key. This means each user can have multiple actors (specifically, one source and one destination), and all user-related information (such as username, email, and authentication) is managed by Django’s user system.

Removed Redundant Fields from Actor:

  • Fields like username and others that duplicate information already present in the User model have been removed from the Actor model. This reduces redundancy.

How It Works:

  • When a user signs up, allauth validates the form and then calls our adapter’s save_user method.
  • Inside save_user, the user is created first.
  • Immediately after, the adapter creates two Actor objects linked to the new user: one for the Source Service and one for the Destination Service.
  • This all happens in a single step, so if anything fails, the user and actors are not created, keeping our data consistent.

Actor Model Improvements:

  • The Actor model now has a manager method to create both actors for a user.
  • Each user can only have one source and one destination actor, enforced by a unique constraint.

Cleaner and Safer Signup Flow:

  • User and actor creation are part of the same process. If actor creation fails, the user isn’t created either.
  • By using the adapter, all logic for user and actor creation is in one place, making it easier to maintain and debug.

Testing updates

  • Confirmed that every new user gets exactly one source and one destination actor.
  • Ensured that no duplicate actors or outboxes are created.
  • Updated tests to reflect the new signup and actor creation flow.

Notes

Testbed already had allauth configured with:

  • Email-based registration
  • Mandatory email verification
  • Custom base template
  • Auto-login after email confirmation
  • Standard redirect to home after login
  • We needed to hook into allauth's signup process to create our Actors.

New User
image

User trying to registers with an existing email
image

Admin
image

…actor creation, and corresponding test suite updates
@aaronjae22 aaronjae22 requested review from lisad and alexbainter May 22, 2025 16:59
@aaronjae22 aaronjae22 self-assigned this May 22, 2025
"preferredUsername": self.username,
"name": self.username,
"id": f"https://example.com/users/{self.user.username}",
"preferredUsername": self.user.username,
Copy link
Member

Choose a reason for hiding this comment

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

Actors are separate from users - there can be multiple per user
So the id can't be the same for both
the preferredUsername doesn't need to be the user's username - it could be "Alice" or "Bob" or "Dave" (destination) and "Sarah" (source)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am currently working on an issue about preferredUsername take

@aaronjae22 aaronjae22 requested a review from lisad May 26, 2025 17:51
Copy link
Member

@lisad lisad left a comment

Choose a reason for hiding this comment

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

Looks mostly good. I think we should merge this and move onward

@aaronjae22 aaronjae22 merged commit 0395385 into main May 27, 2025
1 check passed
@aaronjae22 aaronjae22 deleted the feature/user-actor-integration branch May 27, 2025 15:55
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.

2 participants