@@ -259,6 +259,16 @@ def test_current_user_permissions(self, app, user, url, public_project, non_cont
259259 res = app .get (url_public , auth = superuser .auth )
260260 assert permissions .READ not in res .json ['data' ][0 ]['attributes' ]['current_user_permissions' ]
261261
262+ def test_legacy_host_for_htmls (self , app , url , public_project ):
263+ settings .DOMAIN = 'https://staging3.osf.io'
264+ current_domain_response = app .get (url ).json ['data' ]
265+ assert current_domain_response [- 1 ]['links' ]['html' ].startswith (settings .DOMAIN )
266+
267+ # mock request from legacy OSF domain to staging3 backend
268+ # so that backend uses it to generate html links instead of current domain
269+ legacy_domain_response = app .get (url , headers = {'Referer' : 'http://legacy.osf.io' }).json ['data' ]
270+ assert legacy_domain_response [- 1 ]['links' ]['html' ].startswith ('http://legacy.osf.io' )
271+
262272
263273@pytest .mark .django_db
264274@pytest .mark .enable_bookmark_creation
@@ -1467,25 +1477,6 @@ def test_create_from_template_errors(self, app, user_one, user_two, url):
14671477 expect_errors = True )
14681478 assert res .status_code == 404
14691479
1470- # test_403_on_create_from_template_of_unauthorized_project
1471- template_from = ProjectFactory (creator = user_two , is_public = True )
1472- templated_project_data = {
1473- 'data' : {
1474- 'type' : 'nodes' ,
1475- 'attributes' :
1476- {
1477- 'title' : 'No permission' ,
1478- 'category' : 'project' ,
1479- 'template_from' : template_from ._id ,
1480- }
1481- }
1482- }
1483- res = app .post_json_api (
1484- url , templated_project_data ,
1485- auth = user_one .auth ,
1486- expect_errors = True )
1487- assert res .status_code == 403
1488-
14891480 def test_creates_project_from_template (self , app , user_one , category , url ):
14901481 template_from = ProjectFactory (creator = user_one , is_public = True )
14911482 template_component = ProjectFactory (
@@ -1517,6 +1508,97 @@ def test_creates_project_from_template(self, app, user_one, category, url):
15171508 assert len (new_project .nodes ) == len (template_from .nodes )
15181509 assert new_project .nodes [0 ].title == template_component .title
15191510
1511+ def test_non_contributor_create_project_from_public_template_success (self , app , user_one , category , url ):
1512+ template_from = ProjectFactory (creator = user_one , is_public = True )
1513+ user_without_permissions = AuthUserFactory ()
1514+ templated_project_data = {
1515+ 'data' : {
1516+ 'type' : 'nodes' ,
1517+ 'attributes' :
1518+ {
1519+ 'title' : 'template from project' ,
1520+ 'category' : category ,
1521+ 'template_from' : template_from ._id ,
1522+ }
1523+ }
1524+ }
1525+ res = app .post_json_api (
1526+ url , templated_project_data ,
1527+ auth = user_without_permissions .auth
1528+ )
1529+ assert res .status_code == 201
1530+
1531+ def test_non_contributor_create_project_from_private_template_no_permission_fails (self , app , user_one , category , url ):
1532+ template_from = ProjectFactory (creator = user_one , is_public = False )
1533+ user_without_permissions = AuthUserFactory ()
1534+ templated_project_data = {
1535+ 'data' : {
1536+ 'type' : 'nodes' ,
1537+ 'attributes' :
1538+ {
1539+ 'title' : 'template from project' ,
1540+ 'category' : category ,
1541+ 'template_from' : template_from ._id ,
1542+ }
1543+ }
1544+ }
1545+ res = app .post_json_api (
1546+ url , templated_project_data ,
1547+ auth = user_without_permissions .auth ,
1548+ expect_errors = True
1549+ )
1550+ assert res .status_code == 403
1551+
1552+ def test_contributor_create_project_from_private_template_with_permission_success (self , app , user_one , category , url ):
1553+ template_from = ProjectFactory (creator = user_one , is_public = False )
1554+ user_without_permissions = AuthUserFactory ()
1555+ template_from .add_contributor (user_without_permissions , permissions = permissions .READ , auth = Auth (user_one ), save = True )
1556+ templated_project_data = {
1557+ 'data' : {
1558+ 'type' : 'nodes' ,
1559+ 'attributes' :
1560+ {
1561+ 'title' : 'template from project' ,
1562+ 'category' : category ,
1563+ 'template_from' : template_from ._id ,
1564+ }
1565+ }
1566+ }
1567+ res = app .post_json_api (
1568+ url , templated_project_data ,
1569+ auth = user_without_permissions .auth
1570+ )
1571+ assert res .status_code == 201
1572+ assert template_from .has_permission (user_without_permissions , permissions .READ )
1573+
1574+ template_from .update_contributor (
1575+ user_without_permissions ,
1576+ permission = permissions .WRITE ,
1577+ auth = Auth (user_one ),
1578+ save = True ,
1579+ visible = True
1580+ )
1581+ res = app .post_json_api (
1582+ url , templated_project_data ,
1583+ auth = user_without_permissions .auth
1584+ )
1585+ assert res .status_code == 201
1586+ assert template_from .has_permission (user_without_permissions , permissions .WRITE )
1587+
1588+ template_from .update_contributor (
1589+ user_without_permissions ,
1590+ permission = permissions .ADMIN ,
1591+ auth = Auth (user_one ),
1592+ save = True ,
1593+ visible = True
1594+ )
1595+ res = app .post_json_api (
1596+ url , templated_project_data ,
1597+ auth = user_without_permissions .auth
1598+ )
1599+ assert res .status_code == 201
1600+ assert template_from .has_permission (user_without_permissions , permissions .ADMIN )
1601+
15201602 def test_creates_project_creates_project_and_sanitizes_html (
15211603 self , app , user_one , category , url ):
15221604 title = '<em>Cool</em> <strong>Project</strong>'
0 commit comments