FIX: Restricted site text better error

This commit is contained in:
venarius 2019-04-02 14:16:45 +02:00 committed by Robin Ward
parent 123c05cb07
commit c185109380
3 changed files with 7 additions and 3 deletions
app/controllers/admin
config/locales
spec/requests/admin

View File

@ -119,7 +119,8 @@ class Admin::SiteTextsController < Admin::AdminController
end end
def find_site_text def find_site_text
raise Discourse::NotFound unless I18n.exists?(params[:id]) && !self.class.restricted_keys.include?(params[:id]) raise Discourse::NotFound unless I18n.exists?(params[:id])
raise Discourse::InvalidAccess.new(nil, nil, custom_message: 'email_template_cant_be_modified') if self.class.restricted_keys.include?(params[:id])
record_for(params[:id]) record_for(params[:id])
end end

View File

@ -242,6 +242,7 @@ en:
provider_not_found: "You are not permitted to view the requested resource. The authentication provider does not exist." provider_not_found: "You are not permitted to view the requested resource. The authentication provider does not exist."
read_only_mode_enabled: "The site is in read only mode. Interactions are disabled." read_only_mode_enabled: "The site is in read only mode. Interactions are disabled."
invalid_grant_badge_reason_link: "External or invalid discourse link is not allowed in badge reason" invalid_grant_badge_reason_link: "External or invalid discourse link is not allowed in badge reason"
email_template_cant_be_modified: "This email template can't be modified"
reading_time: "Reading time" reading_time: "Reading time"
likes: "Likes" likes: "Likes"

View File

@ -141,10 +141,12 @@ RSpec.describe Admin::SiteTextsController do
site_text: { value: 'foo' } site_text: { value: 'foo' }
} }
expect(response.status).to eq(404) expect(response.status).to eq(403)
json = ::JSON.parse(response.body) json = ::JSON.parse(response.body)
expect(json['error_type']).to eq('not_found') expect(json['error_type']).to eq('invalid_access')
expect(json['errors'].size).to eq(1)
expect(json['errors'].first).to eq(I18n.t('email_template_cant_be_modified'))
end end
it "returns the right error message" do it "returns the right error message" do