Fixes following external fedireads user

Fixes #42
This commit is contained in:
Mouse Reeve 2020-02-19 11:33:00 -08:00
parent bf58e29a54
commit f7867da7a0
7 changed files with 29 additions and 30 deletions

View file

@ -13,6 +13,7 @@ def get_actor(user):
'preferredUsername': user.localname,
'name': user.name,
'inbox': user.inbox,
'outbox': '%s/outbox' % user.actor,
'followers': '%s/followers' % user.actor,
'following': '%s/following' % user.actor,
'summary': user.summary,
@ -23,6 +24,7 @@ def get_actor(user):
},
'endpoints': {
'sharedInbox': user.shared_inbox,
}
},
'fedireadsUser': True,
}

View file

@ -66,7 +66,10 @@ def handle_account_search(query):
data = response.json()
for link in data['links']:
if link['rel'] == 'self':
try:
user = get_or_create_remote_user(link['href'])
except KeyError:
return HttpResponseNotFound()
return user

View file

@ -29,7 +29,7 @@ def get_or_create_remote_user(actor):
shared_inbox = data.get('endpoints').get('sharedInbox') if \
data.get('endpoints') else None
try:
# throws a key error if it can't find any of these fields
user = models.User.objects.create_user(
username,
'', '', # email and passwords are left blank
@ -42,10 +42,8 @@ def get_or_create_remote_user(actor):
# TODO: I'm never actually using this for remote users
public_key=data.get('publicKey').get('publicKeyPem'),
local=False,
fedireads_user=False,
fedireads_user=data.get('fedireadsUser', False),
)
except KeyError:
return False
return user

View file

@ -14,15 +14,13 @@
{% endif %}
{% if not is_self %}
{% if not request.user in user.followers.all %}
<form action="/follow/" method="post">
<form action="/follow/{{ user.username }}" method="post">
{% csrf_token %}
<input type="hidden" name="user" value="{{ user.id }}"></input>
<input type="submit" value="Follow"></input>
</form>
{% else %}
<form action="/unfollow/" method="post">
<form action="/unfollow/{{ user.username }}" method="post">
{% csrf_token %}
<input type="hidden" name="user" value="{{ user.id }}"></input>
<input type="submit" value="Unfollow"></input>
</form>
{% endif %}

View file

@ -4,9 +4,8 @@
{% for result in results %}
<div>
<h2>{{ result.username }}</h2>
<form action="/follow/" method="post">
<form action="/follow/{{ result.username }}" method="post">
{% csrf_token %}
<input type="hidden" name="user" value="{{ result.id }}"></input>
<input type="submit" value="Follow"></input>
</form>
</div>

View file

@ -56,8 +56,8 @@ urlpatterns = [
r'^shelve/(?P<username>\w+)/(?P<shelf_id>[\w-]+)/(?P<book_id>\d+)/?$',
views.shelve
),
re_path(r'^follow/?$', views.follow),
re_path(r'^unfollow/?$', views.unfollow),
re_path(r'^follow/(?P<username>[\w@\.]+)/?$', views.follow),
re_path(r'^unfollow/(?P<username>[\w@\.]+)/?$', views.unfollow),
re_path(r'^search/?$', views.search),
re_path(r'^edit_profile/?$', views.edit_profile),

View file

@ -274,11 +274,10 @@ def favorite(request, status_id):
@login_required
def follow(request):
def follow(request, username):
''' follow another user, here or abroad '''
to_follow = request.POST.get('user')
# should this be an actor rather than an id? idk
to_follow = models.User.objects.get(id=to_follow)
to_follow = models.User.objects.get(username=username)
outgoing.handle_outgoing_follow(request.user, to_follow)
user_slug = to_follow.localname if to_follow.localname \