This is an automated email from the ASF dual-hosted git repository.

tn 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 1b24f8e  start working on a vote policy edit form
1b24f8e is described below

commit 1b24f8e803247aca9b586bdecc9817f7f9f03903
Author: Thomas Neidhart <[email protected]>
AuthorDate: Wed Mar 12 21:23:33 2025 +0100

    start working on a vote policy edit form
---
 atr/routes/vote_policy.py           | 106 ++++++++++++++++++++++++++++++++++++
 atr/server.py                       |   2 +
 atr/templates/vote-policy-edit.html |  86 +++++++++++++++++++++++++++++
 3 files changed, 194 insertions(+)

diff --git a/atr/routes/vote_policy.py b/atr/routes/vote_policy.py
new file mode 100644
index 0000000..0e29db1
--- /dev/null
+++ b/atr/routes/vote_policy.py
@@ -0,0 +1,106 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""vote_policy.py"""
+
+import quart
+import quart_wtf
+import sqlmodel
+import werkzeug.wrappers.response as response
+import wtforms
+
+import asfquart.session as session
+import atr.db as db
+import atr.db.models as models
+import atr.routes as routes
+from asfquart import base
+from asfquart.base import ASFQuartException
+
+
+class VotePolicyForm(quart_wtf.QuartForm):
+    project_name = wtforms.HiddenField("project_name")
+    mailto_addresses = wtforms.StringField(
+        "Email",
+        validators=[
+            wtforms.validators.InputRequired("Please provide a valid email 
address"),
+            wtforms.validators.Email(),
+        ],
+    )
+    min_hours = wtforms.IntegerField(
+        "Minimum Voting Period:", widget=wtforms.widgets.NumberInput(min=0, 
max=144), default=72
+    )
+    manual_vote = wtforms.BooleanField("Voting Process:")
+    release_checklist = wtforms.StringField("Release Checklist:", 
widget=wtforms.widgets.TextArea())
+    pause_for_rm = wtforms.BooleanField("Pause for RM:")
+
+    submit = wtforms.SubmitField("Save")
+
+
[email protected]_route("/vote/<vote_policy_id>/edit", methods=["GET", "POST"])
+async def root_vote_policy_edit(vote_policy_id: str) -> response.Response | 
str:
+    web_session = await session.read()
+    if web_session is None:
+        raise base.ASFQuartException("Not authenticated", errorcode=401)
+
+    async with db.create_async_db_session() as db_session:
+        statement = 
sqlmodel.select(models.VotePolicy).where(models.VotePolicy.id == 
int(vote_policy_id))
+        vote_policy = (await 
db_session.execute(statement)).scalar_one_or_none()
+        if not vote_policy:
+            raise ASFQuartException("Vote policy not found", 404)
+
+    form = await VotePolicyForm.create_form()
+
+    if quart.request.method == "GET":
+        form.process(obj=vote_policy)
+
+    if await form.validate_on_submit():
+        return ""
+        # return await add_voting_policy(web_session, form)  # pyright: ignore 
[reportArgumentType]
+
+    # For GET requests, show the form
+    return await quart.render_template(
+        "vote-policy-edit.html",
+        asf_id=web_session.uid,
+        form=form,
+    )
+
+
+# async def add_voting_policy(session: session.ClientSession, form: 
CreateVotePolicyForm) -> response.Response:
+#     project_name = form.project_name.data
+#
+#     async with db.create_async_db_session() as db_session:
+#         async with db_session.begin():
+#             statement = 
sqlmodel.select(models.PMC).where(models.PMC.project_name == project_name)
+#             pmc = (await db_session.execute(statement)).scalar_one_or_none()
+#             if not pmc:
+#                 raise base.ASFQuartException("PMC not found", errorcode=404)
+#             elif pmc.project_name not in session.committees:
+#                 raise base.ASFQuartException(
+#                     f"You must be a PMC member of {pmc.display_name} to 
submit a voting policy", errorcode=403
+#                 )
+#
+#             vote_policy = models.VotePolicy(
+#                 mailto_addresses=[unwrap(form.mailto_addresses.data)],
+#                 manual_vote=form.manual_vote.data,
+#                 min_hours=unwrap(form.min_hours.data),
+#                 release_checklist=unwrap(form.release_checklist.data),
+#                 pause_for_rm=form.pause_for_rm.data,
+#             )
+#             db_session.add(vote_policy)
+#
+#     # Redirect to the add package page with the storage token
+#     return quart.redirect(quart.url_for("root_project_view", 
project_name=project_name))
diff --git a/atr/server.py b/atr/server.py
index 1ff9dc9..509c0cc 100644
--- a/atr/server.py
+++ b/atr/server.py
@@ -65,6 +65,7 @@ def register_routes(app: base.QuartApp) -> tuple[str, ...]:
     import atr.routes.project as project
     import atr.routes.release as release
     import atr.routes.root as root
+    import atr.routes.vote_policy as vote_policy
 
     # Add a global error handler to show helpful error messages with 
tracebacks.
     @app.errorhandler(Exception)
@@ -99,6 +100,7 @@ def register_routes(app: base.QuartApp) -> tuple[str, ...]:
         package.__name__,
         project.__name__,
         release.__name__,
+        vote_policy.__name__,
         root.__name__,
     )
 
diff --git a/atr/templates/vote-policy-edit.html 
b/atr/templates/vote-policy-edit.html
new file mode 100644
index 0000000..4977714
--- /dev/null
+++ b/atr/templates/vote-policy-edit.html
@@ -0,0 +1,86 @@
+{% extends "layouts/base.html" %}
+
+{% block title %}
+  Edit a voting policy ~ ATR
+{% endblock title %}
+
+{% block description %}
+  Edit a vote policy.
+{% endblock description %}
+
+{% block theme_css %}
+  <link rel="stylesheet"
+        href="{{ url_for('static', filename='css/atr-small.css') }}" />
+{% endblock theme_css %}
+
+{% block stylesheets %}
+  {{ super() }}
+{% endblock stylesheets %}
+
+{% block content %}
+  <h1>Edit vote policy</h1>
+  <p>
+    Welcome, <strong>{{ asf_id }}</strong>!
+  </p>
+
+  <form method="post"
+        enctype="multipart/form-data"
+        class="striking py-4 px-5">
+    <input type="hidden" name="form_type" value="single" />
+
+    <div class="mb-3 pb-3 row border-bottom">
+      <label for="{{ form.mailto_addresses.id }}"
+             class="col-sm-3 col-form-label text-sm-end">{{ 
form.mailto_addresses.label.text }}</label>
+      <div class="col-sm-8">
+        <div>{{ form.mailto_addresses(size=30, class_="form-control") }}</div>
+        {% if form.mailto_addresses.errors -%}
+          <span class="error-message">{{ form.mailto_addresses.errors[0] 
}}</span>
+        {%- endif %}
+      </div>
+    </div>
+
+    <div class="mb-3 pb-3 row border-bottom">
+      <label for="{{ form.manual_vote.id }}"
+             class="col-sm-3 col-form-label text-sm-end">{{ 
form.manual_vote.label.text }}</label>
+      <div class="col-sm-8">
+        {{ form.manual_vote(class_="form-check-input") }}
+        <label class="form-check-label">Manual</label>
+        <br />
+        <span id="manual_vote-help" class="form-text text-muted">If this is 
set then the vote will be completely manual and following policy is 
ignored.</span>
+      </div>
+    </div>
+
+    <div class="mb-3 pb-3 row border-bottom">
+      <label for="{{ form.min_hours.id }}"
+             class="col-sm-3 col-form-label text-sm-end">{{ 
form.min_hours.label.text }}</label>
+      <div class="col-sm-8">
+        {{ form.min_hours(class_="form-control") }}
+        <span id="min_hours-help" class="form-text text-muted">The minimum 
time to run the vote. If set to 0 then wait until 3 +1 votes and more +1 than 
-1.</span>
+      </div>
+    </div>
+
+    <div class="mb-3 pb-3 row border-bottom">
+      <label for="{{ form.release_checklist.id }}"
+             class="col-sm-3 col-form-label text-sm-end">{{ 
form.release_checklist.label.text }}</label>
+      <div class="col-sm-8">
+        {{ form.release_checklist(rows=10, style='resize: vertical', 
class_="form-control") }}
+        <span id="release_checklist-help" class="form-text 
text-muted">Markdown text describing how to test release candidates.</span>
+      </div>
+    </div>
+
+    <div class="mb-3 pb-3 row border-bottom">
+      <label for="{{ form.pause_for_rm.id }}"
+             class="col-sm-3 col-form-label text-sm-end">{{ 
form.pause_for_rm.label.text }}</label>
+      <div class="col-sm-8">
+        {{ form.pause_for_rm(class_="form-check-input") }}
+        <label class="form-check-label">Enabled</label>
+        <br />
+        <span id="pause_for_rm-help" class="form-text text-muted">If enabled, 
RM can confirm manually if the vote has passed.</span>
+      </div>
+    </div>
+
+    <div class="row">
+      <div class="col-sm-9 offset-sm-3">{{ form.submit(class_="btn btn-primary 
mt-2") }}</div>
+    </div>
+  </form>
+{% endblock content %}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to