From 421ad2daad364fc08ca188ecab2f5c079692e87a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 23 Aug 2020 23:55:29 +0200 Subject: [PATCH] Fix eval/exec commands on Royalnet 5.11 --- royalpack/commands/eval.py | 9 +++++---- royalpack/commands/exec.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/royalpack/commands/eval.py b/royalpack/commands/eval.py index 06d25619..945a8c42 100644 --- a/royalpack/commands/eval.py +++ b/royalpack/commands/eval.py @@ -12,10 +12,11 @@ class EvalCommand(rc.Command): syntax: str = "{espressione}" async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: - user: rbt.User = await data.get_author(error_if_none=True) - if "admin" not in user.roles: - raise rc.CommandError("Non sei autorizzato a eseguire codice arbitrario!\n" - "(Sarebbe un po' pericoloso se te lo lasciassi eseguire, non trovi?)") + async with data.session_acm() as session: + user: rbt.User = await data.find_author(session=session, required=True) + if "admin" not in user.roles: + raise rc.CommandError("Non sei autorizzato a eseguire codice arbitrario!\n" + "(Sarebbe un po' pericoloso se te lo lasciassi eseguire, non trovi?)") try: result = eval(args.joined(require_at_least=1)) except Exception as e: diff --git a/royalpack/commands/exec.py b/royalpack/commands/exec.py index ba024137..d523d620 100644 --- a/royalpack/commands/exec.py +++ b/royalpack/commands/exec.py @@ -12,10 +12,11 @@ class ExecCommand(rc.Command): syntax: str = "{script}" async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: - user: rbt.User = await data.get_author(error_if_none=True) - if "admin" not in user.roles: - raise rc.CommandError("Non sei autorizzato a eseguire codice arbitrario!\n" - "(Sarebbe un po' pericoloso se te lo lasciassi eseguire, non trovi?)") + async with data.session_acm() as session: + user: rbt.User = await data.find_author(session=session, required=True) + if "admin" not in user.roles: + raise rc.CommandError("Non sei autorizzato a eseguire codice arbitrario!\n" + "(Sarebbe un po' pericoloso se te lo lasciassi eseguire, non trovi?)") try: exec(args.joined(require_at_least=1)) except Exception as e: