feat: ToS reminder during instance creation and ToS link in footer
closes: https://gitea.hostea.org/Hostea/dashboard/issues/30tos-reminder
parent
a95158f3df
commit
3ecd2289dc
|
@ -13,6 +13,11 @@
|
|||
<a class="license__link" rel="noreferrer" href="https://hostea.org/about" target="_blank"
|
||||
> About</a
|
||||
>
|
||||
<span class="footer__column-divider--mobile-visible">|</span>
|
||||
<a class="license__link" rel="noreferrer" href="https://hostea.org/tos" target="_blank"
|
||||
> Terms of Service</a
|
||||
>
|
||||
|
||||
</span>
|
||||
</div>
|
||||
<div class="footer__column">
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,21 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
</fieldset>
|
||||
<label class="dash__form-label--inline" for="tos">
|
||||
<span>
|
||||
I agree to the
|
||||
<a href="https://hostea.org/tos/">terms and conditions</a> associated with using Hostea
|
||||
</span>
|
||||
<input
|
||||
class="form__input"
|
||||
name="tos"
|
||||
required
|
||||
id="tos"
|
||||
type="checkbox"
|
||||
value="agreed"
|
||||
/>
|
||||
|
||||
</label>
|
||||
<div class="form__action-container">
|
||||
<button class="form__submit" type="submit">Create Instance</button>
|
||||
</div>
|
||||
|
|
|
@ -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]
|
||||
)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue