forked from mirrors/bookwyrm
Merge pull request #64 from cthulahoops/duplicate_following
Duplicate following
This commit is contained in:
commit
e398acf45f
4 changed files with 37 additions and 7 deletions
|
@ -6,6 +6,7 @@ from Crypto.Hash import SHA256
|
|||
from django.http import HttpResponse, HttpResponseBadRequest, \
|
||||
HttpResponseNotFound, JsonResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
import django.db.utils
|
||||
import json
|
||||
import requests
|
||||
|
||||
|
@ -198,12 +199,19 @@ def handle_incoming_follow(activity):
|
|||
# figure out who they are
|
||||
user = get_or_create_remote_user(activity['actor'])
|
||||
# TODO: allow users to manually approve requests
|
||||
models.UserRelationship.objects.create(
|
||||
user_subject=to_follow,
|
||||
user_object=user,
|
||||
status='follow_request',
|
||||
relationship_id=activity['id']
|
||||
)
|
||||
try:
|
||||
models.UserRelationship.objects.create(
|
||||
user_subject=to_follow,
|
||||
user_object=user,
|
||||
status='follow_request',
|
||||
relationship_id=activity['id']
|
||||
)
|
||||
except django.db.utils.IntegrityError:
|
||||
# Duplicate follow request. Not sure what the correct behaviour is, but just dropping
|
||||
# it works for now. We should perhaps generate the Accept, but then do we need to match
|
||||
# the activity id?
|
||||
return HttpResponse()
|
||||
|
||||
outgoing.handle_outgoing_accept(user, to_follow, activity)
|
||||
return HttpResponse()
|
||||
|
||||
|
|
17
fedireads/migrations/0007_auto_20200223_0902.py
Normal file
17
fedireads/migrations/0007_auto_20200223_0902.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 3.0.3 on 2020-02-23 09:02
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('fedireads', '0006_auto_20200221_1702'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddConstraint(
|
||||
model_name='userrelationship',
|
||||
constraint=models.UniqueConstraint(fields=('user_subject', 'user_object'), name='followers_unique'),
|
||||
),
|
||||
]
|
|
@ -73,6 +73,11 @@ class UserRelationship(FedireadsModel):
|
|||
status = models.CharField(max_length=100, default='follows', null=True)
|
||||
relationship_id = models.CharField(max_length=100)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=['user_subject', 'user_object'], name='followers_unique')
|
||||
]
|
||||
|
||||
@property
|
||||
def absolute_id(self):
|
||||
''' use shelf identifier as absolute id '''
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.urls import path, re_path
|
|||
from fedireads import incoming, outgoing, views, settings, wellknown
|
||||
from fedireads import view_actions as actions
|
||||
|
||||
username_regex = r'[\w@\.-]+'
|
||||
username_regex = r'(?P<username>[\w@\.-]+)'
|
||||
localname_regex = r'(?P<username>[\w\.-]+)'
|
||||
user_path = r'^user/%s' % username_regex
|
||||
local_user_path = r'^user/%s' % localname_regex
|
||||
|
|
Loading…
Reference in a new issue