Skip to content

Commit

Permalink
Merge branch 'comment-shortcut-hints' into 'main'
Browse files Browse the repository at this point in the history
Add md shortcut hints

See merge request reportcreator/reportcreator!788
  • Loading branch information
MWedl committed Dec 3, 2024
2 parents c6048a0 + 919bf8e commit dd6b070
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 50 deletions.
6 changes: 3 additions & 3 deletions packages/frontend/src/components/Markdown/Toolbar.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-toolbar ref="toolbarRef" density="compact" flat class="toolbar">
<markdown-toolbar-button @click="codemirrorAction(toggleStrong)" title="Bold" icon="mdi-format-bold" :disabled="props.disabled" :active="isTypeInSelection(props.editorState, 'strong')" />
<markdown-toolbar-button @click="codemirrorAction(toggleEmphasis)" title="Italic" icon="mdi-format-italic" :disabled="props.disabled" :active="isTypeInSelection(props.editorState, 'emphasis')" />
<markdown-toolbar-button @click="codemirrorAction(toggleStrong)" title="Bold (Ctrl+B)" icon="mdi-format-bold" :disabled="props.disabled" :active="isTypeInSelection(props.editorState, 'strong')" />
<markdown-toolbar-button @click="codemirrorAction(toggleEmphasis)" title="Italic (Ctrl+I)" icon="mdi-format-italic" :disabled="props.disabled" :active="isTypeInSelection(props.editorState, 'emphasis')" />
<markdown-toolbar-button @click="codemirrorAction(toggleStrikethrough)" title="Strikethrough" icon="mdi-format-strikethrough" :disabled="props.disabled" :active="isTypeInSelection(props.editorState, 'strikethrough')" />
<markdown-toolbar-button @click="codemirrorAction(toggleFootnote)" title="Footnote" icon="mdi-format-superscript" :disabled="props.disabled" :active="isTypeInSelection(props.editorState, 'inlineFootnote')" />
<span class="separator" />
Expand Down Expand Up @@ -61,7 +61,7 @@
<markdown-toolbar-button
v-if="props.collab?.comments"
@click="emitCreateComment"
title="Comment"
title="Comment (Ctrl+Alt+M)"
icon="mdi-comment-plus-outline"
:disabled="props.disabled || !props.editorState"
/>
Expand Down
2 changes: 1 addition & 1 deletion plugins/projectnumber/templatetags/random_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
def random_number(a, b=None):
if b is None:
a, b = 0, a
return random.randint(int(a), int(b))
return random.randint(int(a), int(b))
70 changes: 24 additions & 46 deletions plugins/projectnumber/tests/test_plugin_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import contextlib
from unittest import mock

import pytest
from django.apps import apps
from django.template.defaultfilters import date
from django.template.defaulttags import NowNode
from django.utils import dateparse
from reportcreator_api.pentests.customfields.types import (
FieldDefinition,
StringField,
Expand Down Expand Up @@ -30,6 +34,12 @@ def override_projectnumber_settings(**kwargs):
app.settings = old_settings


class MockNowNode(NowNode):
def render(self, context):
now = dateparse.parse_datetime('2024-11-27T12:21:30Z')
return date(now, self.format_string)


@pytest.mark.django_db
class TestProjectNumberPlugin:
@pytest.fixture(autouse=True)
Expand All @@ -38,19 +48,23 @@ def setUp(self):
self.client = api_client(self.user)

@pytest.mark.parametrize(
"template, context, expected",
"template, expected",
[
("{{ project_number }}", {"project_number": 1}, "1"),
("Project No: {{ project_number }}", {"project_number": 1}, "Project No: 1"),
("R{% now 'y' %}-{{project_number|stringformat:'04d'}}", {"project_number": 1}, "R24-0001"),
("{% now 'Y' %}-{{project_number|stringformat:'04d'}}", {"project_number": 1}, "2024-0001"),
("Prefix-{% now 'y' %}{% now 'm' %}{{project_number|stringformat:'04d'}}-Suffix", {"project_number": 1}, "Prefix-24110001-Suffix"),
("{{ 1000|add:project_number }}", {"project_number": 1}, "1001"),
("{{ project_number }}", "1"),
("Project No: {{ project_number }}", "Project No: 1"),
("R{% now 'y' %}-{{project_number|stringformat:'04d'}}", "R24-0001"),
("{% now 'Y' %}-{{project_number|stringformat:'04d'}}", "2024-0001"),
("Prefix-{% now 'y' %}{% now 'm' %}{{project_number|stringformat:'04d'}}-Suffix", "Prefix-24110001-Suffix"),
("{{ 1000|add:project_number }}", "1001"),
("P{{ project_number|stringformat:'04d' }}{% random_number 5 23|stringformat:'02d' %}", "P000117"),
]
)
def test_on_project_saved(self, template, context, expected):
def test_on_project_saved(self, template, expected):
# Override settings to use the custom template
with override_projectnumber_settings(PLUGIN_PROJECTNUMBER_TEMPLATE=template):
with override_projectnumber_settings(PLUGIN_PROJECTNUMBER_TEMPLATE=template), \
mock.patch('django.template.defaulttags.NowNode', new=MockNowNode), \
mock.patch('random.randint', return_value=17):

# Initialize project counter
counter, _ = ProjectNumber.objects.get_or_create(pk=1)
assert counter.current_id == 0
Expand Down Expand Up @@ -84,40 +98,4 @@ def test_on_project_saved(self, template, context, expected):

# Check project counter increment
counter.refresh_from_db()
assert counter.current_id == context['project_number']

@pytest.mark.parametrize("template, context", [
("P{{ project_number|stringformat:'04d' }}{% random_number 5 23|stringformat:'02d' %}", {"project_number": 1}),
])
def test_template_with_random_suffix(self, template, context):
# Override settings for random number suffix template
with override_projectnumber_settings(PLUGIN_PROJECTNUMBER_TEMPLATE=template):
# Create project and validate random suffix
project_type = create_project_type(
report_sections=[
{
'id': 'project_number',
'label': 'Project Counter',
'fields': serialize_field_definition(
FieldDefinition(
fields=[
StringField(
id='project_number',
label='Project Counter',
required=True,
),
]
)
),
}
]
)
project = create_project(project_type=project_type, members=[self.user])
section = project.sections.get(section_id='project_number')

rendered = section.data.get('project_number')
assert rendered.startswith(f"P{context['project_number']:04d}")

# Validate random suffix
random_suffix = int(rendered[-2:])
assert 5 <= random_suffix <= 23
assert counter.current_id == 1

0 comments on commit dd6b070

Please sign in to comment.