Merge branch 'main' into production

This commit is contained in:
Mouse Reeve 2021-02-12 16:23:27 -08:00
commit 70bdac3706
5 changed files with 53 additions and 5 deletions

View file

@ -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()

View file

@ -0,0 +1 @@
{% load humanize %}set a goal to read {{ goal.goal | intcomma }} book{{ goal.goal | pluralize }} in {{ goal.year }}

View file

@ -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})

View file

@ -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)

View file

@ -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
)