-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" move an object including migrating a user account """ | ||
from django.db import models | ||
|
||
from bookwyrm import activitypub | ||
from .activitypub_mixin import ActivityMixin | ||
from .base_model import BookWyrmModel | ||
from . import fields | ||
from .status import Status | ||
|
||
|
||
class Move(ActivityMixin, BookWyrmModel): | ||
"""migrating an activitypub user account""" | ||
|
||
user = fields.ForeignKey( | ||
"User", on_delete=models.PROTECT, activitypub_field="actor" | ||
) | ||
|
||
# TODO: can we just use the abstract class here? | ||
activitypub_object = fields.ForeignKey( | ||
"BookWyrmModel", on_delete=models.PROTECT, | ||
activitypub_field="object", | ||
blank=True, | ||
null=True | ||
) | ||
|
||
target = fields.CharField( | ||
max_length=255, blank=True, null=True, deduplication_field=True | ||
) | ||
|
||
origin = fields.CharField( | ||
max_length=255, blank=True, null=True, deduplication_field=True | ||
) | ||
|
||
activity_serializer = activitypub.Move | ||
|
||
# pylint: disable=unused-argument | ||
@classmethod | ||
def ignore_activity(cls, activity, allow_external_connections=True): | ||
"""don't bother with incoming moves of unknown objects""" | ||
# TODO how do we check this for any conceivable object? | ||
pass | ||
|
||
def save(self, *args, **kwargs): | ||
"""update user active time""" | ||
self.user.update_active_date() | ||
super().save(*args, **kwargs) | ||
|
||
# Ok what else? We can trigger a notification for followers of a user who sends a `Move` for themselves | ||
# What about when a book is merged (i.e. moved from one id into another)? We could use that to send out a message | ||
# to other Bookwyrm instances to update their remote_id for the book, but ...how do we trigger any action? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% extends 'notifications/items/layout.html' %} | ||
|
||
{% load i18n %} | ||
{% load utilities %} | ||
|
||
{% block primary_link %}{% spaceless %} | ||
{{ notification.related_object.local_path }} | ||
{% endspaceless %}{% endblock %} | ||
|
||
{% block icon %} | ||
<span class="icon icon-local"></span> | ||
{% endblock %} | ||
|
||
{% block description %} | ||
<!-- | ||
TODO: a user has a 'name' but not everything does, notably a book. | ||
On the other hand, maybe we don't need to notify anyone if a book | ||
is moved, just update the remote_id? | ||
--> | ||
{% blocktrans trimmed with object_name=notification.related_object.name object_path=notification.related_object.local_path %} | ||
<a href="{{ related_user_link }}">{{ related_user }}</a> | ||
moved {{ object_name }} | ||
"<a href="{{ object_path }}">{{ object_name }}</a>" | ||
{% endblocktrans %} | ||
|
||
<!-- TODO maybe put a brief context message here for migrated user accounts? --> | ||
|
||
{% endblock %} |