def test_workstation_changes(client, group): # Ensure that read permissions are kept up to date if the workstation # changes ws1, ws2 = WorkstationFactory(), WorkstationFactory() user = UserFactory() alg = AlgorithmFactory(workstation=ws1) assert "view_workstation" not in get_perms(user, ws1) assert "view_workstation" not in get_perms(user, ws2) getattr(alg, f"add_{group}")(user=user) assert "view_workstation" in get_perms(user, ws1) assert "view_workstation" not in get_perms(user, ws2) alg.workstation = ws2 alg.save() assert "view_workstation" not in get_perms(user, ws1) assert "view_workstation" in get_perms(user, ws2) # Test permission cleanup assign_perm("view_workstation", getattr(alg, f"{group}s_group"), ws1) assert "view_workstation" in get_perms(user, ws1) assert "view_workstation" in get_perms(user, ws2) alg.save() assert "view_workstation" not in get_perms(user, ws1) assert "view_workstation" in get_perms(user, ws2)
def test_visible_to_public_group_permissions(): g_reg_anon = Group.objects.get( name=settings.REGISTERED_AND_ANON_USERS_GROUP_NAME) algorithm = AlgorithmFactory() assert "view_algorithm" not in get_perms(g_reg_anon, algorithm) algorithm.public = True algorithm.save() assert "view_algorithm" in get_perms(g_reg_anon, algorithm) algorithm.public = False algorithm.save() assert "view_algorithm" not in get_perms(g_reg_anon, algorithm)
def test_publication_object_visibilty(client, mocker): user1 = UserFactory() user2 = UserFactory() alg = AlgorithmFactory() alg.add_user(user1) assert user1.has_perm("view_algorithm", alg) assert not user2.has_perm("view_algorithm", alg) mocker.patch("grandchallenge.publications.utils.get_doi_csl", return_value=TEST_CSL) # create publication _ = get_view_for_user( viewname="publications:create", client=client, method=client.post, data={"identifier": TEST_DOI}, user=user1, ) # add publication to algorithm alg.publications.add(Publication.objects.get()) alg.save() response = get_view_for_user( viewname="publications:list", client=client, method=client.get, user=user1, ) assert response.status_code == 200 assert alg.title in response.rendered_content response = get_view_for_user( viewname="publications:list", client=client, method=client.get, user=user2, ) assert response.status_code == 200 assert alg.title not in response.rendered_content
def test_algorithm_detail_flexible_inputs(client): editor = UserFactory() alg = AlgorithmFactory(use_flexible_inputs=False) alg.add_editor(editor) AlgorithmImageFactory(algorithm=alg, ready=True) flexi_input_url = reverse( viewname="algorithms:execution-session-create-new", kwargs={"slug": alg.slug}, ) response = get_view_for_user( viewname="algorithms:detail", reverse_kwargs={"slug": slugify(alg.slug)}, client=client, user=editor, method=client.get, follow=True, **{"HTTP_X_REQUESTED_WITH": "XMLHttpRequest"}, ) assert response.status_code == 200 assert flexi_input_url not in response.rendered_content alg.use_flexible_inputs = True alg.save() response = get_view_for_user( viewname="algorithms:detail", reverse_kwargs={"slug": slugify(alg.slug)}, client=client, user=editor, method=client.get, follow=True, **{"HTTP_X_REQUESTED_WITH": "XMLHttpRequest"}, ) assert response.status_code == 200 assert flexi_input_url in response.rendered_content