Skip to content

Commit

Permalink
Do not capitalize class names in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hennevogel committed Jul 18, 2022
1 parent 2f3649c commit 254c2ca
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def authorization_message(exception)
when :anonymous_user
'Please login to access the resource'
else
"Sorry, you are not authorized to #{action_for_exception(exception)} this #{ActiveSupport::Inflector.underscore(exception.record.class.to_s).humanize}."
"Sorry, you are not authorized to #{action_for_exception(exception)} this #{ActiveSupport::Inflector.underscore(exception.record.class.to_s).humanize(capitalize: false)}."
end
end

Expand Down
8 changes: 4 additions & 4 deletions src/api/app/controllers/webui/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ class Webui::GroupsController < Webui::WebuiController
after_action :verify_authorized, except: [:show, :autocomplete]

def index
authorize Group, :index?
authorize Group.new, :index?
@groups = Group.all.includes(:users)
end

def show; end

def new
authorize Group, :create?
authorize Group.new, :create?
end

def create
authorize Group, :create?

group = Group.new(title: group_params[:title])
authorize group, :create?

if group.save && group.replace_members(group_params[:members])
flash[:success] = "Group '#{group}' successfully created."
redirect_to controller: :groups, action: :index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def create
flash[:notice] = 'You have already branched this package'
redirect_to(package_show_path(project: e.project, package: e.package))
rescue CreateProjectNoPermission
flash[:error] = 'Sorry, you are not authorized to create this Project.'
flash[:error] = 'Sorry, you are not authorized to create this project.'
redirect_back(fallback_location: root_path)
rescue ArgumentError, Package::UnknownObjectError, Project::UnknownObjectError, APIError, ActiveRecord::RecordInvalid => e
flash[:error] = "Failed to branch: #{e.message}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
end

it { is_expected.to redirect_to(root_path) }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to create this Download repository.') }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to create this download repository.') }
it { expect(DownloadRepository.where(dod_parameters[:download_repository])).not_to exist }
end

Expand Down Expand Up @@ -85,7 +85,7 @@
end

it { is_expected.to redirect_to(root_path) }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to delete this Download repository.') }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to delete this download repository.') }
it { expect(DownloadRepository.where(id: dod_repository.id)).to exist }
end

Expand Down Expand Up @@ -127,7 +127,7 @@
end

it { is_expected.to redirect_to(root_path) }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this Download repository.') }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this download repository.') }

it 'updates the DownloadRepository' do
expect(dod_repository.url).to eq('http://suse.com')
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/controllers/webui/groups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
it 'does not allow to create a group' do
post :create, params: { group: { title: group.title, members: users_to_add.map(&:login).join(',') } }

expect(flash[:error]).to eq('Sorry, you are not authorized to create this Class.')
expect(flash[:error]).to eq('Sorry, you are not authorized to create this group.')
end
end

Expand Down
8 changes: 4 additions & 4 deletions src/api/spec/controllers/webui/package_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
it 'does not allow other users than the owner to delete a package' do
post :remove, params: { project: target_project, package: target_package }

expect(flash[:error]).to eq('Sorry, you are not authorized to delete this Package.')
expect(flash[:error]).to eq('Sorry, you are not authorized to delete this package.')
expect(target_project.packages).not_to be_empty
end

Expand Down Expand Up @@ -258,7 +258,7 @@ def remove_file_post
remove_file_post
end

it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this Package.') }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this package.') }
it { expect(Package.where(name: 'my_package')).to exist }
end
end
Expand Down Expand Up @@ -413,7 +413,7 @@ def remove_file_post
end

it { expect(a_request(:post, post_url)).not_to have_been_made }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this Package.') }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this package.') }
it { is_expected.to redirect_to(root_path) }
end
end
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def do_request(params)
let(:my_user) { create(:confirmed_user, login: 'another_user') }

it { expect(response).to redirect_to(root_path) }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to create this Package.') }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to create this package.') }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

it 'shows an error if user has no permissions for source project' do
post :create, params: { linked_project: source_project, linked_package: source_package, target_project: 'home:admin:nope' }
expect(flash[:error]).to eq('Sorry, you are not authorized to create this Project.')
expect(flash[:error]).to eq('Sorry, you are not authorized to create this project.')
expect(response).to redirect_to(root_path)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def do_proper_post_save
end

it { expect(response).to have_http_status(:redirect) }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this Project.') }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this project.') }
end

context 'when it fails to create the patchinfo package' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
post :update, params: { project_name: another_project.name, config: 'save config' }
end

it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this Project.') }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to update this project.') }
it { expect(response.status).to eq(302) }
it { expect(response).to redirect_to(root_path) }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
}
end

it { expect(response.body).to eq('{"error":"Sorry, you are not authorized to create this Download repository."}') }
it { expect(response.body).to eq('{"error":"Sorry, you are not authorized to create this download repository."}') }
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
end

it { expect(Project.where(name: 'Apache')).not_to exist }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to create this Project.') }
it { expect(flash[:error]).to eq('Sorry, you are not authorized to create this project.') }
it { expect(CreateProjectLogEntryJob).not_to have_been_enqueued }
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/features/webui/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
click_link('Add Attribute')
find('select#attrib_attrib_type_id').select('OBS:VeryImportantProject')
click_button('Add')
expect(page).to have_content('Sorry, you are not authorized to create this Attrib.')
expect(page).to have_content('Sorry, you are not authorized to create this attrib.')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/features/webui/packages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
login other_user
visit new_package_path(project: global_project)

expect(page).to have_text('Sorry, you are not authorized to create this Package')
expect(page).to have_text('Sorry, you are not authorized to create this package')
expect(page).to have_current_path(root_path, ignore_query: true)
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/test/functional/request_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ def test_create_request_with_approver
post '/request?cmd=create', params: format(req_template, approver: 'fred')
assert_response 403
assert_xml_tag(tag: 'status', attributes: { code: 'create_bs_request_not_authorized' })
assert_xml_tag(tag: 'summary', content: 'Sorry, you are not authorized to create this Bs request.')
assert_xml_tag(tag: 'summary', content: 'Sorry, you are not authorized to create this bs request.')

# request creation succeeds because we are "Iggy"
post '/request?cmd=create', params: format(req_template, approver: 'Iggy')
Expand Down

0 comments on commit 254c2ca

Please sign in to comment.