Skip to content

Commit

Permalink
Merge pull request #3528 from opensafely-core/remove-org-project-create
Browse files Browse the repository at this point in the history
Remove project creation page from under an org in the staff area
  • Loading branch information
ghickman authored Sep 11, 2023
2 parents 85c05c8 + f3cec74 commit 2817e0d
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 148 deletions.
2 changes: 0 additions & 2 deletions staff/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
OrgDetail,
OrgEdit,
OrgList,
OrgProjectCreate,
OrgRemoveGitHubOrg,
OrgRemoveMember,
org_add_github_org,
Expand Down Expand Up @@ -135,7 +134,6 @@
path("add/", OrgCreate.as_view(), name="org-create"),
path("<slug>/", OrgDetail.as_view(), name="org-detail"),
path("<slug>/add-github-org/", org_add_github_org, name="org-add-github-org"),
path("<slug>/add-project/", OrgProjectCreate.as_view(), name="org-project-create"),
path("<slug>/edit/", OrgEdit.as_view(), name="org-edit"),
path(
"<slug>/remove-member/", OrgRemoveMember.as_view(), name="org-membership-remove"
Expand Down
28 changes: 1 addition & 27 deletions staff/views/orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 0 additions & 3 deletions templates/staff/org_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ <h1 class="display-4">{{ org.name }}</h1>
<div class="d-flex">
<a class="btn btn-danger mr-1" href="{{ org.get_edit_url }}">Edit</a>
<a class="btn btn-primary mr-1" href="{{ org.get_absolute_url }}">View on Site</a>
<a class="btn btn-primary" href="{% url 'staff:org-project-create' slug=org.slug %}">
Add Project
</a>
</div>
</div>
</div>
Expand Down
65 changes: 0 additions & 65 deletions templates/staff/org_project_create.html

This file was deleted.

51 changes: 0 additions & 51 deletions tests/unit/staff/views/test_orgs.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,7 +10,6 @@
OrgDetail,
OrgEdit,
OrgList,
OrgProjectCreate,
OrgRemoveGitHubOrg,
OrgRemoveMember,
org_add_github_org,
Expand Down Expand Up @@ -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"])

Expand Down

0 comments on commit 2817e0d

Please sign in to comment.