Browse Source

Don't let users clone checks if the account is at check limit

pull/366/head
Pēteris Caune 5 years ago
parent
commit
385021b44c
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
4 changed files with 14 additions and 0 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +8
    -0
      hc/front/tests/test_copy.py
  3. +3
    -0
      hc/front/views.py
  4. +2
    -0
      templates/front/details.html

+ 1
- 0
CHANGELOG.md View File

@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
### Bug Fixes ### Bug Fixes
- "Get a single check" API call now supports read-only API keys (#346) - "Get a single check" API call now supports read-only API keys (#346)
- Don't escape HTML in the subject line of notification emails - Don't escape HTML in the subject line of notification emails
- Don't let users clone checks if the account is at check limit
## v1.14.0 - 2020-03-23 ## v1.14.0 - 2020-03-23


+ 8
- 0
hc/front/tests/test_copy.py View File

@ -16,3 +16,11 @@ class CopyCheckTestCase(BaseTestCase):
r = self.client.post(self.copy_url, follow=True) r = self.client.post(self.copy_url, follow=True)
self.assertContains(r, "This is a brand new check") self.assertContains(r, "This is a brand new check")
self.assertContains(r, "Foo (copy)") self.assertContains(r, "Foo (copy)")
def test_it_obeys_limit(self):
self.profile.check_limit = 0
self.profile.save()
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.copy_url)
self.assertEqual(r.status_code, 400)

+ 3
- 0
hc/front/views.py View File

@ -556,6 +556,9 @@ def transfer(request, code):
def copy(request, code): def copy(request, code):
check = _get_check_for_user(request, code) check = _get_check_for_user(request, code)
if check.project.num_checks_available() <= 0:
return HttpResponseBadRequest()
copied = Check(project=check.project) copied = Check(project=check.project)
copied.name = check.name + " (copy)" copied.name = check.name + " (copy)"
copied.desc, copied.tags = check.desc, check.tags copied.desc, copied.tags = check.desc, check.tags


+ 2
- 0
templates/front/details.html View File

@ -223,11 +223,13 @@
<p>Copy, Transfer, or permanently remove this check.</p> <p>Copy, Transfer, or permanently remove this check.</p>
<div class="text-right"> <div class="text-right">
{% if project.num_checks_available > 0 %}
<button <button
id="copy-btn" id="copy-btn"
data-toggle="modal" data-toggle="modal"
data-target="#copy-modal" data-target="#copy-modal"
class="btn btn-sm btn-default">Create a Copy&hellip;</button> class="btn btn-sm btn-default">Create a Copy&hellip;</button>
{% endif %}
<button <button
id="transfer-btn" id="transfer-btn"
data-toggle="modal" data-toggle="modal"


Loading…
Cancel
Save