~sircmpwn/builds.sr.ht

2e355ec47fb9c6115844fea38614f758154eec36 — Drew DeVault 14 days ago 0809968 0.70.10
secrets: improve error handling

Previously, this would not display errors for a missing secret type, due
to issues with Bootstrap's error CSS. This corrects this error and also
ensures that the list of secrets is displayed correctly in an error
scenario.
2 files changed, 11 insertions(+), 5 deletions(-)

M buildsrht/blueprints/secrets.py
M buildsrht/templates/secrets.html
M buildsrht/blueprints/secrets.py => buildsrht/blueprints/secrets.py +8 -4
@@ 56,7 56,8 @@ def secrets_POST():
        _secret = _secret.encode()

    if not valid.ok:
        return render_template("secrets.html", **valid.kwargs)
        secrets = Secret.query.filter(Secret.user_id == current_user.id).all()
        return render_template("secrets.html", secrets=secrets, **valid.kwargs)

    secret = Secret(current_user, secret_type)



@@ 64,18 65,21 @@ def secrets_POST():
        file_path = valid.require("file-path", friendly_name="Path")
        file_mode = valid.require("file-mode", friendly_name="Mode")
        if not valid.ok:
            return render_template("secrets.html", **valid.kwargs)
            secrets = Secret.query.filter(Secret.user_id == current_user.id).all()
            return render_template("secrets.html", secrets=secrets, **valid.kwargs)
        try:
            file_mode = int(file_mode, 8)
        except:
            valid.error("Must be specified in octal",
                    field="file-mode")
        if not valid.ok:
            return render_template("secrets.html", **valid.kwargs)
            secrets = Secret.query.filter(Secret.user_id == current_user.id).all()
            return render_template("secrets.html", secrets=secrets, **valid.kwargs)
        secret.path = file_path
        secret.mode = file_mode
    if not valid.ok:
        return render_template("secrets.html", **valid.kwargs)
        secrets = Secret.query.filter(Secret.user_id == current_user.id).all()
        return render_template("secrets.html", secrets=secrets, **valid.kwargs)

    secret.name = name
    secret.secret = _secret

M buildsrht/templates/secrets.html => buildsrht/templates/secrets.html +3 -1
@@ 33,7 33,7 @@
      </div>
      <fieldset class="form-group">
        <legend>Secret Type</legend>
        <div class="form-check form-check-inline {{ valid.cls("secret_type") }}">
        <div class="form-check form-check-inline">
          <label class="form-check-label">
            <input
              class="form-check-input"


@@ 66,6 66,8 @@
              {{ "checked" if secret_type == "plaintext_file" else "" }}> File
          </label>
        </div>
        {# XXX: Hack to appease Bootstrap #}
        <div class="form-control d-none {{ valid.cls("secret_type") }}"></div>
        {{ valid.summary("secret_type") }}
        <noscript>
          <p>The following fields only apply to "File" secrets:</p>