Browse Source

Fix db field overflow when copying a check with a long name

pull/457/head
Pēteris Caune 4 years ago
parent
commit
5d650f07fb
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 19 additions and 1 deletions
  1. +3
    -0
      CHANGELOG.md
  2. +10
    -0
      hc/front/tests/test_copy.py
  3. +6
    -1
      hc/front/views.py

+ 3
- 0
CHANGELOG.md View File

@ -18,6 +18,9 @@ All notable changes to this project will be documented in this file.
- Implement badge mode (up/down vs up/late/down) selector (#282) - Implement badge mode (up/down vs up/late/down) selector (#282)
- Add Ping.exitstatus field, store client's reported exit status values (#455) - Add Ping.exitstatus field, store client's reported exit status values (#455)
## Bug Fixes
- Fix db field overflow when copying a check with a long name
## v1.17.0 - 2020-10-14 ## v1.17.0 - 2020-10-14
## Improvements ## Improvements


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

@ -41,3 +41,13 @@ class CopyCheckTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
r = self.client.post(self.copy_url) r = self.client.post(self.copy_url)
self.assertEqual(r.status_code, 403) self.assertEqual(r.status_code, 403)
def test_it_handles_long_check_name(self):
self.check.name = "A" * 100
self.check.save()
self.client.login(username="[email protected]", password="password")
self.client.post(self.copy_url)
q = Check.objects.filter(name="A" * 90 + "... (copy)")
self.assertTrue(q.exists())

+ 6
- 1
hc/front/views.py View File

@ -623,8 +623,13 @@ def copy(request, code):
if check.project.num_checks_available() <= 0: if check.project.num_checks_available() <= 0:
return HttpResponseBadRequest() return HttpResponseBadRequest()
new_name = check.name + " (copy)"
# Make sure we don't exceed the 100 character db field limit:
if len(new_name) > 100:
new_name = check.name[:90] + "... (copy)"
copied = Check(project=check.project) copied = Check(project=check.project)
copied.name = check.name + " (copy)"
copied.name = new_name
copied.desc, copied.tags = check.desc, check.tags copied.desc, copied.tags = check.desc, check.tags
copied.subject, copied.subject_fail = check.subject, check.subject_fail copied.subject, copied.subject_fail = check.subject, check.subject_fail
copied.methods = check.methods copied.methods = check.methods


Loading…
Cancel
Save