django-snapnote 0.1.1__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/CHANGELOG.md +5 -0
  2. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/PKG-INFO +23 -1
  3. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/README.md +21 -0
  4. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/pyproject.toml +1 -0
  5. django_snapnote-0.2.0/src/snapnote/__init__.py +1 -0
  6. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/checks.py +13 -0
  7. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/conf.py +9 -0
  8. django_snapnote-0.2.0/src/snapnote/notifiers.py +147 -0
  9. django_snapnote-0.2.0/tests/test_jira.py +98 -0
  10. django_snapnote-0.1.1/src/snapnote/__init__.py +0 -1
  11. django_snapnote-0.1.1/src/snapnote/notifiers.py +0 -42
  12. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/.gitignore +0 -0
  13. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/LICENSE +0 -0
  14. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/e2e/smoke.mjs +0 -0
  15. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/package-lock.json +0 -0
  16. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/package.json +0 -0
  17. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/AnnotationEditor.tsx +0 -0
  18. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/App.tsx +0 -0
  19. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/api.ts +0 -0
  20. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/capture.ts +0 -0
  21. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/drawing.test.ts +0 -0
  22. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/drawing.ts +0 -0
  23. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/icons.tsx +0 -0
  24. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/main.tsx +0 -0
  25. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/styles.css +0 -0
  26. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/types.ts +0 -0
  27. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/src/vite-env.d.ts +0 -0
  28. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/tsconfig.json +0 -0
  29. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/frontend/vite.config.ts +0 -0
  30. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/admin.py +0 -0
  31. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/apps.py +0 -0
  32. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/forms.py +0 -0
  33. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/locale/es/LC_MESSAGES/django.mo +0 -0
  34. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/locale/es/LC_MESSAGES/django.po +0 -0
  35. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/management/__init__.py +0 -0
  36. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/management/commands/__init__.py +0 -0
  37. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/management/commands/snapnote_purge.py +0 -0
  38. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/middleware.py +0 -0
  39. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/migrations/0001_initial.py +0 -0
  40. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/migrations/__init__.py +0 -0
  41. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/models.py +0 -0
  42. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/permissions.py +0 -0
  43. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/signals.py +0 -0
  44. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/static/snapnote/management.css +0 -0
  45. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/static/snapnote/snapnote.js +0 -0
  46. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/templates/snapnote/base.html +0 -0
  47. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/templates/snapnote/button.html +0 -0
  48. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/templates/snapnote/includes/status_badge.html +0 -0
  49. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/templates/snapnote/ticket_confirm_delete.html +0 -0
  50. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/templates/snapnote/ticket_detail.html +0 -0
  51. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/templates/snapnote/ticket_list.html +0 -0
  52. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/templatetags/__init__.py +0 -0
  53. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/templatetags/snapnote_tags.py +0 -0
  54. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/urls.py +0 -0
  55. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/src/snapnote/views.py +0 -0
  56. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/__init__.py +0 -0
  57. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/conftest.py +0 -0
  58. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/helpers.py +0 -0
  59. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/test_button.py +0 -0
  60. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/test_management.py +0 -0
  61. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/test_report.py +0 -0
  62. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/testproject/__init__.py +0 -0
  63. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/testproject/hostapp/__init__.py +0 -0
  64. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/testproject/hostapp/apps.py +0 -0
  65. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/testproject/hostapp/models.py +0 -0
  66. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/testproject/settings.py +0 -0
  67. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/testproject/templates/alt_base.html +0 -0
  68. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/testproject/templates/host_base.html +0 -0
  69. {django_snapnote-0.1.1 → django_snapnote-0.2.0}/tests/testproject/urls.py +0 -0
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - Jira notifier (`snapnote.notifiers.jira_issue`) with image attachments and a system check.
6
+ - CI: Django 6.1 added to the matrix.
7
+
3
8
  ## 0.1.1
4
9
 
5
10
  - First release on PyPI (0.1.0 was a TestPyPI dry run).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: django-snapnote
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Report problems from any page of a Django site: screenshot, annotations and a ticket list.
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -10,6 +10,7 @@ Classifier: Framework :: Django :: 4.2
10
10
  Classifier: Framework :: Django :: 5.0
11
11
  Classifier: Framework :: Django :: 5.1
12
12
  Classifier: Framework :: Django :: 5.2
13
+ Classifier: Framework :: Django :: 6.1
13
14
  Classifier: License :: OSI Approved :: MIT License
14
15
  Classifier: Programming Language :: Python :: 3
15
16
  Requires-Python: >=3.10
