Skip to content

Commit

Permalink
Remove preact_create_group_form feature flag
Browse files Browse the repository at this point in the history
...and the legacy code that was only used when the feature flag was
disabled.
  • Loading branch information
seanh committed Aug 15, 2024
1 parent 4e958f6 commit 7df5463
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 223 deletions.
1 change: 0 additions & 1 deletion h/models/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"pdf_custom_text_layer": "Use custom text layer in PDFs for improved text selection",
"styled_highlight_clusters": "Style different clusters of highlights in the client",
"client_user_profile": "Enable client-side user profile and preferences management",
"preact_create_group_form": "Enable the new Preact version of the create group form",
}


Expand Down
20 changes: 0 additions & 20 deletions h/templates/groups/legacy_create.html.jinja2

This file was deleted.

59 changes: 0 additions & 59 deletions h/views/groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import deform
from pyramid import httpexceptions
from pyramid.config import not_
from pyramid.view import view_config, view_defaults

from h import form, i18n
Expand All @@ -10,67 +8,10 @@
_ = i18n.TranslationString


@view_defaults(
route_name="group_create",
renderer="h:templates/groups/legacy_create.html.jinja2",
is_authenticated=True,
feature=not_("preact_create_group_form"),
)
class LegacyGroupCreateController:
def __init__(self, request):
self.request = request

self.schema = group_schema(autofocus_name=True).bind(request=self.request)

submit = deform.Button(
title=_("Create group"),
css_class="primary-action-btn "
"group-form__submit-btn "
"js-create-group-create-btn",
)
self.form = request.create_form(
self.schema, css_class="group-form__form", buttons=(submit,)
)

@view_config(request_method="GET")
def get(self):
"""Render the form for creating a new group."""
return self._template_data()

@view_config(request_method="POST")
def post(self):
"""Respond to a submission of the create group form."""

def on_success(appstruct):
group_create_service = self.request.find_service(name="group_create")
group = group_create_service.create_private_group(
name=appstruct["name"],
description=appstruct.get("description"),
userid=self.request.authenticated_userid,
)

url = self.request.route_path(
"group_read", pubid=group.pubid, slug=group.slug
)
return httpexceptions.HTTPSeeOther(url)

return form.handle_form_submission(
self.request,
self.form,
on_success=on_success,
on_failure=self._template_data,
)

def _template_data(self):
"""Return the data needed to render this controller's page."""
return {"form": self.form.render()}


@view_defaults(
route_name="group_create",
renderer="h:templates/groups/create.html.jinja2",
is_authenticated=True,
feature="preact_create_group_form",
)
class GroupCreateController:
def __init__(self, request):
Expand Down
27 changes: 0 additions & 27 deletions tests/functional/h/views/group_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,6 @@
pytestmark = pytest.mark.usefixtures("init_elasticsearch")


class TestGroupCreateController:
@pytest.mark.usefixtures("with_logged_in_user")
def test_submit_create_group_form_without_xhr_returns_full_html_page(
self, filled_out_group_form
):
response = filled_out_group_form.submit().follow()

assert response.text.startswith("<!DOCTYPE html>")

@pytest.mark.usefixtures("with_logged_in_user")
def test_submit_create_group_form_with_xhr_returns_partial_html_snippet(
self, filled_out_group_form
):
response = filled_out_group_form.submit(xhr=True)

assert response.body.strip(b"\n").startswith(b"<form")
assert response.content_type == "text/plain"

@pytest.fixture
def filled_out_group_form(self, app):
response = app.get("/groups/new")
group_form = response.forms["deform"]
group_form["name"] = "My New Group"

return group_form


class TestGroupEditController:
# These permissions tests are a stand-in for testing all functionality of
# the group edit controller as they all need the same permission. We will
Expand Down
116 changes: 0 additions & 116 deletions tests/unit/h/views/groups_test.py
Original file line number Diff line number Diff line change
@@ -1,119 +1,10 @@
from unittest import mock

import pytest
from h_matchers import Any
from pyramid.httpexceptions import HTTPMovedPermanently

from h.traversal.group import GroupContext
from h.views import groups as views


@pytest.mark.usefixtures("group_create_service", "handle_form_submission", "routes")
class TestLegacyGroupCreateController:
def test_get_renders_form(self, controller):
controller.form = form_validating_to({})

result = controller.get()

assert result == {"form": "valid form"}

def test_post_calls_handle_form_submission(
self, controller, handle_form_submission
):
controller.post()

handle_form_submission.assert_called_once_with(
controller.request, controller.form, Any.function(), Any.function()
)

def test_post_returns_handle_form_submission(
self, controller, handle_form_submission
):
assert controller.post() == handle_form_submission.return_value

def test_post_creates_new_group_if_form_valid(
self, controller, group_create_service, handle_form_submission, pyramid_config
):
pyramid_config.testing_securitypolicy("ariadna")

# If the form submission is valid then handle_form_submission() should
# call on_success() with the appstruct.
def call_on_success( # pylint: disable=unused-argument
request, form, on_success, on_failure
):
on_success({"name": "my_new_group", "description": "foobar"})

handle_form_submission.side_effect = call_on_success

controller.post()

assert group_create_service.create_private_group.call_args_list == [
mock.call(name="my_new_group", userid="ariadna", description="foobar")
]

def test_post_redirects_if_form_valid(
self,
controller,
handle_form_submission,
matchers,
group_create_service,
factories,
):
group = factories.Group()
group_create_service.create_private_group.return_value = group

# If the form submission is valid then handle_form_submission() should
# return the redirect that on_success() returns.
def return_on_success( # pylint: disable=unused-argument
request, form, on_success, on_failure
):
return on_success({"name": "my_new_group"})

handle_form_submission.side_effect = return_on_success

response = controller.post()

assert response == matchers.Redirect303To(f"/g/{group.pubid}/{group.slug}")

def test_post_does_not_create_group_if_form_invalid(
self, controller, group_create_service, handle_form_submission
):
# If the form submission is invalid then handle_form_submission() should
# call on_failure().
def call_on_failure( # pylint: disable=unused-argument
request, form, on_success, on_failure
):
on_failure()

handle_form_submission.side_effect = call_on_failure

controller.post()

assert not group_create_service.create_private_group.called

def test_post_returns_template_data_if_form_invalid(
self, controller, handle_form_submission
):
# If the form submission is invalid then handle_form_submission() should
# return the template data that on_failure() returns.
def return_on_failure( # pylint: disable=unused-argument
request, form, on_success, on_failure
):
return on_failure()

handle_form_submission.side_effect = return_on_failure

assert controller.post() == {"form": controller.form.render.return_value}

@pytest.fixture
def controller(self, pyramid_request):
return views.LegacyGroupCreateController(pyramid_request)

@pytest.fixture
def handle_form_submission(self, patch):
return patch("h.views.groups.form.handle_form_submission")


class TestGroupCreateController:
def test_get(self, controller):
result = controller.get()
Expand Down Expand Up @@ -175,13 +66,6 @@ def render(self):
return self.appstruct


def form_validating_to(appstruct):
form = mock.Mock()
form.validate.return_value = appstruct
form.render.return_value = "valid form"
return form


@pytest.fixture
def routes(pyramid_config):
pyramid_config.add_route("group_read", "/g/{pubid}/{slug}")

0 comments on commit 7df5463

Please sign in to comment.