diff --git a/projects/tentacles/BUILD b/projects/tentacles/BUILD index 4febfd8..eb0a078 100644 --- a/projects/tentacles/BUILD +++ b/projects/tentacles/BUILD @@ -6,6 +6,7 @@ py_project( main_deps = [ "//projects/anosql", "//projects/anosql-migrations", + py_requirement("aiosql"), py_requirement("attrs"), py_requirement("click"), py_requirement("flask"), diff --git a/projects/tentacles/src/python/tentacles/__main__.py b/projects/tentacles/src/python/tentacles/__main__.py index 00a220b..46ec85b 100644 --- a/projects/tentacles/src/python/tentacles/__main__.py +++ b/projects/tentacles/src/python/tentacles/__main__.py @@ -23,11 +23,6 @@ from tentacles.workers import * from tentacles.workers import assign_jobs, Worker -@click.group() -def cli(): - pass - - def db_factory(app): store = Db(app.config.get("db", {}).get("uri")) store.connect() @@ -99,7 +94,7 @@ def make_app(): return app -@cli.command() +@click.command() @click.option("--hostname", "hostname", type=str, default="0.0.0.0") @click.option("--port", "port", type=int, default=8080) @click.option("--trace/--no-trace", "trace", default=False) @@ -154,4 +149,4 @@ def serve(hostname: str, port: int, config: Path, trace: bool): if __name__ == "__main__": - cli() + serve() diff --git a/projects/tentacles/src/python/tentacles/blueprints/admin_ui.py b/projects/tentacles/src/python/tentacles/blueprints/admin_ui.py index 2a2727f..ad55e5b 100644 --- a/projects/tentacles/src/python/tentacles/blueprints/admin_ui.py +++ b/projects/tentacles/src/python/tentacles/blueprints/admin_ui.py @@ -74,13 +74,7 @@ def get_users(): return redirect("/admin") -@BLUEPRINT.route("/admin/printers") -@requires_admin -def printers(): - return render_template("printers.html.j2") - - -@BLUEPRINT.route("/admin/printers/add", methods=["GET"]) +@BLUEPRINT.route("/admin/printers", methods=["GET"]) @requires_admin def add_printer(): return render_template("add_printer.html.j2") diff --git a/projects/tentacles/src/python/tentacles/blueprints/user_ui.py b/projects/tentacles/src/python/tentacles/blueprints/user_ui.py index f2fcd6e..7a7a8eb 100644 --- a/projects/tentacles/src/python/tentacles/blueprints/user_ui.py +++ b/projects/tentacles/src/python/tentacles/blueprints/user_ui.py @@ -71,11 +71,14 @@ def post_register(): try: username = request.form["username"] email = request.form["email"] + has_config = False group_id = 1 # Normal users status_id = -3 # Unverified for user_config in current_app.config.get("users", []): if user_config["email"] == email: + has_config = True + if "group_id" in user_config: group_id = user_config["group_id"] @@ -109,6 +112,11 @@ def post_register(): ) elif user.status_id == 1: + # Do the entire approval dance just to be absolutely sure any statically configured users work + ctx.db.try_verify_user(token=user.verification_token) + ctx.db.approve_user(uid=user.id) + ctx.db.enable_user(uid=user.id) + flash("Welcome, please log in", category="success") return render_template("register.html.j2") diff --git a/projects/tentacles/src/python/tentacles/templates/add_printer.html.j2 b/projects/tentacles/src/python/tentacles/templates/add_printer.html.j2 index 5074a97..cfdb305 100644 --- a/projects/tentacles/src/python/tentacles/templates/add_printer.html.j2 +++ b/projects/tentacles/src/python/tentacles/templates/add_printer.html.j2 @@ -21,30 +21,9 @@
- - +
- - {% endblock %} diff --git a/projects/tentacles/src/python/tentacles/templates/printers_list.html.j2 b/projects/tentacles/src/python/tentacles/templates/printers_list.html.j2 index ca6dfba..5eeaed0 100644 --- a/projects/tentacles/src/python/tentacles/templates/printers_list.html.j2 +++ b/projects/tentacles/src/python/tentacles/templates/printers_list.html.j2 @@ -21,10 +21,10 @@ {% endwith %} {% endfor %} {% if ctx.is_admin %} - Add a printer + Add a printer {% endif %} {% else %} - No printers available. {% if ctx.is_admin %}Configure one!{% else %}Ask the admin to configure one!{% endif %} + No printers available. {% if ctx.is_admin %}Configure one!{% else %}Ask the admin to configure one!{% endif %} {% endif %} {% endwith %} diff --git a/projects/tentacles/src/python/tentacles/workers.py b/projects/tentacles/src/python/tentacles/workers.py index 13344e9..29e6019 100644 --- a/projects/tentacles/src/python/tentacles/workers.py +++ b/projects/tentacles/src/python/tentacles/workers.py @@ -38,6 +38,15 @@ class OctoRest(_OR): response.raise_for_status() return response + def files_info(self, *args, **kwargs): + try: + return super().files_info(*args, **kwargs) + except HTTPError as e: + if e.response.status_code == 404: + return {} + else: + raise e + log = logging.getLogger(__name__)