This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push:
new f897562 Fix a category display bug, and do not allow retired to be
added or removed
f897562 is described below
commit f897562b2abf61d5944f70a1b37095b036c1040c
Author: Sean B. Palmer <[email protected]>
AuthorDate: Thu Jun 12 16:12:52 2025 +0100
Fix a category display bug, and do not allow retired to be added or removed
---
atr/routes/projects.py | 51 ++++++++++++++++++++++++----------
atr/templates/committee-directory.html | 2 +-
atr/templates/project-view.html | 12 ++++----
3 files changed, 44 insertions(+), 21 deletions(-)
diff --git a/atr/routes/projects.py b/atr/routes/projects.py
index 16a5da4..87ba850 100644
--- a/atr/routes/projects.py
+++ b/atr/routes/projects.py
@@ -19,7 +19,7 @@
import datetime
import http.client
-from typing import Protocol
+from typing import Final, Protocol
import asfquart.base as base
import quart
@@ -33,6 +33,10 @@ import atr.template as template
import atr.user as user
import atr.util as util
+_FORBIDDEN_CATEGORIES: Final[set[str]] = {
+ "retired",
+}
+
class AddFormProtocol(Protocol):
committee_name: wtforms.HiddenField
@@ -268,6 +272,7 @@ async def view(session: routes.CommitterSession, name: str)
-> response.Response
policy_form=policy_form,
can_edit=can_edit,
metadata_form=metadata_form,
+ forbidden_categories=_FORBIDDEN_CATEGORIES,
)
@@ -280,23 +285,11 @@ async def _metadata_category_edit(
current_languages: list[str],
) -> bool:
# TODO: Add error handling
- # Also this only just squeaks by the complexity checker
modified = False
if (action_type == "add_category") and metadata_form.category_to_add.data:
- new_cat = metadata_form.category_to_add.data.strip()
- if new_cat and (new_cat not in current_categories):
- if ":" in new_cat:
- raise ValueError(f"Category '{new_cat}' contains a colon")
- current_categories.append(new_cat)
- current_categories.sort()
- project.category = ", ".join(current_categories)
- await quart.flash(f"Category '{new_cat}' added.", "success")
- modified = True
+ modified = await _metadata_category_edit_add(metadata_form, project,
current_categories)
elif (action_type == "remove_category") and action_value and (action_value
in current_categories):
- current_categories.remove(action_value)
- project.category = ", ".join(current_categories)
- await quart.flash(f"Category '{action_value}' removed.", "success")
- modified = True
+ modified = await _metadata_category_edit_remove(action_value, project,
current_categories)
elif (action_type == "add_language") and
metadata_form.language_to_add.data:
new_lang = metadata_form.language_to_add.data.strip()
if new_lang and (new_lang not in current_languages):
@@ -315,6 +308,34 @@ async def _metadata_category_edit(
return modified
+async def _metadata_category_edit_add(
+ metadata_form: ProjectMetadataForm, project: models.Project,
current_categories: list[str]
+) -> bool:
+ new_cat = util.unwrap(metadata_form.category_to_add.data).strip()
+ if new_cat and (new_cat not in current_categories):
+ if ":" in new_cat:
+ raise ValueError(f"Category '{new_cat}' contains a colon")
+ if new_cat in _FORBIDDEN_CATEGORIES:
+ raise ValueError(f"Category '{new_cat}' may not be added or
removed")
+ current_categories.append(new_cat)
+ current_categories.sort()
+ project.category = ", ".join(current_categories)
+ await quart.flash(f"Category '{new_cat}' added.", "success")
+ return True
+ return False
+
+
+async def _metadata_category_edit_remove(
+ action_value: str, project: models.Project, current_categories: list[str]
+) -> bool:
+ if action_value in _FORBIDDEN_CATEGORIES:
+ raise ValueError(f"Category '{action_value}' may not be added or
removed")
+ current_categories.remove(action_value)
+ project.category = ", ".join(current_categories)
+ await quart.flash(f"Category '{action_value}' removed.", "success")
+ return True
+
+
async def _metadata_edit(
data: db.Session, project: models.Project, form_data: dict[str, str]
) -> tuple[bool, ProjectMetadataForm]:
diff --git a/atr/templates/committee-directory.html
b/atr/templates/committee-directory.html
index ad69221..2906e86 100644
--- a/atr/templates/committee-directory.html
+++ b/atr/templates/committee-directory.html
@@ -131,7 +131,7 @@
</div>
<div class="mb-1 page-project-subcard-categories">
{% set categories = project.category.split(', ') if
project.category else [] %}
- {% for category in categories[:1] %}
+ {% for category in categories %}
{% if category != "retired" %}<span class="badge
text-bg-primary me-1">{{ category }}</span>{% endif %}
{% endfor %}
{% set langs = project.programming_languages.split(',
') if project.programming_languages else [] %}
diff --git a/atr/templates/project-view.html b/atr/templates/project-view.html
index d3bc960..797520a 100644
--- a/atr/templates/project-view.html
+++ b/atr/templates/project-view.html
@@ -356,11 +356,13 @@
{% for cat in current_categories %}
<div class="badge bg-primary d-flex align-items-center p-2">
<span>{{ cat }}</span>
- <button type="submit"
- name="action"
- value="remove_category:{{ cat }}"
- class="btn-close btn-close-white ms-2
page-remove-tag"
- aria-label="Remove {{ cat }}"></button>
+ {% if cat not in forbidden_categories %}
+ <button type="submit"
+ name="action"
+ value="remove_category:{{ cat }}"
+ class="btn-close btn-close-white ms-2
page-remove-tag"
+ aria-label="Remove {{ cat }}"></button>
+ {% endif %}
</div>
{% endfor %}
</div>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]