diff --git a/README.md b/README.md index f07d9cefb..dcc34b492 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Social reading and reviewing, decentralized with ActivityPub ## Joining BookWyrm BookWyrm is still a young piece of software, and isn't at the level of stability and feature-richness that you'd find in a production-ready application. But it does what it says on the box! If you'd like to join an instance, you can check out the [instances](https://github.com/mouse-reeve/bookwyrm/blob/main/instances.md) list. -I, the maintianer of this project, run https://bookwyrm.social, and I generally give out invite codes to those who ask by [email](mailto:mousereeve@riseup.net), [Mastodon direct message](https://friend.camp/@tripofmice), or [Twitter direct message](https://twitter.com/tripofmice). +You can request an invite to https://bookwyrm.social by [email](mailto:mousereeve@riseup.net), [Mastodon direct message](https://friend.camp/@tripofmice), or [Twitter direct message](https://twitter.com/tripofmice). ## The overall idea ### What it is and isn't @@ -116,7 +116,6 @@ This project is still young and isn't, at the momoment, very stable, so please p ```python from bookwyrm import models user = models.User.objects.get(id=1) - user.is_admin = True user.is_staff = True user.is_superuser = True user.save() diff --git a/bookwyrm/templates/snippets/generated_status/goal.html b/bookwyrm/templates/snippets/generated_status/goal.html new file mode 100644 index 000000000..3b4d0de4f --- /dev/null +++ b/bookwyrm/templates/snippets/generated_status/goal.html @@ -0,0 +1 @@ +{% load humanize %}set a goal to read {{ goal.goal | intcomma }} book{{ goal.goal | pluralize }} in {{ goal.year }} diff --git a/bookwyrm/tests/views/test_follow.py b/bookwyrm/tests/views/test_follow.py index e6c7e46fb..943ffcf82 100644 --- a/bookwyrm/tests/views/test_follow.py +++ b/bookwyrm/tests/views/test_follow.py @@ -40,7 +40,7 @@ class BookViews(TestCase): parent_work=self.work ) - def test_handle_follow(self): + def test_handle_follow_remote(self): ''' send a follow request ''' request = self.factory.post('', {'user': self.remote_user.username}) request.user = self.local_user @@ -56,6 +56,49 @@ class BookViews(TestCase): self.assertEqual(rel.status, 'follow_request') + def test_handle_follow_local_manually_approves(self): + ''' send a follow request ''' + rat = models.User.objects.create_user( + 'rat@local.com', 'rat@rat.com', 'ratword', + local=True, localname='rat', + remote_id='https://example.com/users/rat', + manually_approves_followers=True, + ) + request = self.factory.post('', {'user': rat}) + request.user = self.local_user + self.assertEqual(models.UserFollowRequest.objects.count(), 0) + + with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'): + views.follow(request) + rel = models.UserFollowRequest.objects.get() + + self.assertEqual(rel.user_subject, self.local_user) + self.assertEqual(rel.user_object, rat) + self.assertEqual(rel.status, 'follow_request') + + + + def test_handle_follow_local(self): + ''' send a follow request ''' + rat = models.User.objects.create_user( + 'rat@local.com', 'rat@rat.com', 'ratword', + local=True, localname='rat', + remote_id='https://example.com/users/rat', + ) + request = self.factory.post('', {'user': rat}) + request.user = self.local_user + self.assertEqual(models.UserFollowRequest.objects.count(), 0) + + with patch('bookwyrm.models.activitypub_mixin.broadcast_task.delay'): + views.follow(request) + + rel = models.UserFollows.objects.get() + + self.assertEqual(rel.user_subject, self.local_user) + self.assertEqual(rel.user_object, rat) + self.assertEqual(rel.status, 'follows') + + def test_handle_unfollow(self): ''' send an unfollow ''' request = self.factory.post('', {'user': self.remote_user.username}) diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index f5b2ddd58..c59f2e6d2 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -17,10 +17,13 @@ def follow(request): except models.User.DoesNotExist: return HttpResponseBadRequest() - models.UserFollowRequest.objects.get_or_create( + rel, _ = models.UserFollowRequest.objects.get_or_create( user_subject=request.user, user_object=to_follow, ) + + if to_follow.local and not to_follow.manually_approves_followers: + rel.accept() return redirect(to_follow.local_path) diff --git a/bookwyrm/views/goal.py b/bookwyrm/views/goal.py index 87404b100..4f2d1b6f4 100644 --- a/bookwyrm/views/goal.py +++ b/bookwyrm/views/goal.py @@ -2,6 +2,7 @@ from django.contrib.auth.decorators import login_required from django.http import HttpResponseNotFound from django.shortcuts import redirect +from django.template.loader import get_template from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View @@ -62,9 +63,10 @@ class Goal(View): if request.POST.get('post-status'): # create status, if appropraite + template = get_template('snippets/generated_status/goal.html') create_generated_note( request.user, - 'set a goal to read %d books in %d' % (goal.goal, goal.year), + template.render({'goal': goal, 'user': request.user}).strip(), privacy=goal.privacy )