@@ -86,6 +87,27 @@ def slack(ticket, url):
86
87
  SNAPNOTE_NOTIFIERS = ["snapnote.notifiers.email", "myproject.notifiers.slack"]
87
88
  ```
88
89
 
90
+ ### Jira notifier
91
+
92
+ Built in, opt-in and dependency-free (stdlib only). It creates a Jira Cloud issue per ticket, with the
93
+ page URL, a link to the Snapnote ticket and, optionally, the screenshot and annotations attached:
94
+
95
+ ```python
96
+ SNAPNOTE_NOTIFIERS = ["snapnote.notifiers.email", "snapnote.notifiers.jira_issue"]
97
+ SNAPNOTE_JIRA_URL = "https://yourcompany.atlassian.net"
98
+ SNAPNOTE_JIRA_EMAIL = "bot@yourcompany.com"
99
+ SNAPNOTE_JIRA_API_TOKEN = os.environ["JIRA_API_TOKEN"] # https://id.atlassian.com/manage-profile/security/api-tokens
100
+ SNAPNOTE_JIRA_PROJECT = "APP" # project key
101
+ # optional: SNAPNOTE_JIRA_ISSUE_TYPE = "Bug", SNAPNOTE_JIRA_LABELS = ["snapnote"],
102
+ # SNAPNOTE_JIRA_ATTACH_IMAGES = True, SNAPNOTE_JIRA_TIMEOUT = 10
103
+ ```
104
+
105
+ `manage.py check` warns (`snapnote.W002`) if a required setting is missing. Use a dedicated
106
+ Jira account with access only to that project. Notifiers run synchronously after commit with the
107
+ timeout above; for heavy use, wrap it in your own task queue. Screenshots may contain sensitive
108
+ data: they are attached to the issue, so keep `SNAPNOTE_JIRA_ATTACH_IMAGES = False` if the Jira
109
+ project is broader than who may see them.
110
+
89
111
  ## Security and deployment notes
90
112
 
91
113
  - **Screenshots can contain sensitive data.** Serve `MEDIA_ROOT` only to authenticated staff (or use a
@@ -67,6 +67,27 @@ def slack(ticket, url):
67
67
  SNAPNOTE_NOTIFIERS = ["snapnote.notifiers.email", "myproject.notifiers.slack"]
68
68
  ```
69
69
 
70
+ ### Jira notifier
71
+
72
+ Built in, opt-in and dependency-free (stdlib only). It creates a Jira Cloud issue per ticket, with the
73
+ page URL, a link to the Snapnote ticket and, optionally, the screenshot and annotations attached:
74
+
75
+ ```python
76
+ SNAPNOTE_NOTIFIERS = ["snapnote.notifiers.email", "snapnote.notifiers.jira_issue"]
77
+ SNAPNOTE_JIRA_URL = "https://yourcompany.atlassian.net"
78
+ SNAPNOTE_JIRA_EMAIL = "bot@yourcompany.com"
79
+ SNAPNOTE_JIRA_API_TOKEN = os.environ["JIRA_API_TOKEN"] # https://id.atlassian.com/manage-profile/security/api-tokens
80
+ SNAPNOTE_JIRA_PROJECT = "APP" # project key
81
+ # optional: SNAPNOTE_JIRA_ISSUE_TYPE = "Bug", SNAPNOTE_JIRA_LABELS = ["snapnote"],
82
+ # SNAPNOTE_JIRA_ATTACH_IMAGES = True, SNAPNOTE_JIRA_TIMEOUT = 10
83
+ ```
84
+
85
+ `manage.py check` warns (`snapnote.W002`) if a required setting is missing. Use a dedicated
86
+ Jira account with access only to that project. Notifiers run synchronously after commit with the
87
+ timeout above; for heavy use, wrap it in your own task queue. Screenshots may contain sensitive
88
+ data: they are attached to the issue, so keep `SNAPNOTE_JIRA_ATTACH_IMAGES = False` if the Jira
89
+ project is broader than who may see them.
90
+
70
91
  ## Security and deployment notes
71
92
 
72
93
  - **Screenshots can contain sensitive data.** Serve `MEDIA_ROOT` only to authenticated staff (or use a
@@ -17,6 +17,7 @@ classifiers = [
17
17
  "Framework :: Django :: 5.0",
18
18
  "Framework :: Django :: 5.1",
19
19
  "Framework :: Django :: 5.2",
20
+ "Framework :: Django :: 6.1",
20
21
  "License :: OSI Approved :: MIT License",
21
22
  "Programming Language :: Python :: 3",
22
23
  ]
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"
@@ -19,4 +19,17 @@ def check_settings(app_configs, **kwargs):
19
19
  id="snapnote.W001",
20
20
  )
