A platform for community discussion. Free, open, simple.
UX: Add group name to error message (#11333)
Dan Ungureanu123107c28f04
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex e524c232d9a..a1fc32cf768 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -207,6 +207,7 @@ class ApplicationController < ActionController::Base403,include_ember: true,custom_message: e.custom_message,+ custom_message_params: e.custom_message_params,group: e.group)enddiff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex 628903ed8de..91063417ee3 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -112,6 +112,7 @@ class TopicsController < ApplicationController'not in group',ex.obj,custom_message: 'not_in_group.title_topic',+ custom_message_params: { group: group.name },group: group)enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex fd52a18ee74..1321f005b0b 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -281,7 +281,7 @@ en:email_template_cant_be_modified: "This email template can't be modified"invalid_whisper_access: "Either whispers are not enabled or you do not have access to create whisper posts"not_in_group:- title_topic: "You must be in a group to see this topic."+ title_topic: "You need to request membership to the '%{group}' group to see this topic."title_category: "You must be in a group to see this category."request_membership: "Request Membership"join_group: "Join Group"diff --git a/lib/discourse.rb b/lib/discourse.rbindex 948cf9ac8d0..d9db43e4e59 100644--- a/lib/discourse.rb+++ b/lib/discourse.rb@@ -142,6 +142,7 @@ module Discourseattr_reader :objattr_reader :optsattr_reader :custom_message+ attr_reader :custom_message_paramsattr_reader :groupdef initialize(msg = nil, obj = nil, opts = nil)@@ -150,6 +151,7 @@ module Discourse@opts = opts || {}@obj = obj@custom_message = opts[:custom_message] if @opts[:custom_message]+ @custom_message_params = opts[:custom_message_params] if @opts[:custom_message_params]@group = opts[:group] if @opts[:group]endenddiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 2ceeba01ad4..214263be022 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -1584,6 +1584,30 @@ RSpec.describe TopicsController doendend+ describe 'when topic is allowed to a group' do+ let(:group) { Fabricate(:group, public_admission: true) }+ let(:category) do+ Fabricate(:category_with_definition).tap do |category|+ category.set_permissions(group => :full)+ category.save!+ end+ end+ let(:topic) { Fabricate(:topic, category: category) }++ before do+ SiteSetting.detailed_404 = true+ end++ it 'shows a descriptive error message containing the group name' do+ get "/t/#{topic.id}.json"++ html = CGI.unescapeHTML(response.parsed_body["extras"]["html"])+ expect(response.status).to eq(403)+ expect(html).to include(I18n.t('not_in_group.title_topic', group: group.name))+ expect(html).to include(I18n.t('not_in_group.join_group'))+ end+ end+it 'correctly renders canoicals' doget "/t/#{topic.id}", params: { slug: topic.slug }