Implement mailing lists from templates

This commit is contained in:
Drew DeVault 2020-04-02 13:53:23 -04:00
parent c2b3216250
commit ab1cb8e381
1 changed files with 84 additions and 2 deletions

View File

@ -3,9 +3,10 @@ from hubsrht.projects import ProjectAccess, get_project
from import lists
from hubsrht.types import Event, EventType
from hubsrht.types import MailingList
from srht.config import get_origin
from srht.database import db
from srht.flask import paginate_query
from srht.oauth import loginrequired
from srht.oauth import current_user, loginrequired
from import search_by
from srht.validation import Validation
@ -44,13 +45,94 @@ def new_GET(owner, project_name):
return render_template("mailing-list-new.html", view="new-resource",
owner=owner, project=project, lists=mls)
def lists_from_template(owner, project, template):
project_url = url_for("projects.summary_GET",
project_url = get_origin("", external=True) + project_url
templates = {
"public-inbox": ["public-inbox"],
"announce-devel": [f"{}-announce", f"{}-devel"],
"announce-devel-discuss": [
descs = {
"public-inbox": f"""
General catch-all for patches, questions, and discussions for any of
{current_user.canonical_name}'s projects which do not have their own mailing
When posting patches to this list, please edit the [PATCH] line to include the
specific project you're contributing to, e.g.
[PATCH {} v2] Add thing to stuff
f"{}-announce": f"""
Low-volume mailing list for announcements related to the
[{}]({project_url}) project.
f"{}-devel": f"""
Mailing list for development discussion and patches related to the
[{}]({project_url}) project. For help sending patches to this
list, please consult [](
f"{}-discuss": f"""
Mailing list for end-user discussion and questions related to the
[{}]({project_url}) project.
template = templates[template]
for list_name in template:
mailing_list = lists.get_list(owner, list_name)
mailing_list = lists.create_list(owner, Validation({
"name": list_name,
"description": descs[list_name],
ml = MailingList()
ml.remote_id = mailing_list["id"]
ml.project_id =
ml.owner_id = project.owner_id = mailing_list["name"]
ml.description = mailing_list["description"]
event = Event()
event.event_type = EventType.mailing_list_added
event.mailing_list_id =
event.project_id =
event.user_id = project.owner_id
return redirect(project_url)
@mailing_lists.route("/<owner>/<project_name>/lists/new", methods=["POST"])
def new_POST(owner, project_name):
owner, project = get_project(owner, project_name, ProjectAccess.write)
valid = Validation(request)
if "from-template" in valid:
assert False # TODO: Create lists from template
template = valid.require("template")
valid.expect(template in ["public-inbox",
"announce-devel", "announce-devel-discuss"],
"Invalid template selection")
if not valid.ok:
mls = lists.get_lists(owner)
mls = sorted(mls, key=lambda r: r["updated"], reverse=True)
return render_template("mailing-list-new.html",
view="new-resource", owner=owner, project=project,
lists=mls, **valid.kwargs)
return lists_from_template(owner, project, template)
elif "create" in valid:
mailing_list = lists.create_list(owner, valid)
if not valid.ok: