FIX: When creating new message via URL do not redirect (#27153)

* FIX: When creating new message via URL do not redirect

If a user clicks on `/new-message` route from inside the instance we're
redirecting the user to `/latest` page which is only intended if the
user is coming from an external site. This commit checks for this
condition and only redirects when user is coming from external source.

This also makes the behavior consistent with `new-topic` route.

Internal topic reference: `/t/-/129523/`
This commit is contained in:
Arpit Jalan 2024-05-24 17:25:37 +05:30 committed by GitHub
parent 949c70372c
commit 9db83c37e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 56 additions and 26 deletions

View File

@ -12,49 +12,78 @@ export default DiscourseRoute.extend({
beforeModel(transition) {
const params = transition.to.queryParams;
const userName = params.username;
const groupName = params.groupname || params.group_name;
if (this.currentUser) {
if (!this.currentUser) {
cookie("destination_url", window.location.href);
this.router.replaceWith("login");
return;
}
if (transition.from) {
transition.abort();
if (userName) {
return this.openComposer(transition, userName);
}
if (groupName) {
// send a message to a group
return Group.messageable(groupName)
.then((result) => {
if (result.messageable) {
this.openComposer(transition, groupName);
} else {
this.dialog.alert(
I18n.t("composer.cant_send_pm", { username: groupName })
);
}
})
.catch(() =>
this.dialog.alert(I18n.t("composer.create_message_error"))
);
}
return this.openComposer(transition);
} else {
this.router
.replaceWith("discovery.latest")
.followRedirects()
.then(() => {
if (params.username) {
this.composer.openNewMessage({
recipients: params.username,
title: params.title,
body: params.body,
});
} else if (groupName) {
if (userName) {
return this.openComposer(transition, userName);
}
if (groupName) {
// send a message to a group
Group.messageable(groupName)
return Group.messageable(groupName)
.then((result) => {
if (result.messageable) {
next(() =>
this.composer.openNewMessage({
recipients: groupName,
title: params.title,
body: params.body,
})
);
this.openComposer(transition, 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,
body: params.body,
});
.catch(() =>
this.dialog.alert(I18n.t("composer.create_message_error"))
);
}
return this.openComposer(transition);
});
} else {
cookie("destination_url", window.location.href);
this.router.replaceWith("login");
}
},
openComposer(transition, recipients) {
next(() => {
this.composer.openNewMessage({
recipients,
title: transition.to.queryParams.title,
body: transition.to.queryParams.body,
});
});
},
});

View File

@ -2596,6 +2596,7 @@ en:
modal_ok: "OK"
modal_cancel: "Cancel"
cant_send_pm: "Sorry, you can't send a message to %{username}."
create_message_error: "Sorry, there was an error creating that message. Please try again."
yourself_confirm:
title: "Did you forget to add recipients?"
body: "Right now this message is only being sent to yourself!"