feat(core): Add slash command link
for linking items to tickets
ref: #296 #308
This commit is contained in:
@ -2,11 +2,13 @@ import re
|
||||
|
||||
from .duration import Duration
|
||||
from .related_ticket import CommandRelatedTicket
|
||||
from .linked_model import CommandLinkedModel
|
||||
|
||||
|
||||
class SlashCommands(
|
||||
Duration,
|
||||
CommandRelatedTicket
|
||||
CommandRelatedTicket,
|
||||
CommandLinkedModel,
|
||||
):
|
||||
"""Slash Commands Base Class
|
||||
|
||||
@ -38,6 +40,8 @@ class SlashCommands(
|
||||
|
||||
markdown = re.sub(self.time_spent, self.command_duration, markdown)
|
||||
|
||||
markdown = re.sub(self.linked_item, self.command_linked_model, markdown)
|
||||
|
||||
markdown = re.sub(self.related_ticket, self.command_related_ticket, markdown)
|
||||
|
||||
return markdown
|
||||
|
148
app/core/lib/slash_commands/linked_model.py
Normal file
148
app/core/lib/slash_commands/linked_model.py
Normal file
@ -0,0 +1,148 @@
|
||||
import re
|
||||
|
||||
|
||||
class CommandLinkedModel:
|
||||
# This summary is used for the user documentation
|
||||
"""Link an item to the current ticket. Supports all ticket
|
||||
relations: blocked by, blocks and related.
|
||||
The command keyword is `link` along with the model reference, i.e. `$<type>-<number>`.
|
||||
|
||||
Valid commands are as follows:
|
||||
|
||||
- /link $device-1
|
||||
|
||||
- /link $cluster-55
|
||||
|
||||
Available model types for linking are as follows:
|
||||
|
||||
- cluster
|
||||
|
||||
- config_group
|
||||
|
||||
- device
|
||||
|
||||
- operating_system
|
||||
|
||||
- service
|
||||
|
||||
- software
|
||||
|
||||
For this command to process the following conditions must be met:
|
||||
|
||||
- There is either a `<new line>` (`\\n`) or a `<space>` char immediatly before the slash `/`
|
||||
|
||||
- There is a `<space>` char after the command keyword, i.e. `/link<space>$device-101`
|
||||
"""
|
||||
|
||||
|
||||
linked_item: str = r'[\s|\n]\/(?P<command>[link]+)\s\$(?P<type>[a-z_]+)-(?P<id>\d+)[\s|\n]?'
|
||||
|
||||
|
||||
def command_linked_model(self, match) -> str:
|
||||
"""/link processor
|
||||
|
||||
Slash command usage within a ticket description will add an action comment with the
|
||||
time spent. For a ticket comment, it's duration field is set to the duration valuee calculated.
|
||||
|
||||
Args:
|
||||
match (re.Match): Named group matches
|
||||
|
||||
Returns:
|
||||
str: The matched string if the duration calculation is `0`
|
||||
None: On successfully processing the command
|
||||
"""
|
||||
|
||||
a = 'a'
|
||||
|
||||
command = match.group('command')
|
||||
|
||||
model_type:int = str(match.group('type'))
|
||||
model_id:int = int(match.group('id'))
|
||||
|
||||
|
||||
try:
|
||||
|
||||
from core.models.ticket.ticket_linked_items import TicketLinkedItem
|
||||
|
||||
if model_type == 'cluster':
|
||||
|
||||
from itim.models.clusters import Cluster
|
||||
|
||||
model = Cluster
|
||||
|
||||
item_type = TicketLinkedItem.Modules.CLUSTER
|
||||
|
||||
elif model_type == 'config_group':
|
||||
|
||||
from config_management.models.groups import ConfigGroups
|
||||
|
||||
model = ConfigGroups
|
||||
|
||||
item_type = TicketLinkedItem.Modules.CONFIG_GROUP
|
||||
|
||||
elif model_type == 'device':
|
||||
|
||||
from itam.models.device import Device
|
||||
|
||||
model = Device
|
||||
|
||||
item_type = TicketLinkedItem.Modules.DEVICE
|
||||
|
||||
elif model_type == 'operating_system':
|
||||
|
||||
from itam.models.operating_system import OperatingSystem
|
||||
|
||||
model = OperatingSystem
|
||||
|
||||
item_type = TicketLinkedItem.Modules.OPERATING_SYSTEM
|
||||
|
||||
elif model_type == 'service':
|
||||
|
||||
from itim.models.services import Service
|
||||
|
||||
model = Service
|
||||
|
||||
item_type = TicketLinkedItem.Modules.SERVICE
|
||||
|
||||
elif model_type == 'software':
|
||||
|
||||
from itam.models.software import Software
|
||||
|
||||
model = Software
|
||||
|
||||
item_type = TicketLinkedItem.Modules.SOFTWARE
|
||||
|
||||
else:
|
||||
|
||||
return str(match.string[match.start():match.end()])
|
||||
|
||||
|
||||
if str(self._meta.verbose_name).lower() == 'ticket':
|
||||
|
||||
ticket = self
|
||||
|
||||
elif str(self._meta.verbose_name).lower() == 'comment':
|
||||
|
||||
ticket = self.ticket
|
||||
|
||||
|
||||
if model:
|
||||
|
||||
item = model.objects.get(
|
||||
pk = model_id
|
||||
)
|
||||
|
||||
TicketLinkedItem.objects.create(
|
||||
organization = self.organization,
|
||||
ticket = ticket,
|
||||
item_type = item_type,
|
||||
item = item.id
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
|
||||
return str(match.string[match.start():match.end()])
|
||||
|
||||
return None
|
0
app/core/models/ticket/__init__.py
Normal file
0
app/core/models/ticket/__init__.py
Normal file
@ -49,7 +49,9 @@ All models must meet the following requirements:
|
||||
|
||||
This section details the additional items that may need to be done when adding a new model:
|
||||
|
||||
- If the model is a primary model, add to model reference rendering in `app/core/lib/markdown_plugins/model_reference.py` function `tag_html`
|
||||
- If the model is a primary model, add it to model reference rendering in `app/core/lib/markdown_plugins/model_reference.py` function `tag_html`
|
||||
|
||||
- If the model is a primary model, add it to the model link slash command in `app/core/lib/slash_commands/linked_model.py` function `command_linked_model`
|
||||
|
||||
|
||||
## History
|
||||
|
@ -13,6 +13,12 @@ The ticketing system within Centurion ERP is common to all ticket types. The dif
|
||||
|
||||
- Commenting
|
||||
|
||||
- Linked Items to ticket
|
||||
|
||||
- Milestone
|
||||
|
||||
- Project
|
||||
|
||||
- Related Tickets
|
||||
|
||||
- Slash commands
|
||||
@ -47,6 +53,8 @@ Comment types are:
|
||||
|
||||
Slash commands are a quick action that is specified after a slash command. As the name implies, the command starts with a slash `/`. The following slash commands are available:
|
||||
|
||||
- Linked Item `link`
|
||||
|
||||
- Related `/blocked_by`, `/blocks` and `/relate`
|
||||
|
||||
- Time Spent `/spend`, `/spent`
|
||||
@ -63,6 +71,17 @@ Slash commands are a quick action that is specified after a slash command. As th
|
||||
summary: true
|
||||
|
||||
|
||||
### Linked Items
|
||||
|
||||
::: app.core.lib.slash_commands.CommandLinkedModel
|
||||
options:
|
||||
inherited_members: false
|
||||
members: []
|
||||
show_bases: false
|
||||
show_submodules: false
|
||||
summary: true
|
||||
|
||||
|
||||
### Related Tickets
|
||||
|
||||
::: app.core.lib.slash_commands.CommandRelatedTicket
|
||||
|
@ -93,6 +93,8 @@ nav:
|
||||
|
||||
- projects/centurion_erp/development/api/models/access_organization_permission_checking.md
|
||||
|
||||
- projects/centurion_erp/development/api/models/ticket.md
|
||||
|
||||
- projects/centurion_erp/development/api/models/tenancy_object.md
|
||||
|
||||
- projects/centurion_erp/development/api/common_views.md
|
||||
@ -229,6 +231,12 @@ nav:
|
||||
|
||||
- projects/centurion_erp/user/project_management/project.md
|
||||
|
||||
- projects/centurion_erp/user/project_management/project_state.md
|
||||
|
||||
- projects/centurion_erp/user/project_management/project_task.md
|
||||
|
||||
- projects/centurion_erp/user/project_management/project_type.md
|
||||
|
||||
- Settings:
|
||||
|
||||
- projects/centurion_erp/user/settings/index.md
|
||||
|
Reference in New Issue
Block a user