NEMO-osticket 1.6.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 (29) hide show
  1. nemo_osticket-1.6.0/LICENSE +21 -0
  2. nemo_osticket-1.6.0/NEMO_osticket/__init__.py +0 -0
  3. nemo_osticket-1.6.0/NEMO_osticket/admin.py +3 -0
  4. nemo_osticket-1.6.0/NEMO_osticket/apps.py +22 -0
  5. nemo_osticket-1.6.0/NEMO_osticket/customizations.py +115 -0
  6. nemo_osticket-1.6.0/NEMO_osticket/exceptions.py +2 -0
  7. nemo_osticket-1.6.0/NEMO_osticket/forms.py +84 -0
  8. nemo_osticket-1.6.0/NEMO_osticket/models.py +1200 -0
  9. nemo_osticket-1.6.0/NEMO_osticket/routers.py +22 -0
  10. nemo_osticket-1.6.0/NEMO_osticket/templates/NEMO_osticket/osticket_details.html +73 -0
  11. nemo_osticket-1.6.0/NEMO_osticket/templates/NEMO_osticket/osticket_past_tasks_and_comments.html +104 -0
  12. nemo_osticket-1.6.0/NEMO_osticket/templates/NEMO_osticket/osticket_tab.html +21 -0
  13. nemo_osticket-1.6.0/NEMO_osticket/templates/NEMO_osticket/osticket_tab_content.html +53 -0
  14. nemo_osticket-1.6.0/NEMO_osticket/templates/customizations/customizations_osticket.html +241 -0
  15. nemo_osticket-1.6.0/NEMO_osticket/tests/__init__.py +0 -0
  16. nemo_osticket-1.6.0/NEMO_osticket/tests/test_osticket.py +31 -0
  17. nemo_osticket-1.6.0/NEMO_osticket/tests/test_settings.py +90 -0
  18. nemo_osticket-1.6.0/NEMO_osticket/urls.py +19 -0
  19. nemo_osticket-1.6.0/NEMO_osticket/views/__init__.py +0 -0
  20. nemo_osticket-1.6.0/NEMO_osticket/views/osticket.py +369 -0
  21. nemo_osticket-1.6.0/NEMO_osticket.egg-info/PKG-INFO +124 -0
  22. nemo_osticket-1.6.0/NEMO_osticket.egg-info/SOURCES.txt +27 -0
  23. nemo_osticket-1.6.0/NEMO_osticket.egg-info/dependency_links.txt +1 -0
  24. nemo_osticket-1.6.0/NEMO_osticket.egg-info/requires.txt +14 -0
  25. nemo_osticket-1.6.0/NEMO_osticket.egg-info/top_level.txt +1 -0
  26. nemo_osticket-1.6.0/PKG-INFO +124 -0
  27. nemo_osticket-1.6.0/README.md +68 -0
  28. nemo_osticket-1.6.0/pyproject.toml +56 -0
  29. nemo_osticket-1.6.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Atlantis Labs LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
