forked from GithubBackups/healthchecks
Fix db field overflow when copying a check with a long name
This commit is contained in:
parent
9623e3eacb
commit
5d650f07fb
@ -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
|
||||||
|
@ -41,3 +41,13 @@ class CopyCheckTestCase(BaseTestCase):
|
|||||||
self.client.login(username="bob@example.org", password="password")
|
self.client.login(username="bob@example.org", 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="alice@example.org", password="password")
|
||||||
|
self.client.post(self.copy_url)
|
||||||
|
|
||||||
|
q = Check.objects.filter(name="A" * 90 + "... (copy)")
|
||||||
|
self.assertTrue(q.exists())
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user