Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
99
Issue boards
Milestones
Wiki
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djangoldp-packages
djangoldp
Commits
c3383bc7
Commit
c3383bc7
authored
4 years ago
by
Calum Mackervoy
Browse files
Options
Downloads
Patches
Plain Diff
feature: automatic followers removal
parent
bd08385b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!164
feature: external resources auto-follow and unfollow local ones on activity reception
Pipeline
#7751
passed with stage
in 45 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
djangoldp/activities/services.py
+10
-4
10 additions, 4 deletions
djangoldp/activities/services.py
djangoldp/tests/tests_inbox.py
+12
-2
12 additions, 2 deletions
djangoldp/tests/tests_inbox.py
djangoldp/views.py
+5
-0
5 additions, 0 deletions
djangoldp/views.py
with
27 additions
and
6 deletions
djangoldp/activities/services.py
+
10
−
4
View file @
c3383bc7
...
...
@@ -260,6 +260,15 @@ class ActivityPubService(object):
Follower
.
objects
.
create
(
object
=
obj_id
,
inbox
=
ActivityPubService
.
discover_inbox
(
urlid
),
follower
=
urlid
,
is_backlink
=
True
)
@classmethod
def
remove_followers_for_resource
(
cls
,
external_urlid
,
obj_id
):
'''
removes all followers which match the follower urlid, obj urlid combination
'''
inbox
=
ActivityPubService
.
discover_inbox
(
external_urlid
)
for
follower
in
Follower
.
objects
.
filter
(
object
=
obj_id
,
follower
=
external_urlid
,
inbox
=
inbox
,
is_backlink
=
True
):
follower
.
delete
()
@receiver
([
post_save
])
def
check_save_for_backlinks
(
sender
,
instance
,
created
,
**
kwargs
):
...
...
@@ -362,7 +371,4 @@ def check_m2m_for_backlinks(sender, instance, action, *args, **kwargs):
elif
action
==
"
post_remove
"
or
action
==
"
pre_clear
"
:
for
target
in
targets
:
ActivityPubService
.
send_remove_activity
(
BACKLINKS_ACTOR
,
obj
,
target
)
inbox
=
ActivityPubService
.
discover_inbox
(
target
[
'
@id
'
])
for
follower
in
Follower
.
objects
.
filter
(
object
=
obj
[
'
@id
'
],
follower
=
target
[
'
@id
'
],
inbox
=
inbox
,
is_backlink
=
True
):
follower
.
delete
()
ActivityPubService
.
remove_followers_for_resource
(
target
[
'
@id
'
],
obj
[
'
@id
'
])
This diff is collapsed.
Click to expand it.
djangoldp/tests/tests_inbox.py
+
12
−
2
View file @
c3383bc7
...
...
@@ -306,9 +306,13 @@ class TestsInbox(APITestCase):
# REMOVE & DELETE ACTIVITIES
#
# project model has a direct many-to-many with User
@override_settings
(
SEND_BACKLINKS
=
True
,
DISABLE_OUTBOX
=
True
)
def
test_remove_activity_project_using_origin
(
self
):
project
=
Project
.
objects
.
create
(
urlid
=
"
https://distant.com/projects/1/
"
)
self
.
user
.
projects
.
add
(
project
)
Follower
.
objects
.
create
(
object
=
self
.
user
.
urlid
,
inbox
=
'
https://distant.com/inbox/
'
,
follower
=
project
.
urlid
,
is_backlink
=
True
)
prior_activity_count
=
Activity
.
objects
.
count
()
obj
=
{
"
@type
"
:
"
hd:project
"
,
...
...
@@ -326,7 +330,8 @@ class TestsInbox(APITestCase):
self
.
assertEquals
(
len
(
projects
),
1
)
self
.
assertEquals
(
len
(
user_projects
),
0
)
self
.
assertIn
(
"
https://distant.com/projects/1/
"
,
projects
.
values_list
(
'
urlid
'
,
flat
=
True
))
self
.
_assert_activity_created
(
response
)
self
.
_assert_activity_created
(
response
,
prior_activity_count
+
2
)
self
.
assertEqual
(
Follower
.
objects
.
count
(),
0
)
# TODO: test_remove_activity_project_using_target
...
...
@@ -374,9 +379,12 @@ class TestsInbox(APITestCase):
self
.
assertEqual
(
Activity
.
objects
.
all
().
count
(),
prior_count
+
1
)
# Delete CircleMember
@override_settings
(
SEND_BACKLINKS
=
True
,
DISABLE_OUTBOX
=
True
)
def
test_delete_activity_circle_using_origin
(
self
):
circle
=
Circle
.
objects
.
create
(
urlid
=
"
https://distant.com/circles/1/
"
,
allow_create_backlink
=
False
)
CircleMember
.
objects
.
create
(
urlid
=
"
https://distant.com/circle-members/1/
"
,
circle
=
circle
,
user
=
self
.
user
)
cm
=
CircleMember
.
objects
.
create
(
urlid
=
"
https://distant.com/circle-members/1/
"
,
circle
=
circle
,
user
=
self
.
user
)
Follower
.
objects
.
create
(
object
=
self
.
user
.
urlid
,
inbox
=
'
https://distant.com/inbox/
'
,
follower
=
cm
.
urlid
,
is_backlink
=
True
)
obj
=
{
"
@type
"
:
"
hd:circlemember
"
,
...
...
@@ -400,9 +408,11 @@ class TestsInbox(APITestCase):
circles
=
Circle
.
objects
.
all
()
user_circles
=
self
.
user
.
circles
.
all
()
self
.
assertEquals
(
len
(
circles
),
1
)
self
.
assertEquals
(
CircleMember
.
objects
.
count
(),
0
)
self
.
assertEquals
(
len
(
user_circles
),
0
)
self
.
assertIn
(
"
https://distant.com/circles/1/
"
,
circles
.
values_list
(
'
urlid
'
,
flat
=
True
))
self
.
_assert_activity_created
(
response
)
self
.
assertEqual
(
Follower
.
objects
.
count
(),
0
)
# TODO: test_delete_activity_circle_using_target
...
...
This diff is collapsed.
Click to expand it.
djangoldp/views.py
+
5
−
0
View file @
c3383bc7
...
...
@@ -239,6 +239,7 @@ class InboxView(APIView):
attr
=
getattr
(
origin
,
field_name
)
if
attr
.
filter
(
urlid
=
object_instance
.
urlid
).
exists
():
attr
.
remove
(
object_instance
)
ActivityPubService
.
remove_followers_for_resource
(
origin
.
urlid
,
object_instance
.
urlid
)
def
handle_create_or_update_activity
(
self
,
activity
,
**
kwargs
):
'''
...
...
@@ -264,6 +265,10 @@ class InboxView(APIView):
object_instance
.
allow_create_backlink
=
False
object_instance
.
save
()
object_instance
.
delete
()
urlid
=
getattr
(
object_instance
,
'
urlid
'
,
None
)
if
urlid
is
not
None
:
for
follower
in
Follower
.
objects
.
filter
(
follower
=
urlid
):
follower
.
delete
()
def
handle_follow_activity
(
self
,
activity
,
**
kwargs
):
'''
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment