diff --git a/accounts/templates/common/components/footer.html b/accounts/templates/common/components/footer.html
index e82e052..4b6f4ba 100644
--- a/accounts/templates/common/components/footer.html
+++ b/accounts/templates/common/components/footer.html
@@ -13,6 +13,11 @@
About
+ |
+ Terms of Service
+
diff --git a/common-static/css/main.css b/common-static/css/main.css
index d32d1d2..0a7229d 100644
--- a/common-static/css/main.css
+++ b/common-static/css/main.css
@@ -549,6 +549,21 @@ footer {
padding: 0 10px;
}
+.dash__form-label--inline {
+ display: flex;
+ flex-direction: row-reverse;
+}
+
+.dash__form-label--inline > span {
+ flex: 3;
+ margin: auto;
+}
+
+
+.dash__form-label--inline > input {
+ width: 10%;
+}
+
fieldset {
border: none;
}
diff --git a/dash/templates/dash/instances/new/index.html b/dash/templates/dash/instances/new/index.html
index 0173fed..4522ff0 100644
--- a/dash/templates/dash/instances/new/index.html
+++ b/dash/templates/dash/instances/new/index.html
@@ -50,6 +50,21 @@
{% endfor %}
+
diff --git a/dash/tests.py b/dash/tests.py
index 899adea..cdf6e8b 100644
--- a/dash/tests.py
+++ b/dash/tests.py
@@ -77,7 +77,7 @@ def infra_custom_config(test_name: str):
def create_instance_util(
t: TestCase, c: Client, instance_name: str, config: InstanceConfiguration
):
- payload = {"name": instance_name, "configuration": config.name}
+ payload = {"name": instance_name, "configuration": config.name, "tos": "agreed"}
resp = c.post(reverse("dash.instances.new"), payload)
t.assertEqual(resp.status_code, 302)
@@ -298,3 +298,36 @@ class CreateInstance(TestCase):
).exists(),
False,
)
+
+ def test_tos_agreement_check(self):
+ c = Client()
+ login_util(self, c, "accounts.home")
+ urls = [(reverse("dash.instances.new"), "Instance Configuration")]
+ for (url, test) in urls:
+ print(f"[*] Testing URI: {url}")
+ resp = c.get(url)
+ self.assertEqual(resp.status_code, 200)
+ self.assertEqual(b"Billing" in resp.content, True)
+ self.assertEqual(b"Support" in resp.content, True)
+ self.assertEqual(b"Logout" in resp.content, True)
+ self.assertEqual(str.encode(test) in resp.content, True)
+
+ # create instance
+ payload = {
+ "name": "test_tos_agreement_check",
+ "configuration": self.instance_config[0].name,
+ }
+
+ self.assertEqual(Instance.objects.filter(name=payload["name"]).exists(), False)
+ resp = c.post(reverse("dash.instances.new"), payload)
+ self.assertEqual(resp.status_code, 400)
+
+ self.assertEqual(
+ b"created without agreeing to the terms and conditions" in resp.content,
+ True,
+ )
+
+ instance_name = "test_create_instance_renders"
+ create_instance_util(
+ t=self, c=c, instance_name=instance_name, config=self.instance_config[0]
+ )
diff --git a/dash/views.py b/dash/views.py
index 383a072..3e2c904 100644
--- a/dash/views.py
+++ b/dash/views.py
@@ -80,6 +80,21 @@ def create_instance(request):
ctx = get_ctx()
return render(request, "dash/instances/new/index.html", context=ctx)
+ if "tos" not in request.POST:
+ ctx = get_ctx()
+ ctx["error"] = {
+ "title": "Can't create instance",
+ "reason": "Hostea instance can't be created without agreeing to the terms and conditions",
+ }
+ return render(request, "dash/instances/new/index.html", status=400, context=ctx)
+ if str.strip(request.POST["tos"]) != "agreed":
+ ctx = get_ctx()
+ ctx["error"] = {
+ "title": "Can't create instance",
+ "reason": "Hostea instance can't be created without agreeing to the terms and conditions",
+ }
+ return render(request, "dash/instances/new/index.html", status=400, context=ctx)
+
name = request.POST["name"]
configuration = request.POST["configuration"]
try: