mirror of
https://github.com/discourse/discourse.git
synced 2025-04-01 11:16:42 +08:00
DEV: Update replaceWith
on Route (#23153)
# Context This PR was originally implemented in https://github.com/discourse/discourse/pull/22645 then reverted in https://github.com/discourse/discourse/pull/22693. We protect from aborted transition when _awaiting_ on `replaceWith` by utilizing [followRedirects()](https://api.emberjs.com/ember/5.1/classes/Transition/methods/followRedirects?anchor=followRedirects) # Description Per https://deprecations.emberjs.com/v3.x/#toc_routing-transition-methods We are upgrading all `this.replaceWith` calls on routes to directly call the router service (`this.router.replaceWith`)
This commit is contained in:
parent
3bb2f3a604
commit
3eb8046dde
@ -1,10 +1,17 @@
|
|||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class AdminCustomizeColorsShowRoute extends Route {
|
export default class AdminCustomizeColorsShowRoute extends Route {
|
||||||
|
@service router;
|
||||||
|
|
||||||
model(params) {
|
model(params) {
|
||||||
const all = this.modelFor("adminCustomize.colors");
|
const all = this.modelFor("adminCustomize.colors");
|
||||||
const model = all.findBy("id", parseInt(params.scheme_id, 10));
|
const model = all.findBy("id", parseInt(params.scheme_id, 10));
|
||||||
return model ? model : this.replaceWith("adminCustomize.colors.index");
|
if (model) {
|
||||||
|
return model;
|
||||||
|
} else {
|
||||||
|
this.router.replaceWith("adminCustomize.colors.index");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize(model) {
|
serialize(model) {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class AdminCustomizeEmailStyleIndexRoute extends Route {
|
export default class AdminCustomizeEmailStyleIndexRoute extends Route {
|
||||||
|
@service router;
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
this.replaceWith("adminCustomizeEmailStyle.edit", "html");
|
this.router.replaceWith("adminCustomizeEmailStyle.edit", "html");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,15 @@ export default class AdminCustomizeThemesEditRoute extends Route {
|
|||||||
model(params) {
|
model(params) {
|
||||||
const all = this.modelFor("adminCustomizeThemes");
|
const all = this.modelFor("adminCustomizeThemes");
|
||||||
const model = all.findBy("id", parseInt(params.theme_id, 10));
|
const model = all.findBy("id", parseInt(params.theme_id, 10));
|
||||||
return model
|
if (model) {
|
||||||
? {
|
return {
|
||||||
model,
|
model,
|
||||||
target: params.target,
|
target: params.target,
|
||||||
field_name: params.field_name,
|
field_name: params.field_name,
|
||||||
}
|
};
|
||||||
: this.replaceWith("adminCustomizeThemes.index");
|
} else {
|
||||||
|
this.router.replaceWith("adminCustomizeThemes.index");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize(wrapper) {
|
serialize(wrapper) {
|
||||||
|
@ -7,6 +7,7 @@ import { scrollTop } from "discourse/mixins/scroll-top";
|
|||||||
|
|
||||||
export default class AdminCustomizeThemesShowRoute extends Route {
|
export default class AdminCustomizeThemesShowRoute extends Route {
|
||||||
@service dialog;
|
@service dialog;
|
||||||
|
@service router;
|
||||||
|
|
||||||
serialize(model) {
|
serialize(model) {
|
||||||
return { theme_id: model.get("id") };
|
return { theme_id: model.get("id") };
|
||||||
@ -15,7 +16,11 @@ export default class AdminCustomizeThemesShowRoute extends Route {
|
|||||||
model(params) {
|
model(params) {
|
||||||
const all = this.modelFor("adminCustomizeThemes");
|
const all = this.modelFor("adminCustomizeThemes");
|
||||||
const model = all.findBy("id", parseInt(params.theme_id, 10));
|
const model = all.findBy("id", parseInt(params.theme_id, 10));
|
||||||
return model ? model : this.replaceWith("adminCustomizeThemes.index");
|
if (model) {
|
||||||
|
return model;
|
||||||
|
} else {
|
||||||
|
this.router.replaceWith("adminCustomizeThemes.index");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
|
@ -3,10 +3,13 @@
|
|||||||
chosen a category. It will redirect to the first category.
|
chosen a category. It will redirect to the first category.
|
||||||
**/
|
**/
|
||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class AdminSiteSettingsIndexRoute extends DiscourseRoute {
|
export default class AdminSiteSettingsIndexRoute extends DiscourseRoute {
|
||||||
|
@service router;
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
this.replaceWith(
|
this.router.replaceWith(
|
||||||
"adminSiteSettingsCategory",
|
"adminSiteSettingsCategory",
|
||||||
this.controllerFor("adminSiteSettings").get("visibleSiteSettings")[0]
|
this.controllerFor("adminSiteSettings").get("visibleSiteSettings")[0]
|
||||||
.nameKey
|
.nameKey
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class AdminWatchedWordsIndexRoute extends DiscourseRoute {
|
export default class AdminWatchedWordsIndexRoute extends DiscourseRoute {
|
||||||
|
@service router;
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
this.replaceWith(
|
this.router.replaceWith(
|
||||||
"adminWatchedWords.action",
|
"adminWatchedWords.action",
|
||||||
this.modelFor("adminWatchedWords")[0].nameKey
|
this.modelFor("adminWatchedWords")[0].nameKey
|
||||||
);
|
);
|
||||||
|
@ -1,23 +1,42 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { next } from "@ember/runloop";
|
|
||||||
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 cookie from "discourse/lib/cookie";
|
import cookie from "discourse/lib/cookie";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
import { next } from "@ember/runloop";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
currentUser: service(),
|
||||||
|
|
||||||
beforeModel(transition) {
|
beforeModel(transition) {
|
||||||
if (!this.currentUser) {
|
if (!this.currentUser) {
|
||||||
cookie("destination_url", transition.intent.url);
|
cookie("destination_url", transition.intent.url);
|
||||||
return this.replaceWith("login");
|
return this.router.replaceWith("login");
|
||||||
}
|
}
|
||||||
const params = this.paramsFor("associate-account");
|
const params = this.paramsFor("associate-account");
|
||||||
this.replaceWith(`preferences.account`, this.currentUser).then(() =>
|
this.redirectToAccount(params);
|
||||||
next(() =>
|
},
|
||||||
ajax(`/associate/${encodeURIComponent(params.token)}.json`)
|
|
||||||
.then((model) => showModal("associate-account-confirm", { model }))
|
@action
|
||||||
.catch(popupAjaxError)
|
async redirectToAccount(params) {
|
||||||
)
|
await this.router
|
||||||
);
|
.replaceWith(`preferences.account`, this.currentUser)
|
||||||
|
.followRedirects();
|
||||||
|
next(() => this.showAssociateAccount(params));
|
||||||
|
},
|
||||||
|
|
||||||
|
@action
|
||||||
|
async showAssociateAccount(params) {
|
||||||
|
try {
|
||||||
|
const model = await ajax(
|
||||||
|
`/associate/${encodeURIComponent(params.token)}.json`
|
||||||
|
);
|
||||||
|
showModal("associate-account-confirm", { model });
|
||||||
|
} catch {
|
||||||
|
popupAjaxError;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -20,6 +20,7 @@ import PreloadStore from "discourse/lib/preload-store";
|
|||||||
|
|
||||||
class AbstractCategoryRoute extends DiscourseRoute {
|
class AbstractCategoryRoute extends DiscourseRoute {
|
||||||
@service composer;
|
@service composer;
|
||||||
|
@service router;
|
||||||
|
|
||||||
queryParams = queryParams;
|
queryParams = queryParams;
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ class AbstractCategoryRoute extends DiscourseRoute {
|
|||||||
|
|
||||||
afterModel(model, transition) {
|
afterModel(model, transition) {
|
||||||
if (!model) {
|
if (!model) {
|
||||||
this.replaceWith("/404");
|
this.router.replaceWith("/404");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +64,11 @@ class AbstractCategoryRoute extends DiscourseRoute {
|
|||||||
) {
|
) {
|
||||||
// TODO: avoid throwing away preload data by redirecting on the server
|
// TODO: avoid throwing away preload data by redirecting on the server
|
||||||
PreloadStore.getAndRemove("topic_list");
|
PreloadStore.getAndRemove("topic_list");
|
||||||
return this.replaceWith(
|
this.router.replaceWith(
|
||||||
"discovery.categoryNone",
|
"discovery.categoryNone",
|
||||||
modelParams.category_slug_path_with_id
|
modelParams.category_slug_path_with_id
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setupNavigation(category);
|
this._setupNavigation(category);
|
||||||
|
@ -3,8 +3,11 @@ import { once } from "@ember/runloop";
|
|||||||
import { seenUser } from "discourse/lib/user-presence";
|
import { seenUser } from "discourse/lib/user-presence";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "discourse-common/lib/get-owner";
|
||||||
import deprecated from "discourse-common/lib/deprecated";
|
import deprecated from "discourse-common/lib/deprecated";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
const DiscourseRoute = Route.extend({
|
const DiscourseRoute = Route.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
willTransition() {
|
willTransition() {
|
||||||
seenUser();
|
seenUser();
|
||||||
},
|
},
|
||||||
@ -39,7 +42,7 @@ const DiscourseRoute = Route.extend({
|
|||||||
redirectIfLoginRequired() {
|
redirectIfLoginRequired() {
|
||||||
const app = this.controllerFor("application");
|
const app = this.controllerFor("application");
|
||||||
if (app.get("loginRequired")) {
|
if (app.get("loginRequired")) {
|
||||||
this.replaceWith("login");
|
this.router.replaceWith("login");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -3,12 +3,15 @@ import User from "discourse/models/user";
|
|||||||
import { setTopicList } from "discourse/lib/topic-list-tracker";
|
import { setTopicList } from "discourse/lib/topic-list-tracker";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { resetCachedTopicList } from "discourse/lib/cached-topic-list";
|
import { resetCachedTopicList } from "discourse/lib/cached-topic-list";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The parent route for all discovery routes.
|
The parent route for all discovery routes.
|
||||||
Handles the logic for showing the loading spinners.
|
Handles the logic for showing the loading spinners.
|
||||||
**/
|
**/
|
||||||
export default class DiscoveryRoute extends DiscourseRoute {
|
export default class DiscoveryRoute extends DiscourseRoute {
|
||||||
|
@service router;
|
||||||
|
|
||||||
queryParams = {
|
queryParams = {
|
||||||
filter: { refreshModel: true },
|
filter: { refreshModel: true },
|
||||||
};
|
};
|
||||||
@ -28,14 +31,14 @@ export default class DiscoveryRoute extends DiscourseRoute {
|
|||||||
User.currentProp("user_option.should_be_redirected_to_top", false);
|
User.currentProp("user_option.should_be_redirected_to_top", false);
|
||||||
const period =
|
const period =
|
||||||
User.currentProp("user_option.redirected_to_top.period") || "all";
|
User.currentProp("user_option.redirected_to_top.period") || "all";
|
||||||
this.replaceWith("discovery.top", {
|
this.router.replaceWith("discovery.top", {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
period,
|
period,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (url && (matches = url.match(/top\/(.*)$/))) {
|
} else if (url && (matches = url.match(/top\/(.*)$/))) {
|
||||||
if (this.site.periods.includes(matches[1])) {
|
if (this.site.periods.includes(matches[1])) {
|
||||||
this.replaceWith("discovery.top", {
|
this.router.replaceWith("discovery.top", {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
period: matches[1],
|
period: matches[1],
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
afterModel() {
|
afterModel() {
|
||||||
const params = this.paramsFor("editCategory");
|
const params = this.paramsFor("editCategory");
|
||||||
this.replaceWith(`/c/${params.slug}/edit/general`);
|
this.router.replaceWith(`/c/${params.slug}/edit/general`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
model(params) {
|
model(params) {
|
||||||
return Category.reloadCategoryWithPermissions(
|
return Category.reloadCategoryWithPermissions(
|
||||||
params,
|
params,
|
||||||
@ -13,7 +16,7 @@ export default DiscourseRoute.extend({
|
|||||||
|
|
||||||
afterModel(model) {
|
afterModel(model) {
|
||||||
if (!model.can_edit) {
|
if (!model.can_edit) {
|
||||||
this.replaceWith("/404");
|
this.router.replaceWith("/404");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -6,14 +6,14 @@ import ForgotPassword from "discourse/components/modal/forgot-password";
|
|||||||
|
|
||||||
export default class ForgotPasswordRoute extends DiscourseRoute {
|
export default class ForgotPasswordRoute extends DiscourseRoute {
|
||||||
@service modal;
|
@service modal;
|
||||||
|
@service router;
|
||||||
|
|
||||||
async beforeModel() {
|
async beforeModel() {
|
||||||
const { loginRequired } = this.controllerFor("application");
|
const { loginRequired } = this.controllerFor("application");
|
||||||
|
|
||||||
await this.replaceWith(
|
await this.router.replaceWith(
|
||||||
loginRequired ? "login" : `discovery.${defaultHomepage()}`
|
loginRequired ? "login" : `discovery.${defaultHomepage()}`
|
||||||
);
|
);
|
||||||
|
|
||||||
next(() => this.modal.show(ForgotPassword));
|
next(() => this.modal.show(ForgotPassword));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
titleToken() {
|
titleToken() {
|
||||||
return I18n.t("groups.manage.membership.title");
|
return I18n.t("groups.manage.membership.title");
|
||||||
},
|
},
|
||||||
|
|
||||||
afterModel(group) {
|
afterModel(group) {
|
||||||
if (group.get("automatic")) {
|
if (group.get("automatic")) {
|
||||||
this.replaceWith("group.manage.interaction", group);
|
this.router.replaceWith("group.manage.interaction", group);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,7 @@ import StaticPage from "discourse/models/static-page";
|
|||||||
|
|
||||||
export default class LoginRoute extends DiscourseRoute {
|
export default class LoginRoute extends DiscourseRoute {
|
||||||
@service siteSettings;
|
@service siteSettings;
|
||||||
|
@service router;
|
||||||
|
|
||||||
// `login-page` because `login` controller is the one for
|
// `login-page` because `login` controller is the one for
|
||||||
// the login modal
|
// the login modal
|
||||||
@ -13,9 +14,10 @@ export default class LoginRoute extends DiscourseRoute {
|
|||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
if (!this.siteSettings.login_required) {
|
if (!this.siteSettings.login_required) {
|
||||||
this.replaceWith(`/${defaultHomepage()}`).then((e) => {
|
this.router
|
||||||
next(() => e.send("showLogin"));
|
.replaceWith(`/${defaultHomepage()}`)
|
||||||
});
|
.followRedirects()
|
||||||
|
.then((e) => next(() => e.send("showLogin")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import DiscourseRoute from "discourse/routes/discourse";
|
|||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import { SEARCH_PRIORITIES } from "discourse/lib/constants";
|
import { SEARCH_PRIORITIES } from "discourse/lib/constants";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
let _newCategoryColor = "0088CC";
|
let _newCategoryColor = "0088CC";
|
||||||
let _newCategoryTextColor = "FFFFFF";
|
let _newCategoryTextColor = "FFFFFF";
|
||||||
@ -12,12 +13,14 @@ export function setNewCategoryDefaultColors(backgroundColor, textColor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
controllerName: "edit-category-tabs",
|
controllerName: "edit-category-tabs",
|
||||||
templateName: "edit-category-tabs",
|
templateName: "edit-category-tabs",
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
if (!this.currentUser) {
|
if (!this.currentUser) {
|
||||||
this.replaceWith("/404");
|
this.router.replaceWith("/404");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.currentUser.admin) {
|
if (!this.currentUser.admin) {
|
||||||
@ -25,7 +28,7 @@ export default DiscourseRoute.extend({
|
|||||||
!this.currentUser.moderator ||
|
!this.currentUser.moderator ||
|
||||||
this.siteSettings.moderators_manage_categories_and_groups === false
|
this.siteSettings.moderators_manage_categories_and_groups === false
|
||||||
) {
|
) {
|
||||||
this.replaceWith("/404");
|
this.router.replaceWith("/404");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -8,6 +8,7 @@ import { inject as service } from "@ember/service";
|
|||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
dialog: service(),
|
dialog: service(),
|
||||||
composer: service(),
|
composer: service(),
|
||||||
|
router: service(),
|
||||||
|
|
||||||
beforeModel(transition) {
|
beforeModel(transition) {
|
||||||
const params = transition.to.queryParams;
|
const params = transition.to.queryParams;
|
||||||
@ -15,42 +16,45 @@ export default DiscourseRoute.extend({
|
|||||||
const groupName = params.groupname || params.group_name;
|
const groupName = params.groupname || params.group_name;
|
||||||
|
|
||||||
if (this.currentUser) {
|
if (this.currentUser) {
|
||||||
this.replaceWith("discovery.latest").then(() => {
|
this.router
|
||||||
if (params.username) {
|
.replaceWith("discovery.latest")
|
||||||
this.composer.openNewMessage({
|
.followRedirects()
|
||||||
recipients: params.username,
|
.then(() => {
|
||||||
title: params.title,
|
if (params.username) {
|
||||||
body: params.body,
|
this.composer.openNewMessage({
|
||||||
});
|
recipients: params.username,
|
||||||
} else if (groupName) {
|
title: params.title,
|
||||||
// send a message to a group
|
body: params.body,
|
||||||
Group.messageable(groupName)
|
});
|
||||||
.then((result) => {
|
} else if (groupName) {
|
||||||
if (result.messageable) {
|
// send a message to a group
|
||||||
next(() =>
|
Group.messageable(groupName)
|
||||||
this.composer.openNewMessage({
|
.then((result) => {
|
||||||
recipients: groupName,
|
if (result.messageable) {
|
||||||
title: params.title,
|
next(() =>
|
||||||
body: params.body,
|
this.composer.openNewMessage({
|
||||||
})
|
recipients: groupName,
|
||||||
);
|
title: params.title,
|
||||||
} else {
|
body: params.body,
|
||||||
this.dialog.alert(
|
})
|
||||||
I18n.t("composer.cant_send_pm", { username: groupName })
|
);
|
||||||
);
|
} else {
|
||||||
}
|
this.dialog.alert(
|
||||||
})
|
I18n.t("composer.cant_send_pm", { username: groupName })
|
||||||
.catch(() => this.dialog.alert(I18n.t("generic_error")));
|
);
|
||||||
} else {
|
}
|
||||||
this.composer.openNewMessage({
|
})
|
||||||
title: params.title,
|
.catch(() => this.dialog.alert(I18n.t("generic_error")));
|
||||||
body: params.body,
|
} else {
|
||||||
});
|
this.composer.openNewMessage({
|
||||||
}
|
title: params.title,
|
||||||
});
|
body: params.body,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
cookie("destination_url", window.location.href);
|
cookie("destination_url", window.location.href);
|
||||||
this.replaceWith("login");
|
this.router.replaceWith("login");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -6,35 +6,43 @@ import { inject as service } from "@ember/service";
|
|||||||
|
|
||||||
export default class extends DiscourseRoute {
|
export default class extends DiscourseRoute {
|
||||||
@service composer;
|
@service composer;
|
||||||
|
@service router;
|
||||||
|
@service currentUser;
|
||||||
|
@service site;
|
||||||
|
|
||||||
beforeModel(transition) {
|
beforeModel(transition) {
|
||||||
if (this.currentUser) {
|
if (this.currentUser) {
|
||||||
const category = this.parseCategoryFromTransition(transition);
|
const category = this.parseCategoryFromTransition(transition);
|
||||||
|
|
||||||
if (category) {
|
if (category) {
|
||||||
this.replaceWith("discovery.category", {
|
// Using URL-based transition to avoid bug with dynamic segments and refreshModel query params
|
||||||
category,
|
// https://github.com/emberjs/ember.js/issues/16992
|
||||||
id: category.id,
|
this.router
|
||||||
}).then(() => {
|
.replaceWith(`/c/${category.id}`)
|
||||||
if (this.currentUser.can_create_topic) {
|
.followRedirects()
|
||||||
this.openComposer({ transition, category });
|
.then(() => {
|
||||||
}
|
if (this.currentUser.can_create_topic) {
|
||||||
});
|
this.openComposer({ transition, category });
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (transition.from) {
|
} else if (transition.from) {
|
||||||
// Navigation from another ember route
|
// Navigation from another ember route
|
||||||
transition.abort();
|
transition.abort();
|
||||||
this.openComposer({ transition });
|
this.openComposer({ transition });
|
||||||
} else {
|
} else {
|
||||||
this.replaceWith("discovery.latest").then(() => {
|
this.router
|
||||||
if (this.currentUser.can_create_topic) {
|
.replaceWith("discovery.latest")
|
||||||
this.openComposer({ transition });
|
.followRedirects()
|
||||||
}
|
.then(() => {
|
||||||
});
|
if (this.currentUser.can_create_topic) {
|
||||||
|
this.openComposer({ transition });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// User is not logged in
|
// User is not logged in
|
||||||
cookie("destination_url", window.location.href);
|
cookie("destination_url", window.location.href);
|
||||||
this.replaceWith("login");
|
this.router.replaceWith("login");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
// A base route that allows us to redirect when access is restricted
|
// A base route that allows us to redirect when access is restricted
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
afterModel() {
|
afterModel() {
|
||||||
if (!this.modelFor("user").get("can_edit")) {
|
if (!this.modelFor("user").get("can_edit")) {
|
||||||
this.replaceWith("userActivity");
|
this.router.replaceWith("userActivity");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -1,22 +1,26 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import { next } from "@ember/runloop";
|
import { next } from "@ember/runloop";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
|
||||||
export default class SignupRoute extends DiscourseRoute {
|
export default class SignupRoute extends DiscourseRoute {
|
||||||
beforeModel() {
|
@service router;
|
||||||
const { canSignUp } = this.controllerFor("application");
|
@service siteSettings;
|
||||||
|
|
||||||
if (this.siteSettings.login_required) {
|
beforeModel() {
|
||||||
this.replaceWith("login").then((e) => {
|
this.showCreateAccount();
|
||||||
if (canSignUp) {
|
}
|
||||||
next(() => e.send("showCreateAccount"));
|
|
||||||
}
|
@action
|
||||||
});
|
async showCreateAccount() {
|
||||||
} else {
|
const { canSignUp } = this.controllerFor("application");
|
||||||
this.replaceWith("discovery.latest").then((e) => {
|
const route = await this.router
|
||||||
if (canSignUp) {
|
.replaceWith(
|
||||||
next(() => e.send("showCreateAccount"));
|
this.siteSettings.login_required ? "login" : "discovery.latest"
|
||||||
}
|
)
|
||||||
});
|
.followRedirects();
|
||||||
|
if (canSignUp) {
|
||||||
|
next(() => route.send("showCreateAccount"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ const ALL = "all";
|
|||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
composer: service(),
|
composer: service(),
|
||||||
|
router: service(),
|
||||||
|
currentUser: service(),
|
||||||
navMode: "latest",
|
navMode: "latest",
|
||||||
|
|
||||||
queryParams,
|
queryParams,
|
||||||
@ -98,7 +100,7 @@ export default DiscourseRoute.extend({
|
|||||||
) {
|
) {
|
||||||
// TODO: avoid throwing away preload data by redirecting on the server
|
// TODO: avoid throwing away preload data by redirecting on the server
|
||||||
PreloadStore.getAndRemove("topic_list");
|
PreloadStore.getAndRemove("topic_list");
|
||||||
return this.replaceWith(
|
return this.router.replaceWith(
|
||||||
"tags.showCategoryNone",
|
"tags.showCategoryNone",
|
||||||
params.category_slug_path_with_id,
|
params.category_slug_path_with_id,
|
||||||
tagId
|
tagId
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
let user = this.modelFor("user");
|
let user = this.modelFor("user");
|
||||||
if (user.get("profile_hidden")) {
|
if (user.get("profile_hidden")) {
|
||||||
return this.replaceWith("user.profile-hidden");
|
return this.router.replaceWith("user.profile-hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
@ -3,19 +3,20 @@ import { inject as service } from "@ember/service";
|
|||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
router: service(),
|
router: service(),
|
||||||
|
site: service(),
|
||||||
|
currentUser: service(),
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
const { currentUser } = this;
|
|
||||||
const viewingMe =
|
const viewingMe =
|
||||||
currentUser &&
|
this.currentUser?.get("username") ===
|
||||||
currentUser.get("username") === this.modelFor("user").get("username");
|
this.modelFor("user").get("username");
|
||||||
const destination = viewingMe ? "userActivity" : "user.summary";
|
const destination = viewingMe ? "userActivity" : "user.summary";
|
||||||
|
|
||||||
// HACK: Something with the way the user card intercepts clicks seems to break how the
|
// HACK: Something with the way the user card intercepts clicks seems to break how the
|
||||||
// transition into a user's activity works. This makes the back button work on mobile
|
// transition into a user's activity works. This makes the back button work on mobile
|
||||||
// where there is no user card as well as desktop where there is.
|
// where there is no user card as well as desktop where there is.
|
||||||
if (this.site.mobileView) {
|
if (this.site.mobileView) {
|
||||||
this.replaceWith(destination);
|
this.router.replaceWith(destination);
|
||||||
} else {
|
} else {
|
||||||
this.router.transitionTo(destination);
|
this.router.transitionTo(destination);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
this.replaceWith("userInvited.show", "pending");
|
this.router.replaceWith("userInvited.show", "pending");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -2,8 +2,11 @@ import DiscourseRoute from "discourse/routes/discourse";
|
|||||||
import Invite from "discourse/models/invite";
|
import Invite from "discourse/models/invite";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
model(params) {
|
model(params) {
|
||||||
this.inviteFilter = params.filter;
|
this.inviteFilter = params.filter;
|
||||||
return Invite.findInvitedBy(this.modelFor("user"), params.filter);
|
return Invite.findInvitedBy(this.modelFor("user"), params.filter);
|
||||||
@ -11,7 +14,7 @@ export default DiscourseRoute.extend({
|
|||||||
|
|
||||||
afterModel(model) {
|
afterModel(model) {
|
||||||
if (!model.can_see_invite_details) {
|
if (!model.can_see_invite_details) {
|
||||||
this.replaceWith("userInvited.show", "redeemed");
|
this.router.replaceWith("userInvited.show", "redeemed");
|
||||||
}
|
}
|
||||||
this.controllerFor("user.invited").setProperties({
|
this.controllerFor("user.invited").setProperties({
|
||||||
invitesCount: model.counts,
|
invitesCount: model.counts,
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
const user = this.modelFor("user");
|
const user = this.modelFor("user");
|
||||||
if (user.get("profile_hidden")) {
|
if (user.get("profile_hidden")) {
|
||||||
return this.replaceWith("user.profile-hidden");
|
return this.router.replaceWith("user.profile-hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
return user.summary();
|
return user.summary();
|
||||||
|
@ -2,11 +2,17 @@ import DiscourseRoute from "discourse/routes/discourse";
|
|||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
searchService: service("search"),
|
||||||
|
appEvents: service("app-events"),
|
||||||
|
messageBus: service("message-bus"),
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
if (this.siteSettings.hide_user_profiles_from_public && !this.currentUser) {
|
if (this.siteSettings.hide_user_profiles_from_public && !this.currentUser) {
|
||||||
this.replaceWith("discovery");
|
this.router.replaceWith("discovery");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -31,7 +37,7 @@ export default DiscourseRoute.extend({
|
|||||||
.findDetails()
|
.findDetails()
|
||||||
.then(() => user.findStaffInfo())
|
.then(() => user.findStaffInfo())
|
||||||
.then(() => user.trackStatus())
|
.then(() => user.trackStatus())
|
||||||
.catch(() => this.replaceWith("/404"));
|
.catch(() => this.router.replaceWith("/404"));
|
||||||
},
|
},
|
||||||
|
|
||||||
serialize(model) {
|
serialize(model) {
|
||||||
|
@ -3,8 +3,13 @@ import I18n from "I18n";
|
|||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
|
siteSettings: service(),
|
||||||
|
currentUser: service(),
|
||||||
|
|
||||||
queryParams: {
|
queryParams: {
|
||||||
period: { refreshModel: true },
|
period: { refreshModel: true },
|
||||||
order: { refreshModel: true },
|
order: { refreshModel: true },
|
||||||
@ -36,7 +41,7 @@ export default DiscourseRoute.extend({
|
|||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
if (this.siteSettings.hide_user_profiles_from_public && !this.currentUser) {
|
if (this.siteSettings.hide_user_profiles_from_public && !this.currentUser) {
|
||||||
this.replaceWith("discovery");
|
this.router.replaceWith("discovery");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ globalThis.deprecationWorkflow.config = {
|
|||||||
workflow: [
|
workflow: [
|
||||||
{ handler: "silence", matchId: "route-render-template" },
|
{ handler: "silence", matchId: "route-render-template" },
|
||||||
{ handler: "silence", matchId: "route-disconnect-outlet" },
|
{ handler: "silence", matchId: "route-disconnect-outlet" },
|
||||||
{ handler: "silence", matchId: "routing.transition-methods" },
|
|
||||||
{ handler: "silence", matchId: "this-property-fallback" },
|
{ handler: "silence", matchId: "this-property-fallback" },
|
||||||
{ handler: "silence", matchId: "discourse.select-kit" },
|
{ handler: "silence", matchId: "discourse.select-kit" },
|
||||||
],
|
],
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
router: service(),
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
const appModel = this.modelFor("wizard");
|
const appModel = this.modelFor("wizard");
|
||||||
this.replaceWith("wizard.step", appModel.start);
|
this.router.replaceWith("wizard.step", appModel.start);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class ChatBrowseIndexRoute extends DiscourseRoute {
|
export default class ChatBrowseIndexRoute extends DiscourseRoute {
|
||||||
|
@service router;
|
||||||
|
@service siteSettings;
|
||||||
|
|
||||||
afterModel() {
|
afterModel() {
|
||||||
if (!this.siteSettings.chat_allow_archiving_channels) {
|
if (!this.siteSettings.chat_allow_archiving_channels) {
|
||||||
this.replaceWith("chat.browse");
|
this.router.replaceWith("chat.browse");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,6 @@ export default class ChatBrowseIndexRoute extends DiscourseRoute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
afterModel() {
|
afterModel() {
|
||||||
this.replaceWith("chat.browse.open");
|
this.router.replaceWith("chat.browse.open");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class ChatChannelInfoAboutRoute extends DiscourseRoute {
|
export default class ChatChannelInfoAboutRoute extends DiscourseRoute {
|
||||||
|
@service router;
|
||||||
|
|
||||||
afterModel(model) {
|
afterModel(model) {
|
||||||
if (model.isDirectMessageChannel) {
|
if (model.isDirectMessageChannel) {
|
||||||
this.replaceWith("chat.channel.info.index");
|
this.router.replaceWith("chat.channel.info.index");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class ChatChannelInfoIndexRoute extends DiscourseRoute {
|
export default class ChatChannelInfoIndexRoute extends DiscourseRoute {
|
||||||
|
@service router;
|
||||||
|
|
||||||
afterModel(model) {
|
afterModel(model) {
|
||||||
if (model.isDirectMessageChannel) {
|
if (model.isDirectMessageChannel) {
|
||||||
if (model.isOpen && model.membershipsCount >= 1) {
|
if (model.isOpen && model.membershipsCount >= 1) {
|
||||||
this.replaceWith("chat.channel.info.members");
|
this.router.replaceWith("chat.channel.info.members");
|
||||||
} else {
|
} else {
|
||||||
this.replaceWith("chat.channel.info.settings");
|
this.router.replaceWith("chat.channel.info.settings");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.replaceWith("chat.channel.info.about");
|
this.router.replaceWith("chat.channel.info.about");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class ChatChannelInfoMembersRoute extends DiscourseRoute {
|
export default class ChatChannelInfoMembersRoute extends DiscourseRoute {
|
||||||
|
@service router;
|
||||||
|
|
||||||
afterModel(model) {
|
afterModel(model) {
|
||||||
if (!model.isOpen) {
|
if (!model.isOpen) {
|
||||||
return this.replaceWith("chat.channel.info.settings");
|
return this.router.replaceWith("chat.channel.info.settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.membershipsCount < 1) {
|
if (model.membershipsCount < 1) {
|
||||||
return this.replaceWith("chat.channel.info");
|
return this.router.replaceWith("chat.channel.info");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default class ChatChannelInfoSettingsRoute extends DiscourseRoute {
|
export default class ChatChannelInfoSettingsRoute extends DiscourseRoute {
|
||||||
|
@service router;
|
||||||
|
@service currentUser;
|
||||||
|
|
||||||
afterModel(model) {
|
afterModel(model) {
|
||||||
if (!this.currentUser?.staff && !model.currentUserMembership?.following) {
|
if (!this.currentUser?.staff && !model.currentUserMembership?.following) {
|
||||||
this.replaceWith("chat.channel.info");
|
this.router.replaceWith("chat.channel.info");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ export default class ChatMessageRoute extends DiscourseRoute {
|
|||||||
params.messageId
|
params.messageId
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.catch(() => this.replaceWith("/404"));
|
.catch(() => this.router.replaceWith("/404"));
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user