From 0194dbf00838a648c838fee82b6e2815281e68d8 Mon Sep 17 00:00:00 2001 From: jachamp <28732543+jimchamp@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:22:53 -0700 Subject: [PATCH 1/4] Update edit view's tag type options Adds default "Select" option. Ensures that option order is maintained, regardless of what type of tag is being edited. This change more closely matches the type options in the "Add tag" view, making it easier to combine these two very similar templates in the near future. --- openlibrary/templates/type/tag/edit.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openlibrary/templates/type/tag/edit.html b/openlibrary/templates/type/tag/edit.html index 20d4ca5a5b9..eae852c1735 100644 --- a/openlibrary/templates/type/tag/edit.html +++ b/openlibrary/templates/type/tag/edit.html @@ -36,10 +36,12 @@

$_("Edit Tag")

From 0a9c033b3c0c5a4054f58eeccfc6b73b83135161 Mon Sep 17 00:00:00 2001 From: jachamp <28732543+jimchamp@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:25:00 -0700 Subject: [PATCH 2/4] Add frontend validation for tag type --- openlibrary/templates/tag/add.html | 2 +- openlibrary/templates/type/tag/edit.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlibrary/templates/tag/add.html b/openlibrary/templates/tag/add.html index 2998fe023cf..4d7a71def3d 100644 --- a/openlibrary/templates/tag/add.html +++ b/openlibrary/templates/tag/add.html @@ -39,7 +39,7 @@

$_("Add a tag to Open Library")

- $ tag_types = get_tag_types() $for tag_type in tag_types: diff --git a/openlibrary/templates/type/tag/edit.html b/openlibrary/templates/type/tag/edit.html index eae852c1735..e1724d63cef 100644 --- a/openlibrary/templates/type/tag/edit.html +++ b/openlibrary/templates/type/tag/edit.html @@ -35,7 +35,7 @@

$_("Edit Tag")

- $ tag_types = get_tag_types() $for tag_type in tag_types: From ad2cf9c710434cac7c812e94ebc7bfc68f59f19c Mon Sep 17 00:00:00 2001 From: jachamp <28732543+jimchamp@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:43:04 -0700 Subject: [PATCH 3/4] Add backend tag property validation --- openlibrary/plugins/upstream/addtag.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/openlibrary/plugins/upstream/addtag.py b/openlibrary/plugins/upstream/addtag.py index 67799932d9c..dd89abb0fb2 100644 --- a/openlibrary/plugins/upstream/addtag.py +++ b/openlibrary/plugins/upstream/addtag.py @@ -21,6 +21,10 @@ def get_tag_types(): return ["subject", "work", "collection"] +def validate_tag(tag): + return tag.get('name', '') and tag.get('tag_type', '') + + class addtag(delegate.page): path = '/tag/add' @@ -62,6 +66,10 @@ def POST(self): raise web.unauthorized(message='Permission denied to add tags') i = utils.unflatten(i) + + if not i.tag_name or not i.tag_type: + raise web.badrequest() + match = self.find_match(i) # returns None or Tag (if match found) if match: @@ -120,7 +128,7 @@ def POST(self, key): i = web.input(_comment=None) formdata = self.process_input(i) try: - if not formdata: + if not formdata or not validate_tag(formdata): raise web.badrequest() elif "_delete" in i: tag = web.ctx.site.new( From 2346f81d1feb12cee663b37a1d874403bfbe2b70 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Aug 2024 23:59:09 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/i18n/messages.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlibrary/i18n/messages.pot b/openlibrary/i18n/messages.pot index 1b02f77d596..b5127cda816 100644 --- a/openlibrary/i18n/messages.pot +++ b/openlibrary/i18n/messages.pot @@ -3395,7 +3395,7 @@ msgstr "" msgid "ISBN may be invalid. Click \"Add\" again to submit." msgstr "" -#: books/add.html tag/add.html +#: books/add.html tag/add.html type/tag/edit.html msgid "Select" msgstr ""