fix functions delete/edit/... on different state

This commit is contained in:
Jakobus Schürz 2019-09-30 01:38:23 +02:00
parent 1f52e54211
commit be374f5d77
5 changed files with 61 additions and 61 deletions

View file

@ -69,7 +69,8 @@ def create():
print(fingerprint) print(fingerprint)
ckfp = db.execute( ckfp = db.execute(
'SELECT id, fingerprint, deleted FROM pubkeys WHERE fingerprint = ?', (fingerprint, ) 'SELECT id, fingerprint, deleted FROM pubkeys'
' WHERE fingerprint = ? AND user_id = ?', (fingerprint, g.user['id'] )
).fetchone() ).fetchone()

View file

@ -29,4 +29,4 @@ nav ul li a, nav ul li span, header .action { display: block; padding: 0.5rem; }
.danger { color: #cc2f2e; } .danger { color: #cc2f2e; }
input.danger { color: #cc2f2e; } input.danger { color: #cc2f2e; }
input[type=submit] { align-self: start; min-width: 10em; } input[type=submit] { align-self: start; min-width: 10em; }
.key { color: #cc22ff; } .key { border: 1px solid lightgray;}

View file

@ -8,7 +8,7 @@
Certificates Certificates
{% endif %}</h1> {% endif %}</h1>
{% endblock %} {% endblock %}
{% if g.user %} {% if g.user and pubkey['revoked'] == 0 %}
<!--a class="action" href="{{ url_for('pubkeys.certs_create', id=1 ) }}">New</a--> <!--a class="action" href="{{ url_for('pubkeys.certs_create', id=1 ) }}">New</a-->
<form class="action" action="{{ url_for('pubkeys.certs_create', id=pubkey['id'] ) }}" method="POST"> <form class="action" action="{{ url_for('pubkeys.certs_create', id=pubkey['id'] ) }}" method="POST">
<input type="submit" value="Create new certificate"> <input type="submit" value="Create new certificate">
@ -26,13 +26,14 @@
{% block content %} {% block content %}
{% if g.user %} {% if g.user %}
{% for certificate in certificates %} {% for certificate in certificates %}
{% if certificate['deleted'] == 0 and pubkey['user_id'] == g.user['id'] %} {% if ( certificate['deleted'] == 0 and pubkey['user_id'] == g.user['id'] ) or user['admin'] == 1 %}
<article class="post"> <article class="post">
<header> <header>
<div> <div>
<h1>Certificate ID: {{ certificate['key_id'] }} </h1> <h1>
Certificate ID: {{ certificate['key_id'] }}
</h1>
{% if certificate['revoked'] != 0 %} {% if certificate['revoked'] != 0 %}
<div class="info">this certificate was manually revoked</div> <div class="info">this certificate was manually revoked</div>
{% endif %} {% endif %}
@ -49,6 +50,9 @@
{% endif %} {% endif %}
</header> </header>
<p class="body{% if certificate['revoked'] != 0 %} revoked {% endif %}"> <p class="body{% if certificate['revoked'] != 0 %} revoked {% endif %}">
{% if user['admin'] == 1 %}
<div name="owner" id="owner">owner: {{ pubkey['username']}}</div>
{% endif %}
Serialnumber: {{ certificate['serial'] }}{% if certificate['c.revoked'] != 0 %} - revoked {% endif %} Serialnumber: {{ certificate['serial'] }}{% if certificate['c.revoked'] != 0 %} - revoked {% endif %}
Validity duration: {{ certificate['valid_from'].strftime('%Y-%m-%d %H:%M') }} - {{ certificate['valid_until'].strftime('%Y-%m-%d %H:%M') }} Validity duration: {{ certificate['valid_from'].strftime('%Y-%m-%d %H:%M') }} - {{ certificate['valid_until'].strftime('%Y-%m-%d %H:%M') }}
Principals: {{ certificate['principals'] }} Principals: {{ certificate['principals'] }}
@ -59,10 +63,6 @@
Deleted: {{ certificate['deleted'] }} Deleted: {{ certificate['deleted'] }}
</p> </p>
<p class="about">created on {{ certificate['created'].strftime('%Y-%m-%d') }}</p> <p class="about">created on {{ certificate['created'].strftime('%Y-%m-%d') }}</p>
{% if certificate['revoked'] == 0 %}
</form>
{% endif %}
</article> </article>
{% if not loop.last %} {% if not loop.last %}
<hr> <hr>

View file

@ -17,40 +17,41 @@
{% if g.user %} {% if g.user %}
{% for pubkey in pubkeys %} {% for pubkey in pubkeys %}
{% if ( pubkey['deleted'] == 0 and pubkey['user_id'] == g.user['id'] ) or user['admin'] == 1 %} {% if ( pubkey['deleted'] == 0 and pubkey['user_id'] == g.user['id'] ) or user['admin'] == 1 %}
<article class="post{% if pubkey['revoked'] != 0 %} revoked{% endif %}{% if pubkey['deleted'] != 0 %} deleted{% endif %}"> <article class="post{% if pubkey['deleted'] != 0 %} deleted{% endif %}">
<header> <header>
<div> <div>
<h1> <h1>
<a class="action" href="{{ url_for('pubkeys.certs_index', id=pubkey['id']) }}"> <!--a class="action" href="{{ url_for('pubkeys.certs_index', id=pubkey['id']) }}">
{% if pubkey['revoked'] != 0 %} ({{ pubkey['id'] }}): {{ pubkey['key_name'] }}
<div class="danger">revoked key<div> - </a-->
{% endif %}
({{ pubkey['id'] }}): {{ pubkey['key_name'] }} ({{ pubkey['id'] }}): {{ pubkey['key_name'] }}
</a>
</h1> </h1>
{% if pubkey['revoked'] != 0 %}
<div class="info">this pubkey was revoked manually</div>
{% endif %}
</div> </div>
{% if g.user['id'] == pubkey['user_id'] %} {% if g.user['id'] == pubkey['user_id'] %}
<a class="action" href="{{ url_for('pubkeys.update', id=pubkey['id']) }}">Edit</a> <a class="action" href="{{ url_for('pubkeys.update', id=pubkey['id']) }}">Edit</a>
{% if pubkey['deleted'] == 0 %} {% if pubkey['deleted'] == 0 %}
<a class="action" href="{{ url_for('pubkeys.delete', id=pubkey['id']) }}" onclick="return confirm('Are you sure?');">Delete</a>
<a class="action" href="{{ url_for('pubkeys.deletefinal', id=pubkey['id']) }}" onclick="return confirm('Are you sure?');">Delete final</a>
{% endif %} {% endif %}
{% if pubkey['revoked'] == 0 %} {% if pubkey['revoked'] == 0 %}
<a class="action" href="{{ url_for('pubkeys.revoke', id=pubkey['id']) }}" onclick="return confirm('Are you sure?');">Revoke</a> <form action="{{ url_for('pubkeys.revoke', id=pubkey['id']) }}" method="POST">
<input class="danger" type="submit" value="Revoke cert" onclick="return confirm('Are you sure?');">
</form>
{% else %}
<a class="action" href="{{ url_for('pubkeys.delete', id=pubkey['id']) }}" onclick="return confirm('Are you sure?');">Delete</a>
{% endif %} {% endif %}
{% endif %} {% endif %}
</header> </header>
<div class="body {% if pubkey['revoked'] != 0 %} revoked{% endif %}">
<!--div class="body"-->
{% if user['admin'] == 1 %} {% if user['admin'] == 1 %}
<div name="owner" id="owner">owner: {{ pubkey['username']}}</div> <div name="owner" id="owner">owner: {{ pubkey['username']}}</div>
{% endif %} {% endif %}
<div name="fingerprint" id="fingerprint">fingerprint: {{ pubkey['fingerprint'] }}</div> <div>fingerprint: <div class="key" name="fingerprint" id="fingerprint">{{ pubkey['fingerprint'] }}</div></div>
<br> <div>pubkey: <div class="key" name="ssh_pubkey" id="ssh_pubkey">{{ request.form['ssh_pubkey'] or pubkey['ssh_pubkey'] }}</div></div>
<div class="key" name="ssh_pubkey" id="ssh_pubkey">{{ request.form['ssh_pubkey'] or pubkey['ssh_pubkey'] }}</div> </div>
<p class="about">registered on {{ pubkey['created'].strftime('%Y-%m-%d') }}</p> <p class="about">registered on {{ pubkey['created'].strftime('%Y-%m-%d') }}</p>
</form>
<!--form action="{{ url_for('pubkeys.revoke', id=pubkey['id']) }}" method="POST">
<input class="danger" type="submit" value="Revoke" onclick="return confirm('Are you sure?');">
</form-->
<form action="{{ url_for('pubkeys.certs_index', id=pubkey['id']) }}" method="POST"> <form action="{{ url_for('pubkeys.certs_index', id=pubkey['id']) }}" method="POST">
<input type="submit" value="Certificates"> <input type="submit" value="Certificates">
</form> </form>

View file

@ -5,6 +5,9 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<form action="{{ url_for('pubkeys.deletefinal', id=pubkey['id']) }}" method="post">
<input class="danger" type="submit" value="Delete final" onclick="return confirm('Are you sure?');">
</form>
<form method="post"> <form method="post">
<label for="key_name">SSH-Pubkey ({{ pubkey['id'] }}) {{ pubkey['deleted'] }}</label> <label for="key_name">SSH-Pubkey ({{ pubkey['id'] }}) {{ pubkey['deleted'] }}</label>
<input name="key_name" id="key_name" <input name="key_name" id="key_name"
@ -19,9 +22,4 @@
<input type="submit" value="Save"> <input type="submit" value="Save">
</form> </form>
<hr> <hr>
<ul>
<li><form action="{{ url_for('pubkeys.delete', id=pubkey['id']) }}" method="post">
<input class="danger" type="submit" value="Delete" onclick="return confirm('Are you sure?');">
</form>
</ul>
{% endblock %} {% endblock %}