Skip to content

Commit d6b7edb

Browse files
authored
Merge pull request #11269 from ihorsokhanexoft/fix/ENG-8742
[ENG-8742] include ignored components when create a view-only link
2 parents d88bc14 + b498d1b commit d6b7edb

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

api/nodes/serializers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,12 +1697,15 @@ def create(self, validated_data):
16971697
user = get_user_auth(self.context['request']).user
16981698
anonymous = validated_data.pop('anonymous')
16991699
node = self.context['view'].get_node()
1700+
children = self.context['request'].data.pop('target_type', [])
1701+
if children:
1702+
children = [AbstractNode.load(id) for id in children if id != 'nodes']
17001703

17011704
try:
17021705
view_only_link = new_private_link(
17031706
name=name,
17041707
user=user,
1705-
nodes=[node],
1708+
nodes=[node, *children],
17061709
anonymous=anonymous,
17071710
)
17081711
except ValidationError:

api_tests/nodes/views/test_node_view_only_links_list.py

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from osf_tests.factories import (
66
ProjectFactory,
77
AuthUserFactory,
8-
PrivateLinkFactory
8+
PrivateLinkFactory,
9+
NodeRelationFactory
910
)
1011

1112

@@ -54,6 +55,11 @@ def view_only_link(public_project):
5455
return view_only_link
5556

5657

58+
@pytest.fixture()
59+
def components_factory():
60+
return ProjectFactory
61+
62+
5763
@pytest.mark.django_db
5864
class TestViewOnlyLinksList:
5965

@@ -227,3 +233,77 @@ def test_cannot_create_vol(
227233
}
228234
res = app.post_json_api(url, {'data': payload}, expect_errors=True)
229235
assert res.status_code == 401
236+
237+
def test_create_vol_with_components(
238+
self, app, user, url, public_project, view_only_link, components_factory):
239+
component1 = components_factory(creator=user)
240+
component2 = components_factory(creator=user)
241+
component3 = components_factory(creator=user)
242+
NodeRelationFactory(parent=public_project, child=component1)
243+
NodeRelationFactory(parent=public_project, child=component2)
244+
NodeRelationFactory(parent=public_project, child=component3)
245+
246+
url = f'{url}?embed=creator&embed=nodes'
247+
payload = {
248+
'attributes': {
249+
'name': 'testmultiplenodes',
250+
'anonymous': False,
251+
},
252+
'relationships': {
253+
'nodes': {
254+
'data': [
255+
{
256+
'id': component1._id,
257+
'type': 'nodes'
258+
},
259+
{
260+
'id': component2._id,
261+
'type': 'nodes'
262+
},
263+
{
264+
'id': component3._id,
265+
'type': 'nodes'
266+
}
267+
]
268+
}
269+
}
270+
}
271+
res = app.post_json_api(url, {'data': payload}, auth=user.auth)
272+
assert res.status_code == 201
273+
data = res.json['data']
274+
assert len(data['embeds']['nodes']['data']) == 4
275+
276+
def test_create_vol_no_duplicated_components(
277+
self, app, user, url, public_project, view_only_link, components_factory):
278+
component1 = components_factory(creator=user)
279+
NodeRelationFactory(parent=public_project, child=component1)
280+
281+
url = f'{url}?embed=creator&embed=nodes'
282+
payload = {
283+
'attributes': {
284+
'name': 'testmultiplenodes',
285+
'anonymous': False,
286+
},
287+
'relationships': {
288+
'nodes': {
289+
'data': [
290+
{
291+
'id': component1._id,
292+
'type': 'nodes'
293+
},
294+
{
295+
'id': component1._id,
296+
'type': 'nodes'
297+
},
298+
{
299+
'id': component1._id,
300+
'type': 'nodes'
301+
},
302+
]
303+
}
304+
}
305+
}
306+
res = app.post_json_api(url, {'data': payload}, auth=user.auth)
307+
assert res.status_code == 201
308+
data = res.json['data']
309+
assert len(data['embeds']['nodes']['data']) == 2

api_tests/registrations/views/test_registration_view_only_links_list.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def view_only_link(public_project):
5858
return view_only_link
5959

6060

61+
@pytest.fixture
62+
def components_factory():
63+
return RegistrationFactory
64+
65+
6166
class TestRegistrationViewOnlyLinksList(TestViewOnlyLinksList):
6267
pass
6368

0 commit comments

Comments
 (0)