From 123107c28f045006b844c47c35995a54fcc57b3f Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Tue, 24 Nov 2020 13:06:52 +0200 Subject: [PATCH] UX: Add group name to error message (#11333) The group name used to be part of the error message, but was removed in a past commit. --- app/controllers/application_controller.rb | 1 + app/controllers/topics_controller.rb | 1 + config/locales/server.en.yml | 2 +- lib/discourse.rb | 2 ++ spec/requests/topics_controller_spec.rb | 24 +++++++++++++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e524c232d9a..a1fc32cf768 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -207,6 +207,7 @@ class ApplicationController < ActionController::Base 403, include_ember: true, custom_message: e.custom_message, + custom_message_params: e.custom_message_params, group: e.group ) end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 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 ) end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 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.rb index 948cf9ac8d0..d9db43e4e59 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -142,6 +142,7 @@ module Discourse attr_reader :obj attr_reader :opts attr_reader :custom_message + attr_reader :custom_message_params attr_reader :group def 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] end end diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 2ceeba01ad4..214263be022 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -1584,6 +1584,30 @@ RSpec.describe TopicsController do end end + 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' do get "/t/#{topic.id}", params: { slug: topic.slug }