Skip to content

Commit

Permalink
Merge pull request strictdoc-project#1481 from strictdoc-project/stan…
Browse files Browse the repository at this point in the history
…islaw/rst

UI: Create Document validations: document path is not white-/blacklisted in the config
  • Loading branch information
stanislaw authored Nov 20, 2023
2 parents 4bf6a98 + 3b29386 commit 7cc543e
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pygments.formatters.html import HtmlFormatter
from pygments.lexers.c_cpp import CLexer, CppLexer
from pygments.lexers.data import YamlLexer
from pygments.lexers.markup import TexLexer, RstLexer
from pygments.lexers.markup import RstLexer, TexLexer
from pygments.lexers.python import PythonLexer
from pygments.lexers.templates import HtmlDjangoLexer

Expand Down
28 changes: 28 additions & 0 deletions strictdoc/server/routers/main_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
from strictdoc.helpers.file_system import get_etag
from strictdoc.helpers.mid import MID
from strictdoc.helpers.parallelizer import NullParallelizer
from strictdoc.helpers.path_filter import PathFilter
from strictdoc.helpers.string import (
create_safe_acronym,
is_safe_alphanumeric_string,
Expand Down Expand Up @@ -1591,6 +1592,33 @@ def document_tree__create_document(
),
)

if project_config.include_doc_paths is not None:
path_filter_includes = PathFilter(
project_config.include_doc_paths, positive_or_negative=True
)
if not path_filter_includes.match(document_path):
error_object.add_error(
"document_path",
(
"Document path is not a valid path according to "
"the project config's setting 'include_doc_paths': "
f"{project_config.include_doc_paths}."
),
)
if project_config.exclude_doc_paths is not None:
path_filter_excludes = PathFilter(
project_config.exclude_doc_paths, positive_or_negative=False
)
if path_filter_excludes.match(document_path):
error_object.add_error(
"document_path",
(
"Document path is not a valid path according to "
"the project config's setting 'exclude_doc_paths': "
f"{project_config.exclude_doc_paths}."
),
)

if error_object.any_errors():
template = env().get_template(
"actions/project_index/stream_new_document.jinja.html"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[DOCUMENT]
TITLE: Document 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]

features = [

]

exclude_doc_paths = [
"tests/**",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]

features = [

]

exclude_doc_paths = [
"tests/**",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from tests.end2end.e2e_case import E2ECase
from tests.end2end.end2end_test_setup import End2EndTestSetup
from tests.end2end.helpers.screens.project_index.form_add_document import (
Form_AddDocument,
)
from tests.end2end.helpers.screens.project_index.screen_project_index import (
Screen_ProjectIndex,
)
from tests.end2end.server import SDocTestServer


class Test(E2ECase):
def test(self):
test_setup = End2EndTestSetup(path_to_test_file=__file__)

with SDocTestServer(
input_path=test_setup.path_to_sandbox
) as test_server:
self.open(test_server.get_host_and_port())

screen_project_index = Screen_ProjectIndex(self)
screen_project_index.assert_on_screen()
screen_project_index.assert_empty_tree()

form_add_document: Form_AddDocument = (
screen_project_index.do_open_modal_form_add_document()
)
form_add_document.do_fill_in_title("Document 1")

# First, fill in an invalid path.
form_add_document.do_fill_in_path("tests/document")
form_add_document.do_form_submit_and_catch_error(
"Document path is not a valid path according to the project "
"config's setting 'exclude_doc_paths': ['tests/**']."
)

# Then, fill in a valid path.
form_add_document.do_fill_in_path("docs/document")
form_add_document.do_form_submit()

screen_project_index.assert_contains_document("Document 1")

assert test_setup.compare_sandbox_and_expected_output()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[DOCUMENT]
TITLE: Document 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]

features = [

]

include_doc_paths = [
"docs/**",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]

features = [

]

include_doc_paths = [
"docs/**",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from tests.end2end.e2e_case import E2ECase
from tests.end2end.end2end_test_setup import End2EndTestSetup
from tests.end2end.helpers.screens.project_index.form_add_document import (
Form_AddDocument,
)
from tests.end2end.helpers.screens.project_index.screen_project_index import (
Screen_ProjectIndex,
)
from tests.end2end.server import SDocTestServer


class Test(E2ECase):
def test(self):
test_setup = End2EndTestSetup(path_to_test_file=__file__)

with SDocTestServer(
input_path=test_setup.path_to_sandbox
) as test_server:
self.open(test_server.get_host_and_port())

screen_project_index = Screen_ProjectIndex(self)
screen_project_index.assert_on_screen()
screen_project_index.assert_empty_tree()

form_add_document: Form_AddDocument = (
screen_project_index.do_open_modal_form_add_document()
)
form_add_document.do_fill_in_title("Document 1")

# First, fill in an invalid path.
form_add_document.do_fill_in_path("document")
form_add_document.do_form_submit_and_catch_error(
"Document path is not a valid path according to the project "
"config's setting 'include_doc_paths': ['docs/**']."
)

# Then, fill in a valid path.
form_add_document.do_fill_in_path("docs/document")
form_add_document.do_form_submit()

screen_project_index.assert_contains_document("Document 1")

assert test_setup.compare_sandbox_and_expected_output()
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ def test(self):
"Document path must be relative and only contain slashes, "
"alphanumeric characters, and underscore symbols."
)

form_add_document.do_fill_in_path("/test1.sdoc")
form_add_document.do_form_submit_and_catch_error(
"Document path must be relative and only contain slashes, "
"alphanumeric characters, and underscore symbols."
)
self.assert_text("/test1.sdoc")

0 comments on commit 7cc543e

Please sign in to comment.