Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UX: Add a notice to inform users if they have no paper key.
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
assets/javascripts/discourse/connectors/top-notices/encrypt.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{#if showNoBackupWarning}} | ||
<div class="row"> | ||
<div class="alert alert-warn"> | ||
<div class="close" {{action (mut noticeStatus) 'dismissed'}}> | ||
{{d-icon "times"}} | ||
</div> | ||
{{{i18n "encrypt.no_backup_warn"}}} | ||
</div> | ||
</div> | ||
{{/if}} |
69 changes: 69 additions & 0 deletions
69
assets/javascripts/discourse/connectors/top-notices/encrypt.js.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { getOwner } from "discourse-common/lib/get-owner"; | ||
import { | ||
ENCRYPT_ACTIVE, | ||
ENCRYPT_DISABLED, | ||
getEncryptionStatus | ||
} from "discourse/plugins/discourse-encrypt/lib/discourse"; | ||
|
||
const NO_BACKUP_WARN_NOTICE_KEY = "discourse-encrypt-no-backup-warn"; | ||
|
||
export default { | ||
setupComponent(args, component) { | ||
const currentUser = getOwner(component).lookup("current-user:main"); | ||
const status = getEncryptionStatus(currentUser); | ||
|
||
component.setProperties({ | ||
model: args.model, | ||
isEncryptEnabled: status !== ENCRYPT_DISABLED, | ||
isEncryptActive: status === ENCRYPT_ACTIVE, | ||
showNoBackupWarning: 15, | ||
|
||
/** Listens for encryption status updates. */ | ||
listener() { | ||
const newStatus = getEncryptionStatus(currentUser); | ||
component.setProperties({ | ||
isEncryptEnabled: newStatus !== ENCRYPT_DISABLED, | ||
isEncryptActive: newStatus === ENCRYPT_ACTIVE | ||
}); | ||
}, | ||
|
||
didInsertElement() { | ||
this._super(...arguments); | ||
this.appEvents.on("encrypt:status-changed", this, this.listener); | ||
}, | ||
|
||
willDestroyElement() { | ||
this._super(...arguments); | ||
this.appEvents.off("encrypt:status-changed", this, this.listener); | ||
} | ||
}); | ||
|
||
Ember.defineProperty(component, "noticeStatus", { | ||
set(value) { | ||
window.localStorage.setItem(NO_BACKUP_WARN_NOTICE_KEY, value); | ||
return window.localStorage.getItem(NO_BACKUP_WARN_NOTICE_KEY); | ||
}, | ||
get() { | ||
return window.localStorage.getItem(NO_BACKUP_WARN_NOTICE_KEY); | ||
} | ||
}); | ||
|
||
Ember.defineProperty( | ||
component, | ||
"showNoBackupWarning", | ||
Ember.computed( | ||
"isEncryptActive", | ||
"noticeStatus", | ||
"currentUser.custom_fields.encrypt_private", | ||
() => { | ||
const ids = this.get("currentUser.custom_fields.encrypt_private"); | ||
return ( | ||
this.isEncryptActive && | ||
!this.noticeStatus && | ||
(!ids || Object.keys(JSON.parse(ids)).length === 0) | ||
); | ||
} | ||
) | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
340deb3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robin Ward posted:
I like the modern ember code! Nice.