REFACTOR: preferences/account controller (#7698)
This commit is contained in:
parent
19e3b3b1bc
commit
69f75b2a81
|
@ -2,7 +2,7 @@ import { iconHTML } from "discourse-common/lib/icon-library";
|
||||||
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
||||||
import { default as computed } from "ember-addons/ember-computed-decorators";
|
import { default as computed } from "ember-addons/ember-computed-decorators";
|
||||||
import PreferencesTabController from "discourse/mixins/preferences-tab-controller";
|
import PreferencesTabController from "discourse/mixins/preferences-tab-controller";
|
||||||
import { setting } from "discourse/lib/computed";
|
import { propertyNotEqual, setting } from "discourse/lib/computed";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
import { findAll } from "discourse/models/login-method";
|
import { findAll } from "discourse/models/login-method";
|
||||||
|
@ -40,9 +40,7 @@ export default Ember.Controller.extend(
|
||||||
),
|
),
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.setProperties({
|
this.set("passwordProgress", null);
|
||||||
passwordProgress: null
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
|
@ -54,10 +52,7 @@ export default Ember.Controller.extend(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("model.availableTitles")
|
canSelectTitle: Ember.computed.gt("model.availableTitles.length", 0),
|
||||||
canSelectTitle(availableTitles) {
|
|
||||||
return availableTitles.length > 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed("model.is_anonymous")
|
@computed("model.is_anonymous")
|
||||||
canChangePassword(isAnonymous) {
|
canChangePassword(isAnonymous) {
|
||||||
|
@ -86,15 +81,10 @@ export default Ember.Controller.extend(
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return result.filter(value => {
|
return result.filter(value => value.account || value.method.can_connect);
|
||||||
return value.account || value.method.get("can_connect");
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("model.id")
|
disableConnectButtons: propertyNotEqual("model.id", "currentUser.id"),
|
||||||
disableConnectButtons(userId) {
|
|
||||||
return userId !== this.get("currentUser.id");
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed(
|
@computed(
|
||||||
"model.second_factor_enabled",
|
"model.second_factor_enabled",
|
||||||
|
@ -129,25 +119,23 @@ export default Ember.Controller.extend(
|
||||||
: tokens.slice(0, DEFAULT_AUTH_TOKENS_COUNT);
|
: tokens.slice(0, DEFAULT_AUTH_TOKENS_COUNT);
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("model.user_auth_tokens")
|
canShowAllAuthTokens: Ember.computed.gt(
|
||||||
canShowAllAuthTokens(tokens) {
|
"model.user_auth_tokens.length",
|
||||||
return tokens.length > DEFAULT_AUTH_TOKENS_COUNT;
|
DEFAULT_AUTH_TOKENS_COUNT
|
||||||
},
|
),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
save() {
|
save() {
|
||||||
this.set("saved", false);
|
this.set("saved", false);
|
||||||
|
|
||||||
const model = this.model;
|
this.model.setProperties({
|
||||||
|
name: this.newNameInput,
|
||||||
|
title: this.newTitleInput
|
||||||
|
});
|
||||||
|
|
||||||
model.set("name", this.newNameInput);
|
return this.model
|
||||||
model.set("title", this.newTitleInput);
|
|
||||||
|
|
||||||
return model
|
|
||||||
.save(this.saveAttrNames)
|
.save(this.saveAttrNames)
|
||||||
.then(() => {
|
.then(() => this.set("saved", true))
|
||||||
this.set("saved", true);
|
|
||||||
})
|
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -178,17 +166,14 @@ export default Ember.Controller.extend(
|
||||||
|
|
||||||
delete() {
|
delete() {
|
||||||
this.set("deleting", true);
|
this.set("deleting", true);
|
||||||
const self = this,
|
const message = I18n.t("user.delete_account_confirm"),
|
||||||
message = I18n.t("user.delete_account_confirm"),
|
|
||||||
model = this.model,
|
model = this.model,
|
||||||
buttons = [
|
buttons = [
|
||||||
{
|
{
|
||||||
label: I18n.t("cancel"),
|
label: I18n.t("cancel"),
|
||||||
class: "d-modal-cancel",
|
class: "d-modal-cancel",
|
||||||
link: true,
|
link: true,
|
||||||
callback: () => {
|
callback: () => this.set("deleting", false)
|
||||||
this.set("deleting", false);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label:
|
label:
|
||||||
|
@ -197,14 +182,15 @@ export default Ember.Controller.extend(
|
||||||
class: "btn btn-danger",
|
class: "btn btn-danger",
|
||||||
callback() {
|
callback() {
|
||||||
model.delete().then(
|
model.delete().then(
|
||||||
function() {
|
() => {
|
||||||
bootbox.alert(I18n.t("user.deleted_yourself"), function() {
|
bootbox.alert(
|
||||||
window.location.pathname = Discourse.getURL("/");
|
I18n.t("user.deleted_yourself"),
|
||||||
});
|
() => (window.location.pathname = Discourse.getURL("/"))
|
||||||
|
);
|
||||||
},
|
},
|
||||||
function() {
|
() => {
|
||||||
bootbox.alert(I18n.t("user.delete_yourself_not_allowed"));
|
bootbox.alert(I18n.t("user.delete_yourself_not_allowed"));
|
||||||
self.set("deleting", false);
|
this.set("deleting", false);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -214,25 +200,23 @@ export default Ember.Controller.extend(
|
||||||
},
|
},
|
||||||
|
|
||||||
revokeAccount(account) {
|
revokeAccount(account) {
|
||||||
const model = this.model;
|
|
||||||
this.set("revoking", true);
|
this.set("revoking", true);
|
||||||
model
|
|
||||||
|
this.model
|
||||||
.revokeAssociatedAccount(account.name)
|
.revokeAssociatedAccount(account.name)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
model.get("associated_accounts").removeObject(account);
|
this.model.associated_accounts.removeObject(account);
|
||||||
} else {
|
} else {
|
||||||
bootbox.alert(result.message);
|
bootbox.alert(result.message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError)
|
.catch(popupAjaxError)
|
||||||
.finally(() => {
|
.finally(() => this.set("revoking", false));
|
||||||
this.set("revoking", false);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleShowAllAuthTokens() {
|
toggleShowAllAuthTokens() {
|
||||||
this.set("showAllAuthTokens", !this.showAllAuthTokens);
|
this.toggleProperty("showAllAuthTokens");
|
||||||
},
|
},
|
||||||
|
|
||||||
revokeAuthToken(token) {
|
revokeAuthToken(token) {
|
||||||
|
|
Loading…
Reference in New Issue