This is an automated email from the ASF dual-hosted git repository. gstein pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/steve.git
commit 1c2a544c97385bd18c2f99356b7c320901c85ab3 Author: Greg Stein <[email protected]> AuthorDate: Thu Oct 16 23:54:31 2025 -0500 Draft up load_election_issue decorator. --- v3/server/pages.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/v3/server/pages.py b/v3/server/pages.py index 8b5fcde..912e965 100644 --- a/v3/server/pages.py +++ b/v3/server/pages.py @@ -145,6 +145,42 @@ def load_election(func): return loader +def load_election_issue(func): + "Decorator to load/pass-argument an Election from EID." + + @functools.wraps(func) + async def loader(eid, iid): + + try: + e = steve.election.Election(DB_FNAME, eid) + except steve.election.ElectionNotFound: + result = await basic_info() + result.title = 'Unknown Election' + result.eid = eid + # Note: result.uid (and friends) are needed for the navbar. + raise_404(T_BAD_EID, result) + # NOTREACHED + + _LOGGER.debug(f'Loaded: {e}') + + ### check authz + + try: + i = e.get_issue(iid) + except steve.election.IssueNotFound: + result = await basic_info() + result.title = 'Unknown Issue' + result.eid = eid + result.iid = iid + # Note: result.uid (and friends) are needed for the navbar. + raise_404(T_BAD_IID, result) + # NOTREACHED + + return await func(e, i) + + return loader + + @APP.get('/vote-on/<eid>') @asfquart.auth.require({R.committer}) ### need general solution @load_election @@ -289,7 +325,7 @@ async def do_add_issue_endpoint(election): @APP.post('/do-edit-issue/<eid>/<iid>') @asfquart.auth.require({R.committer}) ### need general solution -###@load_election_issue +@load_election_issue async def do_edit_issue_endpoint(election, issue): result = await basic_info() @@ -306,7 +342,7 @@ async def do_edit_issue_endpoint(election, issue): @APP.delete('/do-delete-issue/<eid>/<iid>') @asfquart.auth.require({R.committer}) ### need general solution -###@load_election_issue +@load_election_issue async def do_delete_issue_endpoint(election, issue): result = await basic_info()
