Skip to content

Commit

Permalink
UX: Improve key reset mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
udan11 committed Apr 28, 2020
1 parent 07a9657 commit 0e37ded
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export default DropdownSelectBoxComponent.extend({
id: "managePaperKeys",
icon: "ticket-alt",
name: I18n.t("encrypt.manage_paper_keys.title")
},
{
id: "reset",
icon: "trash-alt",
name: I18n.t("encrypt.preferences.reset")
}
]
});
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ export default {
case "managePaperKeys":
showModal("manage-paper-keys", { model: this.model });
break;
case "reset":
showModal("reset-key-pair", { model: this.model });
break;
}
},

Expand Down
42 changes: 31 additions & 11 deletions assets/javascripts/discourse/controllers/reset-key-pair.js.es6
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
import discourseComputed from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { reload } from "discourse/plugins/discourse-encrypt/lib/discourse";
import { deleteDb } from "discourse/plugins/discourse-encrypt/lib/database";
import { Promise } from "rsvp";

export default Ember.Controller.extend(ModalFunctionality, {
onShow() {
this.setProperties({
inProgress: false,
everything: true
everything: true,
confirmation: ""
});
},

@discourseComputed("inProgress", "currentUser.username", "confirmation")
disabled(inProgress, username, confirmation) {
return inProgress || username !== confirmation;
},

actions: {
reset() {
this.set("inProgress", true);
ajax("/encrypt/reset", {
type: "POST",
data: {
user_id: this.get("model.id"),
everything: this.everything
}
})

Promise.all([
ajax("/encrypt/reset", {
type: "POST",
data: {
user_id: this.get("model.id"),
everything: this.everything
}
}),
deleteDb
])
.then(() => {
this.currentUser.setProperties({
encrypt_public: null,
encrypt_private: null
});

this.appEvents.trigger("encrypt:status-changed");
reload();
this.send("closeModal");
})
.catch(popupAjaxError);
.catch(popupAjaxError)
.finally(() => {
this.set("inProgress", false);
});
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
{{i18n "encrypt.reset.everything"}}
</label>
</p>
<p>{{{i18n "encrypt.reset.confirm_instructions" username=currentUser.username}}}</p>
{{input type="text" value=confirmation}}
{{/d-modal-body}}

<div class="modal-footer">
{{d-button class="btn btn-danger" icon="trash-alt" label="encrypt.reset.title" action=(action "reset") disabled=inProgress}}
{{d-button class="btn btn-danger" icon="trash-alt" label="encrypt.reset.title" action=(action "reset") disabled=disabled}}
{{d-modal-cancel close=(action "closeModal")}}
</div>
4 changes: 4 additions & 0 deletions assets/stylesheets/common/encrypt.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
input#passphrase {
width: 100%;
}

.select-kit-row.is-highlighted[data-value="reset"] {
background-color: $danger-low;
}
}

pre.exported-key-pair,
Expand Down
3 changes: 2 additions & 1 deletion config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ en:

reset:
title: "Reset Encryption Key Pair"
instructions: "Are you sure you want to reset the encryption key? This operation deletes the encryption key forever unless it was previously exported."
instructions: "Are you sure you want to reset the encryption key? This operation deletes the encryption key forever and you will not be able to access any encrypted messages unless you previously exported it."
confirm_instructions: "Please type <code>{{username}}</code> to confirm:"
everything: "Uninvite from all encrypted private conversations (if any)"

0 comments on commit 0e37ded

Please sign in to comment.