From f3cec74276beb4e0b22cf8dabc10ac1999dc6c96 Mon Sep 17 00:00:00 2001 From: George Hickman Date: Wed, 6 Sep 2023 16:43:04 +0100 Subject: [PATCH] Remove project creation page from under an org in the staff area Projects should either be created by approving an application or via the Interactive form, this is a holdover from when we could create projects as needed. --- staff/urls.py | 2 - staff/views/orgs.py | 28 +---------- templates/staff/org_detail.html | 3 -- templates/staff/org_project_create.html | 65 ------------------------- tests/unit/staff/views/test_orgs.py | 51 ------------------- 5 files changed, 1 insertion(+), 148 deletions(-) delete mode 100644 templates/staff/org_project_create.html diff --git a/staff/urls.py b/staff/urls.py index 09128d35b..ad4c67c2d 100644 --- a/staff/urls.py +++ b/staff/urls.py @@ -32,7 +32,6 @@ OrgDetail, OrgEdit, OrgList, - OrgProjectCreate, OrgRemoveGitHubOrg, OrgRemoveMember, org_add_github_org, @@ -135,7 +134,6 @@ path("add/", OrgCreate.as_view(), name="org-create"), path("/", OrgDetail.as_view(), name="org-detail"), path("/add-github-org/", org_add_github_org, name="org-add-github-org"), - path("/add-project/", OrgProjectCreate.as_view(), name="org-project-create"), path("/edit/", OrgEdit.as_view(), name="org-edit"), path( "/remove-member/", OrgRemoveMember.as_view(), name="org-membership-remove" diff --git a/staff/views/orgs.py b/staff/views/orgs.py index 52d55c080..b255a0c5a 100644 --- a/staff/views/orgs.py +++ b/staff/views/orgs.py @@ -11,7 +11,7 @@ from jobserver.authorization import CoreDeveloper from jobserver.authorization.decorators import require_permission, require_role -from jobserver.models import Org, OrgMembership, Project, User +from jobserver.models import Org, OrgMembership, User from ..forms import OrgAddGitHubOrgForm, OrgAddMemberForm from ..htmx_tools import get_redirect_url @@ -180,32 +180,6 @@ def get_queryset(self): return qs -@method_decorator(require_role(CoreDeveloper), name="dispatch") -class OrgProjectCreate(CreateView): - fields = ["name"] - model = Project - template_name = "staff/org_project_create.html" - - def dispatch(self, request, *args, **kwargs): - self.org = get_object_or_404(Org, slug=self.kwargs["slug"]) - - return super().dispatch(request, *args, **kwargs) - - def form_valid(self, form): - project = form.save(commit=False) - project.created_by = self.request.user - project.updated_by = self.request.user - project.org = self.org - project.save() - - return redirect(project.get_staff_url()) - - def get_context_data(self, **kwargs): - return super().get_context_data() | { - "org": self.org, - } - - @method_decorator(require_role(CoreDeveloper), name="dispatch") class OrgRemoveGitHubOrg(View): def post(self, request, *args, **kwargs): diff --git a/templates/staff/org_detail.html b/templates/staff/org_detail.html index 864159fbf..cfacae0c3 100644 --- a/templates/staff/org_detail.html +++ b/templates/staff/org_detail.html @@ -48,9 +48,6 @@

{{ org.name }}

diff --git a/templates/staff/org_project_create.html b/templates/staff/org_project_create.html deleted file mode 100644 index 99602f33e..000000000 --- a/templates/staff/org_project_create.html +++ /dev/null @@ -1,65 +0,0 @@ -{% extends "staff/base.html" %} - -{% block metatitle %}{{ org.name }}: Staff Area | OpenSAFELY Jobs{% endblock metatitle %} - -{% block breadcrumbs %} - -{% endblock breadcrumbs %} - -{% block jumbotron %} -
-
-

Create a project

-
-
-{% endblock jumbotron %} - -{% block content %} -
-
-
-
- {% csrf_token %} -
- - Project details - - - {% if form.non_field_errors %} -
    - {% for error in form.non_field_errors %} -
  • {{ error }}
  • - {% endfor %} -
- {% endif %} - - {% include "components/form_text.html" with field=form.name label="Project name" name="name" %} - -
- - - -
-
-
-
-{% endblock content %} diff --git a/tests/unit/staff/views/test_orgs.py b/tests/unit/staff/views/test_orgs.py index 9af901fa9..9f5b4acc6 100644 --- a/tests/unit/staff/views/test_orgs.py +++ b/tests/unit/staff/views/test_orgs.py @@ -1,5 +1,4 @@ import pytest -from django.contrib.auth.models import AnonymousUser from django.contrib.messages.storage.fallback import FallbackStorage from django.core.exceptions import PermissionDenied from django.http import Http404 @@ -11,7 +10,6 @@ OrgDetail, OrgEdit, OrgList, - OrgProjectCreate, OrgRemoveGitHubOrg, OrgRemoveMember, org_add_github_org, @@ -314,55 +312,6 @@ def test_orglist_unauthorized(rf): OrgList.as_view()(request) -def tests_orgprojectcreate_get_success(rf, core_developer): - org = OrgFactory() - - request = rf.get("/") - request.user = core_developer - - response = OrgProjectCreate.as_view()(request, slug=org.slug) - - assert response.status_code == 200 - assert response.context_data["org"] == org - - -def tests_orgprojectcreate_post_success(rf, core_developer): - org = OrgFactory() - - assert org.projects.count() == 0 - - request = rf.post("/", {"name": "Test Project"}) - request.user = core_developer - - response = OrgProjectCreate.as_view()(request, slug=org.slug) - - assert response.status_code == 302 - - project = org.projects.first() - assert project is not None - assert response.url == project.get_staff_url() - assert project.created_by == core_developer - assert project.org == org - - -def tests_orgprojectcreate_unauthorized(rf, core_developer): - org = OrgFactory() - - request = rf.get("/") - request.user = AnonymousUser() - - with pytest.raises(PermissionDenied): - OrgProjectCreate.as_view()(request, slug=org.slug) - - -def tests_orgprojectcreate_unknown_org(rf, core_developer): - request = rf.get("/") - request.user = core_developer - - with pytest.raises(Http404): - OrgProjectCreate.as_view()(request, slug="") - - def test_orgremovegithuborg_success(rf, core_developer): org = OrgFactory(github_orgs=["one", "two"])