21
21
  )
22
+ notifiers = conf.get("NOTIFIERS")
23
+ if "snapnote.notifiers.jira_issue" in notifiers:
24
+ from .notifiers import JIRA_REQUIRED
25
+
26
+ missing = [f"SNAPNOTE_{name}" for name in JIRA_REQUIRED if not conf.get(name)]
27
+ if missing:
28
+ messages.append(
29
+ Warning(
30
+ "The Jira notifier is enabled but misconfigured.",
31
+ hint="Missing settings: " + ", ".join(missing),
32
+ id="snapnote.W002",
33
+ )
34
+ )
22
35
  return messages
@@ -13,6 +13,15 @@ DEFAULTS = {
13
13
  "UPLOAD_TO": "snapnote/",
14
14
  "THROTTLE": "10/hour",
15
15
  "AUTO_INJECT": False,
16
+ # Jira notifier (snapnote.notifiers.jira_issue). URL, EMAIL, API_TOKEN and PROJECT are required.
17
+ "JIRA_URL": "",
18
+ "JIRA_EMAIL": "",
19
+ "JIRA_API_TOKEN": "",
20
+ "JIRA_PROJECT": "",
21
+ "JIRA_ISSUE_TYPE": "Bug",
22
+ "JIRA_LABELS": ["snapnote"],
23
+ "JIRA_ATTACH_IMAGES": True,
24
+ "JIRA_TIMEOUT": 10,
16
25
  }
17
26
 
18
27
 
