diff --git a/apps/tests/test_app_settings_view.py b/apps/tests/test_app_settings_view.py index 7218261c..73655e50 100644 --- a/apps/tests/test_app_settings_view.py +++ b/apps/tests/test_app_settings_view.py @@ -67,7 +67,7 @@ def test_user_can_edit_true(self): self.assertEqual(response.status_code, 302) - url = f"/{self.project.slug}/" + f"apps/settings/{self.app_instance.id}" + url = f"/projects/{self.project.slug}/" + f"apps/settings/{self.app_instance.id}" response = c.get(url) @@ -84,7 +84,7 @@ def test_user_can_edit_false(self): self.app.user_can_edit = True self.app.save() - url = f"/{self.project.slug}/" + f"apps/settings/{self.app_instance.id}" + url = f"/projects/{self.project.slug}/" + f"apps/settings/{self.app_instance.id}" response = c.get(url) diff --git a/apps/tests/test_create_app_view.py b/apps/tests/test_create_app_view.py index 7d616f18..9c14c918 100644 --- a/apps/tests/test_create_app_view.py +++ b/apps/tests/test_create_app_view.py @@ -60,7 +60,7 @@ def test_has_permission(self): self.assertEqual(response.status_code, 302) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) @@ -75,11 +75,11 @@ def test_has_reached_app_limit(self): self.assertEqual(response.status_code, 302) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) - response = c.post(f"/{project.slug}/apps/create/jupyter-lab") + response = c.post(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) @@ -96,11 +96,11 @@ def test_missing_access_to_project(self): self.assertEqual(response.status_code, 302) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) - response = c.post(f"/{project.slug}/apps/create/jupyter-lab") + response = c.post(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) @@ -119,7 +119,7 @@ def test_has_permission_when_none(self): self.assertEqual(response.status_code, 302) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) @@ -134,7 +134,7 @@ def test_has_permission_when_not_specified(self): self.assertEqual(response.status_code, 302) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) @@ -153,13 +153,13 @@ def test_has_permission_project_level(self): self.assertEqual(response.status_code, 302) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) project = self.get_data() - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) @@ -171,7 +171,7 @@ def test_has_permission_project_level(self): project=project, ) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) @@ -186,7 +186,7 @@ def test_permission_overrides_reached_app_limit(self): self.assertEqual(response.status_code, 302) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) @@ -202,7 +202,7 @@ def test_permission_overrides_reached_app_limit(self): self.user = User.objects.get(username=test_user["email"]) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) @@ -217,7 +217,7 @@ def test_app_limit_is_per_project(self): self.assertEqual(response.status_code, 302) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) @@ -226,7 +226,7 @@ def test_app_limit_is_per_project(self): project.authorized.add(user2) project.save() - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) @@ -238,11 +238,11 @@ def test_app_limit_is_per_project(self): project=project, ) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) @@ -261,7 +261,7 @@ def test_app_limit_altered_for_project(self): project.save() - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) @@ -276,7 +276,7 @@ def test_app_limit_altered_for_project_v2(self): self.assertEqual(response.status_code, 302) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) @@ -288,7 +288,7 @@ def test_app_limit_altered_for_project_v2(self): project=project, ) - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 403) @@ -296,6 +296,6 @@ def test_app_limit_altered_for_project_v2(self): project.save() - response = c.get(f"/{project.slug}/apps/create/jupyter-lab") + response = c.get(f"/projects/{project.slug}/apps/create/jupyter-lab") self.assertEqual(response.status_code, 200) diff --git a/apps/tests/test_delete_app_view.py b/apps/tests/test_delete_app_view.py index 846240c5..c80668c0 100644 --- a/apps/tests/test_delete_app_view.py +++ b/apps/tests/test_delete_app_view.py @@ -65,7 +65,7 @@ def test_user_can_delete_false(self): self.assertEqual(response.status_code, 302) - url = f"/{self.project.slug}/apps/delete/" + f"{self.category.slug}/{self.app_instance.id}" + url = f"/projects/{self.project.slug}/apps/delete/" + f"{self.category.slug}/{self.app_instance.id}" response = c.get(url) @@ -83,7 +83,7 @@ def test_user_can_delete_true(self): self.app.save() with patch("apps.tasks.delete_resource.delay") as mock_task: - url = f"/{self.project.slug}/apps/delete/" + f"{self.category.slug}/{self.app_instance.id}" + url = f"/projects/{self.project.slug}/apps/delete/" + f"{self.category.slug}/{self.app_instance.id}" response = c.get(url) diff --git a/apps/tests/test_get_status_view.py b/apps/tests/test_get_status_view.py index 6810aac1..4130724b 100644 --- a/apps/tests/test_get_status_view.py +++ b/apps/tests/test_get_status_view.py @@ -42,7 +42,7 @@ def test_user_has_access(self): self.assertEqual(response.status_code, 302) - url = f"/{self.project.slug}/apps/status" + url = f"/projects/{self.project.slug}/apps/status" response = c.post(url, {"apps": [self.app_instance.id]}) @@ -51,7 +51,7 @@ def test_user_has_access(self): def test_user_has_no_access(self): c = Client() - url = f"/{self.project.slug}/apps/status" + url = f"/projects/{self.project.slug}/apps/status" response = c.post(url, {"apps": [self.app_instance.id]}) @@ -62,7 +62,7 @@ def test_user_has_no_access(self): self.assertEqual(response.status_code, 200) - url = f"/{self.project.slug}/apps/status" + url = f"/projects/{self.project.slug}/apps/status" response = c.post(url, {"apps": [self.app_instance.id]}) @@ -76,7 +76,7 @@ def test_apps_empty(self): self.assertEqual(response.status_code, 302) - url = f"/{self.project.slug}/apps/status" + url = f"/projects/{self.project.slug}/apps/status" response = c.post(url, {"apps": []}) diff --git a/cypress/e2e/ui-tests/test-public-webpages.cy.js b/cypress/e2e/ui-tests/test-public-webpages.cy.js index 930ba030..cd82036f 100644 --- a/cypress/e2e/ui-tests/test-public-webpages.cy.js +++ b/cypress/e2e/ui-tests/test-public-webpages.cy.js @@ -30,7 +30,6 @@ describe("Tests of the public pages of the website", () => { cy.get("li.nav-item a").contains("User guide").click() cy.url().should("include", "/docs/") cy.get('[data-cy="sidebar-title"]').should('contain', 'user guide') // check that the sidebar title is there, comes from our templates - cy.get('.col-lg-8 > h1').should('contain', 'Congratulations') // check that the page content is there, comes from django-wiki templates }) it("should open the signup page on link click", () => { diff --git a/cypress/e2e/ui-tests/test-project-as-superuser.cy.js b/cypress/e2e/ui-tests/test-superuser-functionality.cy.js similarity index 92% rename from cypress/e2e/ui-tests/test-project-as-superuser.cy.js rename to cypress/e2e/ui-tests/test-superuser-functionality.cy.js index 1754d8da..96e839a2 100644 --- a/cypress/e2e/ui-tests/test-project-as-superuser.cy.js +++ b/cypress/e2e/ui-tests/test-superuser-functionality.cy.js @@ -363,4 +363,35 @@ describe("Test superuser access", () => { }) + it("can add pages to user docs", () => { + + const root_article_name = "user-documentation" + const root_article_content = "user-documentation-homepage" + const regular_article_name ="regular-article" + const regular_article_slug ="regular-article" + const regular_article_content = "regular-article-content" + + cy.log("Creating the root article") + cy.visit("/docs/") + cy.get('h1').should('contain', 'Congratulations') // check that django-wiki was correctly installed + cy.get('#id_title').clear().type(root_article_name) + cy.get('#id_content').clear().type(root_article_content) + cy.get('button[name="save_changes"]').click() + cy.log("Checking that the root article was successfully created") + cy.get('h1#article-title').contains(root_article_name) + cy.get('div.wiki-article').contains(root_article_content) + + cy.log("Adding a regular article") + cy.get(".btn-group").get(".btn").contains("Add a new article").click() + cy.get(".btn-group").get("a.dropdown-item").contains("New article below").click() + cy.url().should("include", "/docs/_create/") + cy.get('#id_title').clear().type(regular_article_name) + cy.get('#id_content').clear().type(regular_article_content) + cy.get('button[name="save_changes"]').click() + cy.log("Checking that the regular article was successfully created") + cy.url().should("include", regular_article_slug) + cy.get('h1#article-title').contains(regular_article_name) + cy.get('div.wiki-article').contains(regular_article_content) + }) + }) diff --git a/projects/tests/test_grant_access_to_project_view.py b/projects/tests/test_grant_access_to_project_view.py index 6bdb1849..2b96f5e7 100644 --- a/projects/tests/test_grant_access_to_project_view.py +++ b/projects/tests/test_grant_access_to_project_view.py @@ -39,7 +39,7 @@ def test_grant_access_to_user(self): project = self.get_data() response = self.client.post( - f"/{project.slug}/project/access/grant/", + f"/projects/{project.slug}/project/access/grant/", {"selected_user": test_user_2["email"]}, ) @@ -72,7 +72,7 @@ def test_grant_access_to_user_no_access(self): project = self.get_data(user=self.user2) response = self.client.post( - f"/{project.slug}/project/access/grant/", + f"/projects/{project.slug}/project/access/grant/", {"selected_user": test_user_2["email"]}, ) @@ -89,7 +89,7 @@ def test_grant_access_to_non_existing_user(self): project = self.get_data() response = self.client.post( - f"/{project.slug}/project/access/grant/", + f"/projects/{project.slug}/project/access/grant/", {"selected_user": "non_existing_user"}, ) diff --git a/projects/tests/test_revoke_access_to_project_view.py b/projects/tests/test_revoke_access_to_project_view.py index 9760c36e..903b1921 100644 --- a/projects/tests/test_revoke_access_to_project_view.py +++ b/projects/tests/test_revoke_access_to_project_view.py @@ -42,7 +42,7 @@ def test_revoke_access_to_user(self): project = self.get_data() response = self.client.post( - f"/{project.slug}/project/access/revoke/", + f"/projects/{project.slug}/project/access/revoke/", {"selected_user": test_user_2["email"]}, ) @@ -71,7 +71,7 @@ def test_revoke_access_non_existing_user(self): project = self.get_data() response = self.client.post( - f"/{project.slug}/project/access/revoke/", + f"/projects/{project.slug}/project/access/revoke/", {"selected_user": "non_existing_user"}, ) @@ -88,7 +88,7 @@ def test_revoke_access_user_no_access_to_project(self): project = self.get_data() response = self.client.post( - f"/{project.slug}/project/access/revoke/", + f"/projects/{project.slug}/project/access/revoke/", {"selected_user": test_user_3["email"]}, ) @@ -107,7 +107,7 @@ def test_revoke_access_can_not_remove_if_not_owner(self): project.authorized.add(self.user3) response = self.client.post( - f"/{project.slug}/project/access/revoke/", + f"/projects/{project.slug}/project/access/revoke/", {"selected_user": test_user_3["email"]}, ) diff --git a/projects/tests/test_update_pattern_view.py b/projects/tests/test_update_pattern_view.py index 5c454315..aeb64a56 100644 --- a/projects/tests/test_update_pattern_view.py +++ b/projects/tests/test_update_pattern_view.py @@ -32,7 +32,7 @@ def test_update_pattern_view(self): # Test with valid pattern response = self.client.post( - f"/{project.slug}/pattern/update/", + f"/projects/{project.slug}/pattern/update/", {"pattern": "pattern-1"}, ) @@ -40,7 +40,7 @@ def test_update_pattern_view(self): # Test with invalid pattern response = self.client.post( - f"/{project.slug}/pattern/update/", + f"/projects/{project.slug}/pattern/update/", {"pattern": "pattern-0"}, ) @@ -55,7 +55,7 @@ def test_update_pattern_view_no_access(self): project = self.get_data() response = self.client.post( - f"/{project.slug}/pattern/update/", + f"/projects/{project.slug}/pattern/update/", {"pattern": "pattern-1"}, ) diff --git a/projects/urls.py b/projects/urls.py index 3afd7942..6af75800 100644 --- a/projects/urls.py +++ b/projects/urls.py @@ -18,13 +18,13 @@ app_name = "projects" User = get_user_model() basicpatterns = [ - path("projects/", views.IndexView.as_view(), name="index"), + path("", views.IndexView.as_view(), name="index"), path( - "projects/create/", + "create/", login_required(views.CreateProjectView.as_view()), name="create", ), - path("projects/templates/", views.project_templates, name="project_templates"), + path("templates/", views.project_templates, name="project_templates"), path("/", views.DetailsView.as_view(), name="details"), path( "/environments/create/", @@ -103,58 +103,3 @@ urlpatterns = basicpatterns + extrapatterns else: urlpatterns = basicpatterns - - -# Related to SS-861 -# Everying below this comment should be removed once the new urls are used everywhere by users. -# This was written on 2024-02-16 - - -class CustomRedirectView(View): - def get_redirect_url(self, *args, **kwargs): - # Extract the project_slug from kwargs - # Construct the new URL - return f"{self.request.get_full_path()}".replace(f"/{self.request.user}", "") - - def get(self, request, *args, **kwargs): - url = self.get_redirect_url(*args, **kwargs) - return HttpResponseRedirect(url) - - -urlpatterns += [ - path("//", CustomRedirectView.as_view(), name="redirect_details"), - path("//project/status/", CustomRedirectView.as_view(), name="redirect_status"), - path("//settings/", CustomRedirectView.as_view(), name="settings"), - path("//delete/", CustomRedirectView.as_view(), name="delete"), - path( - "//details/change/", - CustomRedirectView.as_view(), - name="redirect_change_description", - ), - path( - "//pattern/update/", - CustomRedirectView.as_view(), - name="redirect_update_pattern", - ), - path( - "//project/publish/", - CustomRedirectView.as_view(), - name="redirect_publish_project", - ), - path( - "//project/access/grant/", - CustomRedirectView.as_view(), - name="redirect_grant_access", - ), - path( - "//project/access/revoke/", - CustomRedirectView.as_view(), - name="redirect_revoke_access", - ), - path( - "//project/status/", - CustomRedirectView.as_view(), - name="redirect_get_status", - ), -] -# End of temporary code diff --git a/projects/views.py b/projects/views.py index 66df4dce..5af8b993 100644 --- a/projects/views.py +++ b/projects/views.py @@ -374,7 +374,7 @@ def post(self, request, project_slug): log.save() - return HttpResponseRedirect(f"/{project_slug}/settings?template=access") + return HttpResponseRedirect(f"/projects/{project_slug}/settings?template=access") @method_decorator( @@ -517,7 +517,7 @@ def post(self, request, *args, **kwargs): ) l2.save() - next_page = request.POST.get("next", "/{}".format(project.slug)) + next_page = request.POST.get("next", "/projects/{}".format(project.slug)) return HttpResponseRedirect(next_page, {"message": "Created project"}) diff --git a/studio/urls.py b/studio/urls.py index 62da86b0..77e99a01 100644 --- a/studio/urls.py +++ b/studio/urls.py @@ -43,17 +43,17 @@ # for django-wiki path("docs/notifications/", include("django_nyt.urls")), path("docs/", include("wiki.urls")), + path("projects/", include("projects.urls", namespace="projects")), path("", include("common.urls", namespace="common")), path("", include("models.urls", namespace="models")), path("", include("portal.urls", namespace="portal")), path("", include("news.urls", namespace="news")), path("", include("collections_module.urls", namespace="collections_module")), - path("", include("projects.urls", namespace="projects")), path( "//monitor/", include("monitor.urls", namespace="monitor"), ), - path("/apps/", include("apps.urls", namespace="apps")), + path("projects//apps/", include("apps.urls", namespace="apps")), ] + staticfiles_urlpatterns() + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)