File without changes
@@ -0,0 +1,3 @@
1
+ from django.contrib import admin
2
+
3
+ # Register your admin models here.
@@ -0,0 +1,22 @@
1
+ from django.apps import AppConfig
2
+ from django.conf import settings
3
+
4
+ # Add our custom database router to redirect to the proper database
5
+ if (
6
+ hasattr(settings, "DATABASE_ROUTERS")
7
+ and "NEMO_osticket.routers.OsTicketDatabaseRouter" not in settings.DATABASE_ROUTERS
8
+ ):
9
+ settings.DATABASE_ROUTERS.append("NEMO_osticket.routers.OsTicketDatabaseRouter")
10
+ else:
11
+ setattr(settings, "DATABASE_ROUTERS", ["NEMO_osticket.routers.OsTicketDatabaseRouter"])
12
+
13
+
14
+ class OsTicketConfig(AppConfig):
15
+ name = "NEMO_osticket"
16
+ verbose_name = "osTicket"
17
+ default_auto_field = "django.db.models.AutoField"
18
+
19
+ def ready(self):
20
+ """
21
+ This code will be run when Django starts.
22
+ """
@@ -0,0 +1,115 @@
1
+ import re
2
+ from logging import getLogger
3
+ from typing import Dict, Optional
4
+
5
+ from NEMO.decorators import customization
6
+ from NEMO.exceptions import InvalidCustomizationException
7
+ from NEMO.models import Reservation, Tool, User
8
+ from NEMO.views.customization import CustomizationBase
9
+ from django.core.exceptions import ValidationError
10
+ from django.core.validators import validate_comma_separated_integer_list
11
+ from django.template import Context, Template
12
+
13
+ from NEMO_osticket.models import OstFormField, OstHelpTopic, OstListItems, get_osticket_form_fields
14
+
15
+ osticket_customization_logger = getLogger(__name__)
16
+
17
+
18
+ @customization(key="osticket", title="OsTicket")
19
+ class OsTicketCustomization(CustomizationBase):
20
+ variables = {
21
+ "osticket_tool_control_replace_problem_tab": "",
22
+ "osticket_tool_control_tab_name": "Help desk",
23
+ "osticket_create_ticket_include_reservations": "",
24
+ "osticket_create_ticket_help_topic_label": "Help Topic",
25
+ "osticket_create_ticket_help_topic_exclude_list": "",
26
+ "osticket_create_ticket_issue_summary_label": "Issue Summary",
27
+ "osticket_create_ticket_message_label": "Description",
28
+ "osticket_create_ticket_subject_template": "[{{ tool.name }}] {{ subject }}",
29
+ "osticket_create_ticket_message_template": "Tool name: {{ tool.name }}\nCreated by: {{ user.get_name }}\n{% if reservation %}Reservation: {{ reservation.start|date:'SHORT_DATETIME_FORMAT' }} to {{ reservation.end|date:'SHORT_DATETIME_FORMAT' }}\n{% endif %}Help topic: {{ topic }}\n\n{{ message }}",
30
+ "osticket_tool_matching_field_id": "",
31
+ "osticket_tool_matching_nemo_property_template": "{{ tool.id }}",
32
+ "osticket_tool_matching_property_extract_re": "",
33
+ "osticket_view_ticket_display_description": "",
34
+ }
35
+
36
+ def context(self) -> Dict:
37
+ context_dict = super().context()
38
+ context_dict["ticket_form_fields"] = get_osticket_form_fields(exclude_matching=False)
39
+ context_dict["help_topics"] = OstHelpTopic.objects.all()
40
+ context_dict["excluded_help_topic_ids"] = self.get_list_int("osticket_create_ticket_help_topic_exclude_list")
41
+ return context_dict
42
+
43
+ def validate(self, name, value):
44
+ if name == "osticket_create_ticket_help_topic_exclude_list" and value:
45
+ validate_comma_separated_integer_list(value)
46
+ if name == "osticket_tool_matching_nemo_property_template" and value:
47
+ try:
48
+ Template(value).render(Context({"tool": Tool.objects.first()}))
49
+ except Exception as e:
50
+ raise ValidationError(str(e))
51
+ if value and name in ["osticket_create_ticket_subject_template", "osticket_create_ticket_message_template"]:
52
+ try:
53
+ Template(value).render(
54
+ Context(
55
+ {
56
+ "subject": "Subject",
57
+ "message": "Message",
58
+ "tool": Tool.objects.first(),
59
+ "topic": "Topic",
60
+ "user": User.objects.first(),
61
+ "reservation": Reservation.objects.first(),
62
+ }
63
+ )
64
+ )
65
+ except Exception as e:
66
+ raise ValidationError(str(e))
67
+
68
+ def save(self, request, element=None) -> Dict[str, Dict[str, str]]:
69
+ errors = super().save(request, element)
70
+ excluded_topics = ",".join(request.POST.getlist("osticket_create_ticket_help_topic_exclude_list", []))
71
+ try:
72
+ self.validate("osticket_create_ticket_help_topic_exclude_list", excluded_topics)
73
+ type(self).set("osticket_create_ticket_help_topic_exclude_list", excluded_topics)
74
+ except (ValidationError, InvalidCustomizationException) as e:
75
+ errors["osticket_create_ticket_help_topic_exclude_list"] = {
76
+ "error": str(e.message or e.msg),
77
+ "value": excluded_topics,
78
+ }
79
+ return errors
80
+
81
+ @classmethod
82
+ def get_osticket_tool_matching_field(cls) -> Optional[OstFormField]:
83
+ return OstFormField.objects.filter(id=cls.get_int("osticket_tool_matching_field_id") or None).first()
84
+
85
+ @classmethod
86
+ def get_osticket_tool_matching_value(cls, tool: Tool) -> Optional[OstListItems]:
87
+ field = cls.get_osticket_tool_matching_field()
88
+ osticket_re_matching = cls.get("osticket_tool_matching_property_extract_re")
89
+ if field:
90
+ if field.is_list_type():
91
+ list_options = field.get_list_options()
92
+ if list_options:
93
+ for item in list_options:
94
+ if cls.is_tool_match(tool, item.value, osticket_re_matching):
95
+ return item
96
+ return None
97
+
98
+ @classmethod
99
+ def get_tool_matching_nemo_property(cls, tool: Tool) -> str:
100
+ return Template(cls.get("osticket_tool_matching_nemo_property_template")).render(Context({"tool": tool}))
101
+
102
+ @classmethod
103
+ def is_tool_match(cls, tool: Tool, osticket_field_value: str, osticket_re_matching=None):
104
+ try:
105
+ nemo_property = cls.get_tool_matching_nemo_property(tool)
106
+ osticket_property = None
107
+ if osticket_re_matching:
108
+ match = re.match(rf"{osticket_re_matching}", osticket_field_value)
109
+ if match:
110
+ osticket_property = match.group(1)
111
+ if nemo_property and osticket_property:
112
+ return nemo_property == osticket_property
113
+ except Exception as e:
114
+ osticket_customization_logger.error(e)
115
+ return False
@@ -0,0 +1,2 @@
1
+ class OsTicketException(Exception):
2
+ pass
@@ -0,0 +1,84 @@
1
+ import json
2
+
3
+ from NEMO.models import Reservation
4
+ from django import forms
5
+ from django.conf import settings
6
+ from django.core.exceptions import ValidationError
7
+
8
+ from NEMO_osticket.customizations import OsTicketCustomization
9
+ from NEMO_osticket.models import OstHelpTopic, get_osticket_form_fields
10
+
11
+
12
+ # This custom model choice field doesn't use the field queryset to check validity
13
+ class CustomModelChoiceField(forms.ModelChoiceField):
14
+ def to_python(self, value):
15
+ if value in self.empty_values:
16
+ return None
17
+ try:
18
+ key = self.to_field_name or "pk"
19
+ if isinstance(value, self.queryset.model):
20
+ value = getattr(value, key)
21
+ value = self.queryset.model.objects.all().get(**{key: value})
22
+ except (ValueError, TypeError, self.queryset.model.DoesNotExist):
23
+ raise ValidationError(
24
+ self.error_messages["invalid_choice"],
25
+ code="invalid_choice",
26
+ params={"value": value},
27
+ )
28
+ return value
29
+
30
+
31
+ class OsTicketForm(forms.Form):
32
+ message = forms.CharField(label="Description", widget=forms.Textarea())
33
+ reservation = CustomModelChoiceField(required=False, label="Reservation", queryset=Reservation.objects.none())
34
+
35
+ def __init__(self, *args, **kwargs):
36
+ super().__init__(*args, **kwargs)
37
+ field_ordering = ["reservation", "topicId"]
38
+ create_ticket_include_reservations = OsTicketCustomization.get_bool(
39
+ "osticket_create_ticket_include_reservations"
40
+ )
41
+ if not create_ticket_include_reservations:
42
+ del self.fields["reservation"]
43
+ topic_choices = []
44
+ if settings.DATABASES.get("osticket", False):
45
+ topic_choices = [
46
+ (item.topic_id, item.topic)
47
+ for item in OstHelpTopic.objects.exclude(
48
+ topic_id__in=OsTicketCustomization.get_list_int("osticket_create_ticket_help_topic_exclude_list")
49
+ )
50
+ ]
51
+ self.fields["topicId"] = forms.ChoiceField(choices=topic_choices)
52
+ self.fields["topicId"].label = OsTicketCustomization.get("osticket_create_ticket_help_topic_label")
53
+ self.fields["topicId"].required = True
54
+ for ostField in get_osticket_form_fields():
55
+ if ostField.label not in field_ordering:
56
+ field_ordering.append(ostField.name)
57
+ required = ostField.flags not in [13057, 12289, 769]
58
+ max_length = None
59
+ if ostField.configuration:
60
+ config_json = json.loads(ostField.configuration)
61
+ max_length = config_json.get("length", None) or None
62
+ if ostField.type == "text":
63
+ self.fields[ostField.name] = forms.CharField(max_length=max_length)
64
+ self.fields[ostField.name].label = ostField.label
65
+ self.fields[ostField.name].required = required
66
+ elif ostField.type == "memo":
67
+ self.fields[ostField.name] = forms.CharField(max_length=max_length, widget=forms.Textarea())
68
+ self.fields[ostField.name].label = ostField.label
69
+ self.fields[ostField.name].required = required
70
+ elif ostField.is_list_type():
71
+ choices = [(item.id, item.value) for item in ostField.get_list_options()]
72
+ self.fields[ostField.name] = forms.ChoiceField(choices=choices)
73
+ self.fields[ostField.name].label = ostField.label
74
+ self.fields[ostField.name].required = required
75
+ if "subject" in self.fields:
76
+ self.fields["subject"].label = OsTicketCustomization.get("osticket_create_ticket_issue_summary_label")
77
+ if "message" in self.fields:
78
+ self.fields["message"].label = OsTicketCustomization.get("osticket_create_ticket_message_label")
79
+ if "subject" in field_ordering:
80
+ field_ordering.remove("subject")
81
+ if "message" in field_ordering:
82
+ field_ordering.remove("message")
83
+ field_ordering.extend(["subject", "message"])
84
+ self.order_fields(field_ordering)