diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index ce14d2903aeeaa..f459e4bcecc405 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -945,46 +945,6 @@ export default Ember.Controller.extend(bufferedProperty("model"), { } }, - joinGroup() { - const groupId = this.get("model.group.id"); - if (groupId) { - if (this.get("model.group.allow_membership_requests")) { - const groupName = this.get("model.group.name"); - return ajax(`/groups/${groupName}/request_membership`, { - type: "POST", - data: { - topic_id: this.get("model.id") - } - }) - .then(() => { - bootbox.alert( - I18n.t("topic.group_request_sent", { - group_name: this.get("model.group.full_name") - }), - () => - this.previousURL - ? DiscourseURL.routeTo(this.previousURL) - : DiscourseURL.routeTo("/") - ); - }) - .catch(popupAjaxError); - } else { - const topic = this.model; - return ajax(`/groups/${groupId}/members`, { - type: "PUT", - data: { user_id: this.get("currentUser.id") } - }) - .then(() => - topic.reload().then(() => { - topic.set("view_hidden", false); - topic.postStream.refresh(); - }) - ) - .catch(popupAjaxError); - } - } - }, - replyAsNewTopic(post, quotedText) { const composerController = this.composer; @@ -1182,7 +1142,7 @@ export default Ember.Controller.extend(bufferedProperty("model"), { } }, - hasError: Ember.computed.or("model.notFoundHtml", "model.message"), + hasError: Ember.computed.or("model.errorHtml", "model.errorMessage"), noErrorYet: Ember.computed.not("hasError"), categories: Ember.computed.alias("site.categoriesList"), diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index 346226b9eb4d86..a3b42bcaeb320b 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -1067,31 +1067,16 @@ export default RestModel.extend({ // Handles an error loading a topic based on a HTTP status code. Updates // the text to the correct values. errorLoading(result) { - const status = result.jqXHR.status; - const topic = this.topic; this.set("loadingFilter", false); topic.set("errorLoading", true); - // If the result was 404 the post is not found - // If it was 410 the post is deleted and the user should not see it - if (status === 404 || status === 410) { - topic.set("notFoundHtml", result.jqXHR.responseText); - return; - } - - // If the result is 403 it means invalid access - if (status === 403) { - topic.set("noRetry", true); - if (Discourse.User.current()) { - topic.set("message", I18n.t("topic.invalid_access.description")); - } else { - topic.set("message", I18n.t("topic.invalid_access.login_required")); - } - return; + const json = result.jqXHR.responseJSON; + if (json && json.extras && json.extras.html) { + topic.set("errorHtml", json.extras.html); + } else { + topic.set("errorMessage", I18n.t("topic.server_error.description")); + topic.set("noRetry", result.jqXHR.status === 403); } - - // Otherwise supply a generic error message - topic.set("message", I18n.t("topic.server_error.description")); } }); diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6 index d44afe930ec752..1af3697106e469 100644 --- a/app/assets/javascripts/discourse/models/topic.js.es6 +++ b/app/assets/javascripts/discourse/models/topic.js.es6 @@ -17,16 +17,15 @@ import { } from "ember-addons/ember-computed-decorators"; export function loadTopicView(topic, args) { - const topicId = topic.get("id"); const data = _.merge({}, args); - const url = `${Discourse.getURL("/t/")}${topicId}`; + const url = `${Discourse.getURL("/t/")}${topic.id}`; const jsonUrl = (data.nearPost ? `${url}/${data.nearPost}` : url) + ".json"; delete data.nearPost; delete data.__type; delete data.store; - return PreloadStore.getAndRemove(`topic_${topicId}`, () => + return PreloadStore.getAndRemove(`topic_${topic.id}`, () => ajax(jsonUrl, { data }) ).then(json => { topic.updateFromJson(json); diff --git a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 index c1db98d7779495..aadf72eb35fddc 100644 --- a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 @@ -198,6 +198,18 @@ export default (filterArg, params) => { }, actions: { + error(err) { + const json = err.jqXHR.responseJSON; + if (json && json.extras && json.extras.html) { + this.controllerFor("discovery").set( + "errorHtml", + err.jqXHR.responseJSON.extras.html + ); + } else { + this.replaceWith("exception"); + } + }, + setNotification(notification_level) { this.currentModel.setNotification(notification_level); }, diff --git a/app/assets/javascripts/discourse/templates/discovery.hbs b/app/assets/javascripts/discourse/templates/discovery.hbs index c6242e9e5b847b..6801ab3f55164c 100644 --- a/app/assets/javascripts/discourse/templates/discovery.hbs +++ b/app/assets/javascripts/discourse/templates/discovery.hbs @@ -1,32 +1,36 @@ -