Merge pull request #64 from cthulahoops/duplicate_following

Duplicate following
This commit is contained in:
Mouse Reeve 2020-02-23 12:11:22 -08:00 committed by GitHub
commit e398acf45f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 7 deletions

View file

@ -6,6 +6,7 @@ from Crypto.Hash import SHA256
from django.http import HttpResponse, HttpResponseBadRequest, \ from django.http import HttpResponse, HttpResponseBadRequest, \
HttpResponseNotFound, JsonResponse HttpResponseNotFound, JsonResponse
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
import django.db.utils
import json import json
import requests import requests
@ -198,12 +199,19 @@ def handle_incoming_follow(activity):
# figure out who they are # figure out who they are
user = get_or_create_remote_user(activity['actor']) user = get_or_create_remote_user(activity['actor'])
# TODO: allow users to manually approve requests # TODO: allow users to manually approve requests
try:
models.UserRelationship.objects.create( models.UserRelationship.objects.create(
user_subject=to_follow, user_subject=to_follow,
user_object=user, user_object=user,
status='follow_request', status='follow_request',
relationship_id=activity['id'] 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) outgoing.handle_outgoing_accept(user, to_follow, activity)
return HttpResponse() return HttpResponse()

View 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'),
),
]

View file

@ -73,6 +73,11 @@ class UserRelationship(FedireadsModel):
status = models.CharField(max_length=100, default='follows', null=True) status = models.CharField(max_length=100, default='follows', null=True)
relationship_id = models.CharField(max_length=100) relationship_id = models.CharField(max_length=100)
class Meta:
constraints = [
models.UniqueConstraint(fields=['user_subject', 'user_object'], name='followers_unique')
]
@property @property
def absolute_id(self): def absolute_id(self):
''' use shelf identifier as absolute id ''' ''' use shelf identifier as absolute id '''

View file

@ -6,7 +6,7 @@ from django.urls import path, re_path
from fedireads import incoming, outgoing, views, settings, wellknown from fedireads import incoming, outgoing, views, settings, wellknown
from fedireads import view_actions as actions from fedireads import view_actions as actions
username_regex = r'[\w@\.-]+' username_regex = r'(?P<username>[\w@\.-]+)'
localname_regex = r'(?P<username>[\w\.-]+)' localname_regex = r'(?P<username>[\w\.-]+)'
user_path = r'^user/%s' % username_regex user_path = r'^user/%s' % username_regex
local_user_path = r'^user/%s' % localname_regex local_user_path = r'^user/%s' % localname_regex