Skip to content

Commit a227997

Browse files
committed
fix: index new collection submissions in SHARE and Elasticsearch
1 parent 8e29e38 commit a227997

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

api_tests/collections/test_views.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,6 +4358,45 @@ def test_update_share_called(self, app, collection_with_zero_collection_submissi
43584358
assert res.status_code == 201
43594359
_shmock.assert_called()
43604360

4361+
def test_private_project_made_public_on_non_moderated_submit(self, app, collection_with_zero_collection_submission, user_one, project_four, url, payload):
4362+
# Projects are private by default; non-moderated submit should make referent public
4363+
assert not project_four.is_public
4364+
4365+
collection_with_zero_collection_submission.is_public = True
4366+
collection_with_zero_collection_submission.save()
4367+
4368+
with mock_update_share():
4369+
res = app.post_json_api(
4370+
url.format(collection_with_zero_collection_submission._id),
4371+
payload(guid=project_four._id),
4372+
auth=user_one.auth)
4373+
assert res.status_code == 201
4374+
4375+
project_four.refresh_from_db()
4376+
assert project_four.is_public
4377+
4378+
def test_on_collection_updated_notifies_share_when_collection_goes_public(self, user_one, project_one, project_two):
4379+
from website.collections.tasks import on_collection_updated
4380+
4381+
collection = CollectionFactory(creator=user_one)
4382+
with mock_update_share():
4383+
collection.collect_object(project_one, user_one)
4384+
collection.collect_object(project_two, user_one)
4385+
4386+
with mock_update_share() as _shmock:
4387+
on_collection_updated(collection._id)
4388+
4389+
# on_collection_updated should not call update_share when collection is private
4390+
_shmock.assert_not_called()
4391+
4392+
with mock_update_share() as _shmock:
4393+
collection.is_public = True
4394+
collection.save()
4395+
on_collection_updated(collection._id)
4396+
4397+
# Both accepted submissions should trigger a SHARE update
4398+
assert _shmock.call_count == 2
4399+
43614400
def test_filters(self, app, collection_with_one_collection_submission, collection_with_three_collection_submission, project_two, project_four, user_one, subject_one, url, payload):
43624401
res = app.get(f'{url.format(collection_with_three_collection_submission._id)}?filter[id]={project_two._id}', auth=user_one.auth)
43634402
assert res.status_code == 200

osf/utils/workflows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def db_name(self):
392392
'source': [CollectionSubmissionStates.IN_PROGRESS],
393393
'dest': CollectionSubmissionStates.ACCEPTED,
394394
'before': [],
395-
'after': ['_notify_accepted'],
395+
'after': ['_make_public', '_notify_accepted'],
396396
'unless': ['is_moderated', 'is_hybrid_moderated'],
397397
},
398398
{
@@ -408,7 +408,7 @@ def db_name(self):
408408
'source': [CollectionSubmissionStates.IN_PROGRESS],
409409
'dest': CollectionSubmissionStates.ACCEPTED,
410410
'before': [],
411-
'after': ['_notify_contributors_pending', '_notify_moderators_pending'],
411+
'after': ['_make_public', '_notify_contributors_pending', '_notify_moderators_pending'],
412412
'conditions': ['is_hybrid_moderated', 'is_submitted_by_moderator_contributor'],
413413
},
414414
{

website/collections/tasks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from django.apps import apps
22
import logging
33
from framework.celery_tasks import app as celery_app
4+
from osf.utils.workflows import CollectionSubmissionStates
45

56

67
logger = logging.getLogger(__name__)
78

89
@celery_app.task(ignore_results=True)
910
def on_collection_updated(collection_id):
11+
from api.share.utils import update_share
12+
1013
Collection = apps.get_model('osf.Collection')
1114
coll = Collection.load(collection_id)
1215

@@ -15,6 +18,11 @@ def on_collection_updated(collection_id):
1518
if coll.is_public:
1619
# Add all collection submissions back to ES index
1720
coll.bulk_update_search(collection_submissions)
21+
# Notify SHARE for every accepted submission so collection membership is indexed
22+
for submission in collection_submissions.filter(
23+
machine_state=CollectionSubmissionStates.ACCEPTED
24+
):
25+
update_share(submission.guid.referent)
1826
else:
1927
# Remove all collection submissions from ES index
2028
coll.bulk_update_search(collection_submissions, op='delete')

0 commit comments

Comments
 (0)