FEATURE: Allow staff members to reset encryption keys.

approved
#1

FEATURE: Allow staff members to reset encryption keys.

diff --git a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.hbs b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.hbs
index ea7326f..576b1c1 100644
--- a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.hbs
+++ b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.hbs
@@ -40,7 +40,12 @@
                 <label for="password">{{i18n "encrypt.preferences.passphrase_label"}}</label>
                 {{input type="password" value=passphrase id="passphrase" autocomplete="current-password" disabled=inProgress}}
               </p>
-              <p>{{d-button class="btn-primary" icon="unlock" action=(action "activateEncrypt") disabled=inProgress label="encrypt.preferences.activate"}}</p>
+              <p>
+                {{d-button class="btn-primary" icon="unlock" action=(action "activateEncrypt") disabled=inProgress label="encrypt.preferences.activate"}}
+                {{#if model.staff}}
+                  <span><a {{action "reset"}} class="text-danger">{{i18n 'encrypt.preferences.reset'}}</a></span>
+                {{/if}}
+              </p>
             </form>
           {{/if}}
         {{else}}
@@ -61,8 +66,8 @@
               {{/if}}
               <p>
                 <label>
-                {{input type="checkbox" checked=importKey}}
-                {{i18n "encrypt.preferences.import_key"}}
+                  {{input type="checkbox" checked=importKey}}
+                  {{i18n "encrypt.preferences.import_key"}}
                 </label>
               </p>
               {{#if importKey}}
@@ -81,6 +86,7 @@
       {{else}}
         {{#if isEncryptEnabled}}
           <p>{{i18n 'encrypt.preferences.status_enabled_other'}}</p>
+          <p><a {{action "reset"}} class="text-danger">{{i18n 'encrypt.preferences.reset'}}</a></p>
         {{else}}
           <p>{{i18n 'encrypt.preferences.status_disabled_other'}}</p>
         {{/if}}
diff --git a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6 b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
index 4e87966..b206dc5 100644
--- a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
+++ b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
@@ -314,7 +314,11 @@ export default {
     },
 
     export() {
-      showModal("export-keypair");
+      showModal("export-keypair").set("model", this.get("model"));
+    },
+
+    reset() {
+      showModal("reset-keypair").set("model", this.get("model"));
     }
   }
 };
diff --git a/assets/javascripts/discourse/controllers/export-keypair.js.es6 b/assets/javascripts/discourse/controllers/export-keypair.js.es6
index 6b11c63..da5478e 100644
--- a/assets/javascripts/discourse/controllers/export-keypair.js.es6
+++ b/assets/javascripts/discourse/controllers/export-keypair.js.es6
@@ -17,6 +17,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
     this.setProperties({
       passphrase: "",
       exported: "",
+      inProgress: false,
       error: ""
     });
   },
@@ -43,7 +44,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
     export() {
       this.set("inProgress", true);
 
-      const user = Discourse.User.current();
+      const user = this.get("model");
       const publicStr = user.get("custom_fields.encrypt_public_key");
       const privateStr = user.get("custom_fields.encrypt_private_key");
       const salt = user.get("custom_fields.encrypt_salt");
diff --git a/assets/javascripts/discourse/controllers/reset-keypair.js.es6 b/assets/javascripts/discourse/controllers/reset-keypair.js.es6
new file mode 100644
index 0000000..a872cf5
--- /dev/null
+++ b/assets/javascripts/discourse/controllers/reset-keypair.js.es6
@@ -0,0 +1,28 @@
+import ModalFunctionality from "discourse/mixins/modal-functionality";
+import { ajax } from "discourse/lib/ajax";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { reload } from "discourse/plugins/discourse-encrypt/lib/discourse";
+
+export default Ember.Controller.extend(ModalFunctionality, {
+  onShow() {
+    this.setProperties({
+      inProgress: false,
+      everything: true
+    });
+  },
+
+  actions: {
+    reset() {
+      this.set("inProgress", true);
+      ajax("/encrypt/reset", {
+        type: "POST",
+        data: {
+          user_id: this.get("model.id"),
+          everything: this.get("everything")
+        }
+      })
+        .then(reload)
+        .catch(popupAjaxError);
+    }
+  }
+});
diff --git a/assets/javascripts/discourse/templates/modal/export-keypair.hbs b/assets/javascripts/discourse/templates/modal/export-keypair.hbs
index b30135b..70dcc54 100644
--- a/assets/javascripts/discourse/templates/modal/export-keypair.hbs
+++ b/assets/javascripts/discourse/templates/modal/export-keypair.hbs
@@ -14,13 +14,10 @@
 {{/d-modal-body}}
 
 <div class="modal-footer">
-  {{d-button class="btn btn-primary" icon="file-export" label="encrypt.export.title" action=(action "export")}}
   {{#if exported}}
-    {{#if copied}}
-      {{d-button class="btn" icon="clipboard" label="admin.customize.copied_to_clipboard" action=(action "copy")}}
-    {{else}}
-      {{d-button class="btn" icon="clipboard" label="admin.customize.copy_to_clipboard" action=(action "copy")}}
-    {{/if}}
+    {{d-button class="btn btn-primary" icon="clipboard" label=(if copied "admin.customize.copied_to_clipboard" "admin.customize.copy_to_clipboard") action=(action "copy")}}
+  {{else}}
+    {{d-button class="btn btn-primary" icon="file-export" label="encrypt.export.title" action=(action "export") disabled=inProgress}}
   {{/if}}
   {{d-modal-cancel close=(action "closeModal")}}
 </div>
diff --git a/assets/javascripts/discourse/templates/modal/reset-keypair.hbs b/assets/javascripts/discourse/templates/modal/reset-keypair.hbs
new file mode 100644
index 0000000..efd244a
--- /dev/null
+++ b/assets/javascripts/discourse/templates/modal/reset-keypair.hbs
@@ -0,0 +1,14 @@
+{{#d-modal-body title="encrypt.reset.title"}}
+  <p>{{i18n "encrypt.reset.instructions"}}</p>
+  <p>
+    <label>
+      {{input type="checkbox" checked=everything disabled=inProgress}}
+      {{i18n "encrypt.reset.everything"}}
+    </label>
+  </p>
+{{/d-modal-body}}
+
+<div class="modal-footer">
+  {{d-button class="btn btn-danger" icon="trash" label="encrypt.reset.title" action=(action "reset") disabled=inProgress}}
+  {{d-modal-cancel close=(action "closeModal")}}
+</div>
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index b521be0..612bd2f 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -48,10 +48,16 @@ en:
           <p>Please paste the encryption key you previously you previously exported.</p>
 
         activate: "Activate Encrypted Messages"
-        deactivate: "Deactive Encryption on this Device"
+        deactivate: "Deactivate Encryption on this Device"
         enable: "Enable Encrypted Messages"
         change: "Change Passphrase"
+        reset: "Reset Encryption Key"
 
       export:
         title: "Export Encryption Keypair"
         instructions: "You may export your keypair for safe keeping in case you forget your passphrase. Please note that the exported keypair is unprotected."
+
+      reset:
+        title: "Reset Encryption Keypair"
+        instructions: "Are you sure you want to reset your encryption key? This operation deletes the encryption key forever unless it was previously exported."
+        everything: "Uninvite user from any private conversations and delete topic keys."
diff --git a/plugin.rb b/plugin.rb
index 9408d9a..3dcfbf1 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -7,17 +7,16 @@
 enabled_site_setting :encrypt_enabled
 
 # Register custom stylesheet.
-register_asset "stylesheets/common/encrypt.scss"
-[ "clipboard", "exchange", "file-export", "lock", "times", "unlock" ].each { |i| register_svg_icon i }
+register_asset 'stylesheets/common/encrypt.scss'

[... diff too long, it was truncated ...]

GitHub sha: f0f42561

1 Like
Approved #2