@@ -0,0 +1,147 @@
1
+ import base64
2
+ import json
3
+ import logging
4
+ import urllib.request
5
+ import uuid
6
+
7
+ from django.conf import settings
8
+ from django.core.mail import send_mail
9
+ from django.utils.translation import gettext as _
10
+
11
+ from . import conf
12
+
13
+ logger = logging.getLogger("snapnote")
14
+
15
+
16
+ def email(ticket, absolute_url):
17
+ recipients = list(conf.get("NOTIFY_EMAILS"))
18
+ if not recipients:
19
+ return
20
+ body = "\n".join(
21
+ part
22
+ for part in (
23
+ ticket.description,
24
+ f"{_('Page')}: {ticket.page_url}",
25
+ f"{_('Ticket')}: {absolute_url}" if absolute_url else "",
26
+ )
27
+ if part
28
+ )
29
+ send_mail(
30
+ subject=f"[Snapnote] {ticket.title}",
31
+ message=body,
32
+ from_email=getattr(settings, "DEFAULT_FROM_EMAIL", None),
33
+ recipient_list=recipients,
34
+ )
35
+
36
+
37
+ JIRA_REQUIRED = ("JIRA_URL", "JIRA_EMAIL", "JIRA_API_TOKEN", "JIRA_PROJECT")
38
+
39
+
40
+ def _jira_request(path, data, content_type, extra_headers=None):
41
+ token = f"{conf.get('JIRA_EMAIL')}:{conf.get('JIRA_API_TOKEN')}".encode()
42
+ request = urllib.request.Request(
43
+ f"{conf.get('JIRA_URL').rstrip('/')}{path}",
44
+ data=data,
45
+ method="POST",
46
+ headers={
47
+ "Authorization": "Basic " + base64.b64encode(token).decode(),
48
+ "Content-Type": content_type,
49
+ "Accept": "application/json",
50
+ **(extra_headers or {}),
51
+ },
52
+ )
53
+ with urllib.request.urlopen(request, timeout=conf.get("JIRA_TIMEOUT")) as response: # noqa: S310
54
+ return json.loads(response.read() or b"{}")
55
+
56
+
57
+ def _adf_paragraph(*parts):
58
+ """A paragraph in Atlassian Document Format; parts are text or (text, url) links."""
59
+ content = []
60
+ for part in parts:
61
+ if isinstance(part, tuple):
62
+ text, url = part
63
+ content.append(
64
+ {"type": "text", "text": text, "marks": [{"type": "link", "attrs": {"href": url}}]}
65
+ )
66
+ else:
67
+ content.append({"type": "text", "text": part})
68
+ return {"type": "paragraph", "content": content}
69
+
70
+
71
+ def _multipart(field, filename, content):
72
+ boundary = uuid.uuid4().hex
73
+ body = (
74
+ (
75
+ f"--{boundary}\r\n"
76
+ f'Content-Disposition: form-data; name="{field}"; filename="{filename}"\r\n'
77
+ "Content-Type: application/octet-stream\r\n\r\n"
78
+ ).encode()
79
+ + content
80
+ + f"\r\n--{boundary}--\r\n".encode()
81
+ )
82
+ return body, f"multipart/form-data; boundary={boundary}"
83
+
84
+
85
+ def jira_issue(ticket, absolute_url):
86
+ """Creates a Jira Cloud issue for the ticket and attaches its images.
87
+
88
+ The ticket text is untrusted user input; it is only ever sent as plain text.
89
+ """
90
+ blocks = []
91
+ if ticket.description:
92
+ blocks.append(_adf_paragraph(ticket.description))
93
+ page = ticket.safe_page_url
94
+ blocks.append(
95
+ _adf_paragraph("Page: ", (page, page))
96
+ if page
97
+ else _adf_paragraph(f"Page: {ticket.page_url}")
98
+ )
99
+ if absolute_url:
100
+ blocks.append(_adf_paragraph("Snapnote ticket: ", (absolute_url, absolute_url)))
101
+ if ticket.reported_by_id:
102
+ blocks.append(_adf_paragraph(f"Reported by: {ticket.reported_by}"))
103
+ payload = {
104
+ "fields": {
105
+ "project": {"key": conf.get("JIRA_PROJECT")},
106
+ "issuetype": {"name": conf.get("JIRA_ISSUE_TYPE")},
107
+ "summary": ticket.title[:255],
108
+ "labels": list(conf.get("JIRA_LABELS")),
109
+ "description": {"type": "doc", "version": 1, "content": blocks},
110
+ }
111
+ }
112
+ issue = _jira_request("/rest/api/3/issue", json.dumps(payload).encode(), "application/json")
113
+ key = issue["key"]
114
+ if conf.get("JIRA_ATTACH_IMAGES"):
115
+ for name in ("screenshot", "annotations"):
116
+ image = getattr(ticket, name)
117
+ if not image:
118
+ continue
119
+ try:
120
+ with image.open("rb") as handle:
121
+ body, content_type = _multipart(
122
+ "file", f"{name}-{ticket.pk}.png", handle.read()
123
+ )
124
+ _jira_request(
125
+ f"/rest/api/3/issue/{key}/attachments",
126
+ body,
127
+ content_type,
128
+ {"X-Atlassian-Token": "no-check"},
129
+ )
130
+ except Exception:
131
+ # The issue exists already; a missing image must not fail the notifier.
132
+ logger.exception(
133
+ "Could not attach %s of ticket %s to Jira issue %s", name, ticket.pk, key
134
+ )
135
+ return key
136
+
137
+
138
+ def run_notifiers(sender, ticket, request_url="", **kwargs):
139
+ """Runs every configured notifier; a failing one never breaks the others."""
140
+ from django.utils.module_loading import import_string
141
+
142
+ for path in conf.get("NOTIFIERS"):
143
+ try:
144
+ notifier = import_string(path) if isinstance(path, str) else path
145
+ notifier(ticket, request_url)
146
+ except Exception:
147
+ logger.exception("Snapnote notifier %r failed", path)
@@ -0,0 +1,98 @@
1
+ import json
2
+ from unittest import mock
3
+
4
+ import pytest
5
+ from django.core.checks import run_checks
6
+
7
+ from snapnote import notifiers
8
+
9
+
10
+ @pytest.fixture
11
+ def jira(settings):
12
+ settings.SNAPNOTE_JIRA_URL = "https://acme.atlassian.net/"
13
+ settings.SNAPNOTE_JIRA_EMAIL = "bot@acme.com"
14
+ settings.SNAPNOTE_JIRA_API_TOKEN = "secret"
15
+ settings.SNAPNOTE_JIRA_PROJECT = "APP"
16
+
17
+
18
+ class FakeResponse:
19
+ def __init__(self, body):
20
+ self.body = body
21
+
22
+ def __enter__(self):
23
+ return self
24
+
25
+ def __exit__(self, *args):
26
+ return False
27
+
28
+ def read(self):
29
+ return json.dumps(self.body).encode()
30
+
31
+
32
+ def fake_urlopen(calls, fail_attachments=False):
33
+ def urlopen(request, timeout=None):
34
+ calls.append(request)
35
+ if "attachments" in request.full_url and fail_attachments:
36
+ raise OSError("boom")
37
+ return FakeResponse({"key": "APP-7"})
38
+
39
+ return urlopen
40
+
41
+
42
+ def test_creates_issue_and_attaches_images(jira, make_ticket, png):
43
+ ticket = make_ticket(
44
+ title="Broken", description="It fails", screenshot=png(), annotations=png("a.png")
45
+ )
46
+ calls = []
47
+ with mock.patch("urllib.request.urlopen", fake_urlopen(calls)):
48
+ key = notifiers.jira_issue(ticket, "http://testserver/snapnote/1/")
49
+ assert key == "APP-7"
50
+ create, shot, ann = calls
51
+ assert create.full_url == "https://acme.atlassian.net/rest/api/3/issue"
52
+ assert create.get_header("Authorization").startswith("Basic ")
53
+ fields = json.loads(create.data)["fields"]
54
+ assert fields["project"] == {"key": "APP"} and fields["issuetype"] == {"name": "Bug"}
55
+ assert fields["summary"] == "Broken" and fields["labels"] == ["snapnote"]
56
+ text = json.dumps(fields["description"])
57
+ assert "It fails" in text and "http://testserver/snapnote/1/" in text
58
+ assert shot.full_url.endswith("/issue/APP-7/attachments")
59
+ assert shot.get_header("X-atlassian-token") == "no-check"
60
+ assert ann.full_url.endswith("/issue/APP-7/attachments")
61
+
62
+
63
+ def test_no_attachments_when_disabled_or_absent(jira, settings, make_ticket, png):
64
+ settings.SNAPNOTE_JIRA_ATTACH_IMAGES = False
65
+ calls = []
66
+ with mock.patch("urllib.request.urlopen", fake_urlopen(calls)):
67
+ notifiers.jira_issue(make_ticket(screenshot=png()), "")
68
+ assert len(calls) == 1
69
+
70
+
71
+ def test_attachment_failure_does_not_fail_notifier(jira, make_ticket, png):
72
+ calls = []
73
+ with mock.patch("urllib.request.urlopen", fake_urlopen(calls, fail_attachments=True)):
74
+ assert notifiers.jira_issue(make_ticket(screenshot=png()), "") == "APP-7"
75
+
76
+
77
+ def test_javascript_page_url_is_not_a_link(jira, make_ticket):
78
+ calls = []
79
+ with mock.patch("urllib.request.urlopen", fake_urlopen(calls)):
80
+ notifiers.jira_issue(make_ticket(page_url="javascript:alert(1)"), "")
81
+ assert '"link"' not in calls[0].data.decode()
82
+
83
+
84
+ def test_jira_failure_is_contained_by_runner(jira, settings, make_ticket):
85
+ settings.SNAPNOTE_NOTIFIERS = ["snapnote.notifiers.jira_issue"]
86
+ with mock.patch("urllib.request.urlopen", side_effect=OSError("down")):
87
+ notifiers.run_notifiers(None, make_ticket(), "") # must not raise
88
+
89
+
90
+ def test_check_warns_when_misconfigured(settings):
91
+ settings.SNAPNOTE_NOTIFIERS = ["snapnote.notifiers.jira_issue"]
92
+ warnings = [m for m in run_checks() if m.id == "snapnote.W002"]
93
+ assert warnings and "SNAPNOTE_JIRA_URL" in warnings[0].hint
94
+
95
+
96
+ def test_check_silent_when_configured(jira, settings):
97
+ settings.SNAPNOTE_NOTIFIERS = ["snapnote.notifiers.jira_issue"]
98
+ assert not [m for m in run_checks() if m.id == "snapnote.W002"]
@@ -1 +0,0 @@
1
- __version__ = "0.1.1"
@@ -1,42 +0,0 @@
1
- import logging
2
-
3
- from django.conf import settings
4
- from django.core.mail import send_mail
5
- from django.utils.translation import gettext as _
6
-
7
- from . import conf
8
-
9
- logger = logging.getLogger("snapnote")
10
-
11
-
12
- def email(ticket, absolute_url):
13
- recipients = list(conf.get("NOTIFY_EMAILS"))
14
- if not recipients:
15
- return
16
- body = "\n".join(
17
- part
18
- for part in (
19
- ticket.description,
20
- f"{_('Page')}: {ticket.page_url}",
21
- f"{_('Ticket')}: {absolute_url}" if absolute_url else "",
22
- )
23
- if part
24
- )
25
- send_mail(
26
- subject=f"[Snapnote] {ticket.title}",
27
- message=body,
28
- from_email=getattr(settings, "DEFAULT_FROM_EMAIL", None),
29
- recipient_list=recipients,
30
- )
31
-
32
-
33
- def run_notifiers(sender, ticket, request_url="", **kwargs):
34
- """Runs every configured notifier; a failing one never breaks the others."""
35
- from django.utils.module_loading import import_string
36
-
37
- for path in conf.get("NOTIFIERS"):
38
- try:
39
- notifier = import_string(path) if isinstance(path, str) else path
40
- notifier(ticket, request_url)
41
- except Exception:
42
- logger.exception("Snapnote notifier %r failed", path)
File without changes