Commit e16b5939 authored by Małgorzata Ksionek's avatar Małgorzata Ksionek

Rephrase error message and add code review remarks

Add cr remarks

Add cr remarks

Add cr remarks

Add cr remarks

Add cr remarks
parent 529abbf8
...@@ -22,7 +22,7 @@ module MembershipActions ...@@ -22,7 +22,7 @@ module MembershipActions
.new(current_user, update_params) .new(current_user, update_params)
.execute(member) .execute(member)
member = result.fetch(:member, nil) member = result[:member]
if result[:status] == :success if result[:status] == :success
if member.expires? if member.expires?
......
...@@ -16,9 +16,9 @@ module Members ...@@ -16,9 +16,9 @@ module Members
enqueue_delete_todos(member) if downgrading_to_guest? enqueue_delete_todos(member) if downgrading_to_guest?
end end
return success(member: member) unless member.errors.any? return error(member.errors.full_messages.to_sentence, pass_back: { member: member }) if member.errors.any?
error(member.errors.full_messages.to_sentence) success(member: member)
end end
private private
......
...@@ -91,7 +91,7 @@ module EE ...@@ -91,7 +91,7 @@ module EE
end end
def email_does_not_match_any_allowed_domains(email) def email_does_not_match_any_allowed_domains(email)
_("email '%{email}' does not match the allowed domains of %{email_domains}" % _("email '%{email}' does not match the allowed domain of %{email_domains}" %
{ email: email, email_domains: ::Gitlab::Utils.to_exclusive_sentence(group_allowed_email_domains.map(&:domain)) }) { email: email, email_domains: ::Gitlab::Utils.to_exclusive_sentence(group_allowed_email_domains.map(&:domain)) })
end end
......
...@@ -23,12 +23,12 @@ module EE ...@@ -23,12 +23,12 @@ module EE
.new(current_user, { override: true }) .new(current_user, { override: true })
.execute(member, permission: :override) .execute(member, permission: :override)
updated_member = result.fetch(:member, nil) updated_member = result[:member]
if result[:status] == :success if result[:status] == :success
present_member(updated_member) present_member(updated_member)
else else
render_validation_error!(member) render_validation_error!(updated_member)
end end
end end
...@@ -45,12 +45,12 @@ module EE ...@@ -45,12 +45,12 @@ module EE
.new(current_user, { override: false }) .new(current_user, { override: false })
.execute(member, permission: :override) .execute(member, permission: :override)
updated_member = result.fetch(:member, nil) updated_member = result[:member]
if result[:status] == :success if result[:status] == :success
present_member(updated_member) present_member(updated_member)
else else
render_validation_error!(member) render_validation_error!(updated_member)
end end
end end
......
...@@ -89,18 +89,16 @@ RSpec.describe Groups::GroupMembersController do ...@@ -89,18 +89,16 @@ RSpec.describe Groups::GroupMembersController do
context 'for a user with an un-verified email belonging to a domain different from the allowed domain' do context 'for a user with an un-verified email belonging to a domain different from the allowed domain' do
let(:email) { 'test@gmail.com' } let(:email) { 'test@gmail.com' }
context 'for a user with an email belonging to the allowed domain' do it 'returns error status' do
it 'returns error status' do subject
subject
expect(response).to have_gitlab_http_status(:unprocessable_entity) expect(response).to have_gitlab_http_status(:unprocessable_entity)
end end
it 'returns error message' do it 'returns error message' do
subject subject
expect(json_response).to eq({ 'message' => "User email 'test@gmail.com' does not match the allowed domains of gitlab.com" }) expect(json_response).to eq({ 'message' => "User email 'test@gmail.com' does not match the allowed domain of gitlab.com" })
end
end end
end end
end end
......
...@@ -142,12 +142,12 @@ module API ...@@ -142,12 +142,12 @@ module API
.new(current_user, declared_params(include_missing: false)) .new(current_user, declared_params(include_missing: false))
.execute(member) .execute(member)
updated_member = result.fetch(:member, nil) updated_member = result[:member]
if result[:status] == :success if result[:status] == :success
present_members updated_member present_members updated_member
else else
render_validation_error!(member) render_validation_error!(updated_member)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -33508,7 +33508,7 @@ msgstr "" ...@@ -33508,7 +33508,7 @@ msgstr ""
msgid "element is not a hierarchy" msgid "element is not a hierarchy"
msgstr "" msgstr ""
msgid "email '%{email}' does not match the allowed domains of %{email_domains}" msgid "email '%{email}' does not match the allowed domain of %{email_domains}"
msgstr "" msgstr ""
msgid "email '%{email}' is not a verified email." msgid "email '%{email}' is not a verified email."
......
...@@ -13,9 +13,11 @@ RSpec.describe Members::UpdateService do ...@@ -13,9 +13,11 @@ RSpec.describe Members::UpdateService do
{ access_level: Gitlab::Access::MAINTAINER } { access_level: Gitlab::Access::MAINTAINER }
end end
subject { described_class.new(current_user, params).execute(member, permission: permission) }
shared_examples 'a service raising Gitlab::Access::AccessDeniedError' do shared_examples 'a service raising Gitlab::Access::AccessDeniedError' do
it 'raises Gitlab::Access::AccessDeniedError' do it 'raises Gitlab::Access::AccessDeniedError' do
expect { described_class.new(current_user, params).execute(member, permission: permission) } expect { subject }
.to raise_error(Gitlab::Access::AccessDeniedError) .to raise_error(Gitlab::Access::AccessDeniedError)
end end
end end
...@@ -24,14 +26,14 @@ RSpec.describe Members::UpdateService do ...@@ -24,14 +26,14 @@ RSpec.describe Members::UpdateService do
it 'updates the member' do it 'updates the member' do
expect(TodosDestroyer::EntityLeaveWorker).not_to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, member.user_id, member.source_id, source.class.name) expect(TodosDestroyer::EntityLeaveWorker).not_to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, member.user_id, member.source_id, source.class.name)
updated_member = described_class.new(current_user, params).execute(member, permission: permission).fetch(:member) updated_member = subject.fetch(:member)
expect(updated_member).to be_valid expect(updated_member).to be_valid
expect(updated_member.access_level).to eq(Gitlab::Access::MAINTAINER) expect(updated_member.access_level).to eq(Gitlab::Access::MAINTAINER)
end end
it 'returns success status' do it 'returns success status' do
result = described_class.new(current_user, params).execute(member, permission: permission).fetch(:status) result = subject.fetch(:status)
expect(result).to eq(:success) expect(result).to eq(:success)
end end
...@@ -41,7 +43,7 @@ RSpec.describe Members::UpdateService do ...@@ -41,7 +43,7 @@ RSpec.describe Members::UpdateService do
it do it do
expect(TodosDestroyer::EntityLeaveWorker).to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, member.user_id, member.source_id, source.class.name).once expect(TodosDestroyer::EntityLeaveWorker).to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, member.user_id, member.source_id, source.class.name).once
updated_member = described_class.new(current_user, params).execute(member, permission: permission).fetch(:member) updated_member = subject.fetch(:member)
expect(updated_member).to be_valid expect(updated_member).to be_valid
expect(updated_member.access_level).to eq(Gitlab::Access::GUEST) expect(updated_member.access_level).to eq(Gitlab::Access::GUEST)
...@@ -73,7 +75,7 @@ RSpec.describe Members::UpdateService do ...@@ -73,7 +75,7 @@ RSpec.describe Members::UpdateService do
let(:params) { { expires_at: 2.days.ago } } let(:params) { { expires_at: 2.days.ago } }
it 'returns error status' do it 'returns error status' do
result = described_class.new(current_user, params).execute(member, permission: permission) result = subject
expect(result[:status]).to eq(:error) expect(result[:status]).to eq(:error)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment