Require time bomb (#86)

Require time bomb (#86)

  • Added a setting for requiring time bombs

  • add js tests

  • fix missing semicolon

  • run prettier

  • run prettier on tests; yes I have some commit hooks I need to re-setup

  • Just use spaces for hash keys

diff --git a/assets/javascripts/discourse/connectors/composer-action-after/encrypt.hbs b/assets/javascripts/discourse/connectors/composer-action-after/encrypt.hbs
index 349866b..262b882 100644
--- a/assets/javascripts/discourse/connectors/composer-action-after/encrypt.hbs
+++ b/assets/javascripts/discourse/connectors/composer-action-after/encrypt.hbs
@@ -8,7 +8,7 @@
       {{~#if model.isEncrypted}}
         {{~#unless model.editingPost~}}
           <div class="composer-action-divider"></div>
-          {{~encrypted-post-timer-dropdown topicDeleteAt=this.model.topic.delete_at onChange=(action "timerClicked")}}
+          {{~encrypted-post-timer-dropdown topicDeleteAt=this.model.topic.delete_at disabled=timeBombRequired onChange=(action "timerClicked")}}
           <span title={{ i18n "encrypt.time_bomb.title" after=this.model.deleteAfterMinutesLabel}}>{{this.model.deleteAfterMinutesLabel}}</span>
         {{/unless}}
       {{/if}}
diff --git a/assets/javascripts/discourse/connectors/composer-action-after/encrypt.js.es6 b/assets/javascripts/discourse/connectors/composer-action-after/encrypt.js.es6
index ca7231e..d6484a3 100644
--- a/assets/javascripts/discourse/connectors/composer-action-after/encrypt.js.es6
+++ b/assets/javascripts/discourse/connectors/composer-action-after/encrypt.js.es6
@@ -10,10 +10,21 @@ export default {
   setupComponent(args, component) {
     const currentUser = getOwner(component).lookup("current-user:main");
     const status = getEncryptionStatus(currentUser);
+    const timerOptions = {
+      "3 minutes": "3",
+      "1 hour": "60",
+      "3 hours": "180",
+      "12 hours": "720",
+      "24 hours": "1440",
+      "3 days": "4320",
+      "7 days": "10080",
+    };
 
     component.setProperties({
       isEncryptEnabled: status !== ENCRYPT_DISABLED,
       isEncryptActive: status === ENCRYPT_ACTIVE,
+      timeBombRequired: this.siteSettings.require_time_bombs,
+      timeBombLength: this.siteSettings.required_time_bomb_length.replace,
 
       /** Listens for encryption status updates. */
       listener() {
@@ -27,6 +38,16 @@ export default {
       didInsertElement() {
         this._super(...arguments);
         this.appEvents.on("encrypt:status-changed", this, this.listener);
+        if (this.timeBombRequired) {
+          this.model.setProperties({
+            deleteAfterMinutes: this.timeBombRequired
+              ? timerOptions[this.timeBombLength]
+              : null,
+            deleteAfterMinutesLabel: this.timeBombRequired
+              ? I18n.t("encrypt.time_bomb." + this.timeBombLength)
+              : null,
+          });
+        }
       },
 
       willDestroyElement() {
@@ -40,8 +61,12 @@ export default {
             isEncrypted: !this.model.isEncrypted,
             isEncryptedChanged: true,
             showEncryptError: !this.model.isEncrypted,
-            deleteAfterMinutes: null,
-            deleteAfterMinutesLabel: null,
+            deleteAfterMinutes: this.timeBombRequired
+              ? timerOptions[this.timeBombLength]
+              : null,
+            deleteAfterMinutesLabel: this.timeBombRequired
+              ? I18n.t("encrypt.time_bomb." + this.timeBombLength)
+              : null,
           });
         } else {
           this.model.set("showEncryptError", !this.model.showEncryptError);
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index a752a5e..671fe70 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -9,3 +9,5 @@ en:
     auto_enable_encrypt: "Automatically enable encrypt for all logged in users"
     encrypt_groups: "The name of groups that are able to use encryption (empty means everyone)."
     encrypt_pms_default: "Encrypt all new private messages by default"
+    require_time_bombs: "Require that all encrypted PMs are automatically destroyed"
+    required_time_bomb_length: "The length of time encrypted PMs will live if required_time_bombs is enabled"
\ No newline at end of file
diff --git a/config/settings.yml b/config/settings.yml
index 4ed300a..8872573 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -15,3 +15,18 @@ plugins:
   encrypt_pms_default:
     client: true
     default: true
+  require_time_bombs:
+    client: true
+    default: true
+  required_time_bomb_length:
+    client: true
+    default: "3 minutes"
+    type: enum
+    choices:
+      - "3 minutes"
+      - "1 hour"
+      - "3 hours"
+      - "12 hours"
+      - "24 hours"
+      - "3 days"
+      - "7 days"
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..58a8570
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,4558 @@
+{
+  "name": "discourse-encrypt",
+  "version": "1.0.0",
+  "lockfileVersion": 2,
+  "requires": true,
+  "packages": {
+    "": {
+      "version": "1.0.0",
+      "license": "MIT",
+      "devDependencies": {
+        "eslint-config-discourse": "^1.1.8",
+        "prettier": "2.2.1"
+      }
+    },
+    "node_modules/@babel/code-frame": {
+      "version": "7.10.4",
+      "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz",
+      "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==",
+      "dev": true,
+      "license": "MIT",
+      "dependencies": {
+        "@babel/highlight": "^7.10.4"
+      }
+    },
+    "node_modules/@babel/generator": {
+      "version": "7.11.6",
+      "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.11.6.tgz",
+      "integrity": "sha512-DWtQ1PV3r+cLbySoHrwn9RWEgKMBLLma4OBQloPRyDYvc5msJM9kvTLo1YnlJd1P/ZuKbdli3ijr5q3FvAF3uA==",
+      "dev": true,
+      "license": "MIT",
+      "dependencies": {
+        "@babel/types": "^7.11.5",
+        "jsesc": "^2.5.1",
+        "source-map": "^0.5.0"
+      }
+    },
+    "node_modules/@babel/helper-function-name": {
+      "version": "7.10.4",
+      "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.10.4.tgz",
+      "integrity": "sha512-YdaSyz1n8gY44EmN7x44zBn9zQ1Ry2Y+3GTA+3vH6Mizke1Vw0aWDM66FOYEPw8//qKkmqOckrGgTYa+6sceqQ==",
+      "dev": true,
+      "license": "MIT",
+      "dependencies": {
+        "@babel/helper-get-function-arity": "^7.10.4",
+        "@babel/template": "^7.10.4",
+        "@babel/types": "^7.10.4"
+      }
+    },
+    "node_modules/@babel/helper-get-function-arity": {
+      "version": "7.10.4",
+      "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.10.4.tgz",
+      "integrity": "sha512-EkN3YDB+SRDgiIUnNgcmiD361ti+AVbL3f3Henf6dqqUyr5dMsorno0lJWJuLhDhkI5sYEpgj6y9kB8AOU1I2A==",
+      "dev": true,
+      "license": "MIT",
+      "dependencies": {
+        "@babel/types": "^7.10.4"
+      }
+    },
+    "node_modules/@babel/helper-split-export-declaration": {
+      "version": "7.11.0",
+      "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.11.0.tgz",
+      "integrity": "sha512-74Vejvp6mHkGE+m+k5vHY93FX2cAtrw1zXrZXRlG4l410Nm9PxfEiVTn1PjDPV5SnmieiueY4AFg2xqhNFuuZg==",
+      "dev": true,
+      "license": "MIT",
+      "dependencies": {
+        "@babel/types": "^7.11.0"
+      }
+    },
+    "node_modules/@babel/helper-validator-identifier": {
+      "version": "7.10.4",
+      "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz",
+      "integrity": "sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==",
+      "dev": true,
+      "license": "MIT"
+    },
+    "node_modules/@babel/highlight": {
+      "version": "7.10.4",
+      "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz",
+      "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==",
+      "dev": true,
+      "license": "MIT",

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

GitHub sha: cae5923a

This commit appears in #86 which was approved by eviltrout. It was merged by blake.