Skip to content

Commit

Permalink
Revert "send freshdesk api (#1896)" (#1900)
Browse files Browse the repository at this point in the history
This reverts commit 63b3cdb.
  • Loading branch information
whabanks authored Jul 23, 2024
1 parent cb3affc commit 5b182b6
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 124 deletions.
40 changes: 1 addition & 39 deletions app/main/views/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def get_template_data(template_id):
methods=["GET", "POST"],
)
@user_has_permissions("manage_templates")
def add_service_template(service_id, template_type, template_folder_id=None): # noqa: C901
def add_service_template(service_id, template_type, template_folder_id=None):
if template_type not in ["sms", "email", "letter"]:
abort(404)
if not current_service.has_permission("letter") and template_type == "letter":
Expand Down Expand Up @@ -791,26 +791,6 @@ def add_service_template(service_id, template_type, template_folder_id=None): #
template_folder_id,
form.template_category_id.data if current_app.config["FF_TEMPLATE_CATEGORY"] else None,
)
# Send the information in form's template_category_other field to Freshdesk
# This code path is a little complex - We do not want to raise an error if the request to Freshdesk fails, only if template creation fails
if form.template_category_other.data:
is_english = get_current_locale(current_app) == "en"
try:
current_user.send_new_template_category_request(
current_user.id,
current_service.id,
form.template_category_other.data if is_english else None,
form.template_category_other.data if not is_english else None,
new_template["data"]["id"],
)
except HTTPError as e:
current_app.logger.error(
f"Failed to send new template category request to Freshdesk: {e} for template {new_template['data']['id']}, data is {form.template_category_other.data}"
)
except AttributeError as e:
current_app.logger.error(
f"Failed to send new template category request to Freshdesk: {e} for template {new_template['data']['id']}, data is {form.template_category_other.data}"
)
except HTTPError as e:
if (
e.status_code == 400
Expand Down Expand Up @@ -941,7 +921,6 @@ def edit_service_template(service_id, template_id): # noqa: C901 TODO: remove t

new_template = get_template(new_template_data, current_service)
template_change = get_template(template, current_service).compare_to(new_template)

if template_change.placeholders_added and not request.form.get("confirm"):
example_column_headings = first_column_headings[new_template.template_type] + list(new_template.placeholders)
return render_template(
Expand Down Expand Up @@ -977,23 +956,6 @@ def edit_service_template(service_id, template_id): # noqa: C901 TODO: remove t
None if form.process_type.data == TC_PRIORITY_VALUE else form.process_type.data,
form.template_category_id.data if current_app.config["FF_TEMPLATE_CATEGORY"] else None,
)
# Send the information in form's template_category_other field to Freshdesk
# This code path is a little complex - We do not want to raise an error if the request to Freshdesk fails, only if template creation fails
if form.template_category_other.data:
is_english = get_current_locale(current_app) == "en"
try:
current_user.send_new_template_category_request(
current_user.id,
current_service.id,
form.template_category_other.data if is_english else None,
form.template_category_other.data if not is_english else None,
template_id,
)
except HTTPError as e:
current_app.logger.error(
f"Failed to send new template category request to Freshdesk: {e} for template {template_id}, data is {form.template_category_other.data}"
)

flash(_("'{}' template saved").format(form.name.data), "default_with_tick")
return redirect(
url_for(
Expand Down
7 changes: 0 additions & 7 deletions app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,6 @@ def send_branding_request(
self.id, serviceID, service_name, org_id, org_name, filename, alt_text_en, alt_text_fr, branding_logo_name
)

def send_new_template_category_request(
self, user_id, service_id, template_category_name_en, template_category_name_fr, template_id
):
user_api_client.send_new_template_category_request(
user_id, service_id, template_category_name_en, template_category_name_fr, template_id
)

def refresh_session_id(self):
self.current_session_id = user_api_client.get_user(self.id).get("current_session_id")
session["current_session_id"] = self.current_session_id
Expand Down
73 changes: 0 additions & 73 deletions tests/app/main/views/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,79 +103,6 @@ def test_delete(self, fake_uuid, mocker):
assert actual_data == {}


class TestSendOtherCategoryInfo:
def test_create_email_template_cat_other_to_freshdesk(
self,
client_request,
mock_create_service_template,
mock_get_template_folders,
mock_get_service_template_when_no_template_exists,
mock_get_template_categories,
mock_send_other_category_to_freshdesk,
active_user_with_permissions,
fake_uuid,
):
client_request.post(
".add_service_template",
service_id=SERVICE_ONE_ID,
template_type="email",
_data={
"name": "new name",
"subject": "Food incoming!",
"template_content": "here's a burrito 🌯",
"template_type": "email",
"template_category_id": TESTING_TEMPLATE_CATEGORY,
"service": SERVICE_ONE_ID,
"process_type": DEFAULT_PROCESS_TYPE,
"button_pressed": "save",
"template_category_other": "hello",
},
_follow_redirects=True,
)
assert mock_create_service_template.called is True
assert mock_send_other_category_to_freshdesk.called is True
mock_send_other_category_to_freshdesk.assert_called_once_with(
active_user_with_permissions["id"], SERVICE_ONE_ID, "hello", None, fake_uuid
)

def test_edit_email_template_cat_other_to_freshdesk(
self,
client_request,
mock_get_template_categories,
mock_get_service_template,
mock_update_service_template,
mock_send_other_category_to_freshdesk,
active_user_with_permissions,
fake_uuid,
):
name = "new name"
content = "template <em>content</em> with & entity"
client_request.post(
".edit_service_template",
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
_data={
"id": fake_uuid,
"name": name,
"template_content": content,
"template_type": "sms",
"template_category_id": DEFAULT_TEMPLATE_CATEGORY_LOW,
"service": SERVICE_ONE_ID,
"template_category_other": "hello",
"reply_to_text": "[email protected]",
},
_follow_redirects=True,
)

mock_update_service_template.assert_called_with(
fake_uuid, name, "sms", content, SERVICE_ONE_ID, None, DEFAULT_PROCESS_TYPE, DEFAULT_TEMPLATE_CATEGORY_LOW
)
assert mock_send_other_category_to_freshdesk.called is True
mock_send_other_category_to_freshdesk.assert_called_once_with(
active_user_with_permissions["id"], SERVICE_ONE_ID, "hello", None, fake_uuid
)


def test_should_show_empty_page_when_no_templates(
client_request,
service_one,
Expand Down
5 changes: 0 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,11 +970,6 @@ def _create(name, type_, content, service, subject=None, process_type=None, pare
return mocker.patch("app.service_api_client.create_service_template", side_effect=_create)


@pytest.fixture(scope="function")
def mock_send_other_category_to_freshdesk(mocker):
return mocker.patch("app.user_api_client.send_new_template_category_request")


@pytest.fixture(scope="function")
def mock_update_service_template(mocker):
def _update(
Expand Down

0 comments on commit 5b182b6

Please sign in to comment.