rework upload dialog

This commit is contained in:
Vincent Breitmoser 2019-06-05 13:21:37 +02:00
parent db96a62b49
commit b4509d19d1
No known key found for this signature in database
GPG Key ID: 7BD18320DEADFA11
6 changed files with 102 additions and 61 deletions

View File

@ -1,8 +1,11 @@
{{#> layout }}
<p>
Managing the key <span class="fingerprint"><a href="{{key_link}}" target="_blank">{{key_fpr}}</a></span>.
</p>
{{#if uid_status}}
<p>
Your key <span class="fingerprint"><a href="{{key_link}}" target="_blank">{{key_fpr}}</a></span> is published for the following addresses.
<p style="padding-top: 1em;">
Your key is published with the following identity information:
</p>
{{#each uid_status}}
@ -26,8 +29,9 @@
</p>
{{else}}
<p>
Your key <span class="fingerprint"><a href="{{key_link}}">{{key_fpr}}</a></span> is not published for any addresses.
<p style="padding-top: 1em;">
Your key is published with only technical data, but no identity information
(<a href="/about" target="_blank">what does this mean?</a>)
</p>
<p>

View File

@ -1,9 +1,13 @@
{{#> layout}}
<div class="row">
{{#if verified }}
Key for <span class="email">{{ userid }}</span> published.
<p>
Key for <a href="/pks/lookup?op=get&search={{ userid }}"<span class="email">{{ userid }}</span></a> published.
</p>
{{else}}
Verification failed! You can <a href="/upload">try uploading again</a>.
<p>
Verification failed! You can <a href="/upload">try uploading again</a>.
</p>
{{/if}}
</div>
{{/layout}}

View File

@ -1,53 +1,67 @@
{{#> layout }}
<p>
The key <span class="fingerprint"><a href="{{key_link}}" target="_blank">{{key_fpr}}</a></span> was successfully uploaded.
You uploaded the key <span class="fingerprint"><a href="{{key_link}}" target="_blank">{{key_fpr}}</a></span>.
</p>
{{#if is_revoked}}
<p style="padding-top: 1em;">
This key is now published with technical data, but no identity information (<a href="/about" target="_blank">what does this mean?</a>)
</p>
<p>
This key is revoked. It can not be searched by email address.
This key is revoked, and can't be made available for search by e-mail address.
</p>
{{else}}
{{#if uid_status}}
<p>
To make this key available for search by an e-mail address, you must
verify it belongs to you:
{{#if email_published}}
<p style="padding-top: 1em;">
This key is now published with the following identity information (<a href="/about" target="_blank">what does this mean?</a>):
</p>
{{#each uid_status}}
{{#each email_published}}
<div class="publishedUid">
<div>
{{#if revoked}}
Revoked
{{else}}
{{#if published}}
Published
{{else}}
{{#if requested}}
Verification Pending
{{else}}
<form action="/upload/request-verify" method="post">
<input type="hidden" name="token" value="{{../token}}" />
<input type="hidden" name="address" value="{{address}}" />
<input type="submit" class="link" value="Send Verification Mail">
</form>
{{/if}}
{{/if}}
{{/if}}
</div>
<p>
<span class="email">{{address}}</span>
</p>
<div>Published</div>
<p><span class="email">{{this}}</span></p>
</div>
{{/each}}
<p>
The distributed key will also contain only verified addresses.
</p>
{{else}}
<p>
This key contains no email addresses.
<p style="padding-top: 1em;">
This key is now published with technical data, but no identity information (<a href="/about" target="_blank">what does this mean?</a>)
</p>
{{/if}}
{{#if email_unpublished}}
<p style="padding-top: 1em;">
To make the key available for search by e-mail address, you can verify it belongs to you:
</p>
{{#each email_unpublished}}
<div class="publishedUid">
<div>
{{#if requested}}
Verification Pending
{{else}}
<form action="/upload/request-verify" method="post">
<input type="hidden" name="token" value="{{../token}}" />
<input type="hidden" name="address" value="{{address}}" />
<input type="submit" class="link" value="Send Verification Mail">
</form>
{{/if}}
</div>
<p><span class="email">{{address}}</span></p>
</div>
{{/each}}
{{/if}}
{{#if count_revoked}}
{{#if count_revoked_one}}
<p style="padding-top: 1em;">
This key contains one revoked identity, which is not published.
</p>
{{else}}
<p style="padding-top: 1em;">
This key contains {{count_revoked}} revoked identities, which are not
published.
</p>
{{/if}}
{{/if}}
{{/if}}
{{/layout}}

View File

@ -46,6 +46,7 @@ pub mod response {
Ok {
token: String,
key_fpr: String,
is_revoked: bool,
status: HashMap<String,EmailStatus>,
},
OkMulti { key_fprs: Vec<String> },
@ -258,7 +259,7 @@ fn show_upload_verify(
) -> response::UploadResponse {
let key_fpr = verify_state.fpr.to_string();
if tpk_status.is_revoked {
return response::UploadResponse::Ok { token, key_fpr, status: HashMap::new() };
return response::UploadResponse::Ok { token, key_fpr, is_revoked: true, status: HashMap::new() };
}
let status: HashMap<_,_> = tpk_status.email_status
@ -278,5 +279,5 @@ fn show_upload_verify(
})
.collect();
response::UploadResponse::Ok { token, key_fpr, status }
response::UploadResponse::Ok { token, key_fpr, is_revoked: false, status }
}

View File

@ -62,7 +62,7 @@ fn json_or_error<T>(data: Result<Json<T>, JsonError>) -> Result<Json<T>, JsonErr
fn upload_ok_json(response: UploadResponse) -> Result<JsonValue,JsonErrorResponse> {
match response {
UploadResponse::Ok { token, key_fpr, status } =>
UploadResponse::Ok { token, key_fpr, is_revoked: _, status } =>
Ok(json!(json::UploadResult { token, key_fpr, status })),
UploadResponse::OkMulti { key_fprs } => Ok(json!(key_fprs)),
UploadResponse::Error(error) => Err(JsonErrorResponse(Status::BadRequest, error)),

View File

@ -59,7 +59,10 @@ mod template {
pub key_link: String,
pub is_revoked: bool,
pub token: String,
pub uid_status: Vec<UploadUidStatus>,
pub email_published: Vec<String>,
pub email_unpublished: Vec<UploadUidStatus>,
pub count_revoked_one: bool,
pub count_revoked: usize,
}
#[derive(Serialize)]
@ -79,8 +82,6 @@ mod template {
pub struct UploadUidStatus {
pub address: String,
pub requested: bool,
pub published: bool,
pub revoked: bool,
}
}
@ -88,7 +89,8 @@ mod template {
impl MyResponse {
fn upload_response(response: UploadResponse) -> Self {
match response {
UploadResponse::Ok { token, key_fpr, status } => Self::upload_ok(token, key_fpr, status),
UploadResponse::Ok { token, key_fpr, is_revoked, status } =>
Self::upload_ok(token, key_fpr, is_revoked, status),
UploadResponse::OkMulti { key_fprs } => Self::upload_ok_multi(key_fprs),
UploadResponse::Error(error) => MyResponse::bad_request(
"upload/upload", failure::err_msg(error)),
@ -98,28 +100,44 @@ impl MyResponse {
fn upload_ok(
token: String,
key_fpr: String,
is_revoked: bool,
uid_status: HashMap<String,EmailStatus>,
) -> Self {
let key_link = format!("/pks/lookup?op=get&search={}", &key_fpr);
let mut uid_status: Vec<_> = uid_status
.into_iter()
.map(|(email,status)|
template::UploadUidStatus {
address: email.to_string(),
requested: status == EmailStatus::Pending,
published: status == EmailStatus::Published,
revoked: status == EmailStatus::Revoked,
})
let count_revoked = uid_status.iter()
.filter(|(_,status)| **status == EmailStatus::Revoked)
.count();
let mut email_published: Vec<_> = uid_status.iter()
.filter(|(_,status)| **status == EmailStatus::Published)
.map(|(email,_)| email.to_string())
.collect();
uid_status.sort_by(|fst,snd| {
fst.revoked.cmp(&snd.revoked).then(fst.address.cmp(&snd.address))
});
email_published.sort_unstable();
let mut email_unpublished: Vec<_> = uid_status.into_iter()
.filter(|(_,status)| *status == EmailStatus::Unpublished ||
*status == EmailStatus::Pending)
.map(|(email,status)|
template::UploadUidStatus {
address: email.to_string(),
requested: status == EmailStatus::Pending,
})
.collect();
email_unpublished
.sort_unstable_by(|fst,snd| fst.address.cmp(&snd.address));
let context = template::VerificationSent {
version: env!("VERGEN_SEMVER").to_string(),
commit: env!("VERGEN_SHA_SHORT").to_string(),
is_revoked: false, key_fpr, key_link, token, uid_status,
is_revoked,
key_fpr,
key_link,
token,
email_published,
email_unpublished,
count_revoked_one: count_revoked == 1,
count_revoked,
};
MyResponse::ok("upload/upload-ok", context)
}