Commit 0174562a authored by Igor Drozdov's avatar Igor Drozdov

Merge branch...

Merge branch '242039-follow-up-from-graphql-create-board-list-with-milestone-or-assignee' into 'master'

Follow-up from "GraphQL: Create board list with milestone or assignee"

See merge request gitlab-org/gitlab!44798
parents d9c4c9e3 b3cd4ae2
...@@ -21,6 +21,7 @@ class GroupMember < Member ...@@ -21,6 +21,7 @@ class GroupMember < Member
scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) } scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) }
scope :of_ldap_type, -> { where(ldap: true) } scope :of_ldap_type, -> { where(ldap: true) }
scope :count_users_by_group_id, -> { group(:source_id).count } scope :count_users_by_group_id, -> { group(:source_id).count }
scope :with_user, -> (user) { where(user: user) }
after_create :update_two_factor_requirement, unless: :invite? after_create :update_two_factor_requirement, unless: :invite?
after_destroy :update_two_factor_requirement, unless: :invite? after_destroy :update_two_factor_requirement, unless: :invite?
......
...@@ -19,7 +19,6 @@ module EE ...@@ -19,7 +19,6 @@ module EE
private private
# rubocop: disable CodeReuse/ActiveRecord
override :authorize_list_type_resource! override :authorize_list_type_resource!
def authorize_list_type_resource!(board, params) def authorize_list_type_resource!(board, params)
super super
...@@ -27,7 +26,7 @@ module EE ...@@ -27,7 +26,7 @@ module EE
if params[:milestone_id] if params[:milestone_id]
milestones = ::Boards::MilestonesFinder.new(board, current_user).execute milestones = ::Boards::MilestonesFinder.new(board, current_user).execute
unless milestones.where(id: params[:milestone_id]).exists? unless milestones.id_in(params[:milestone_id]).exists?
raise ::Gitlab::Graphql::Errors::ArgumentError, 'Milestone not found!' raise ::Gitlab::Graphql::Errors::ArgumentError, 'Milestone not found!'
end end
end end
...@@ -35,12 +34,11 @@ module EE ...@@ -35,12 +34,11 @@ module EE
if params[:assignee_id] if params[:assignee_id]
users = ::Boards::UsersFinder.new(board, current_user).execute users = ::Boards::UsersFinder.new(board, current_user).execute
unless users.where(user_id: params[:assignee_id]).exists? unless users.with_user(params[:assignee_id]).exists?
raise ::Gitlab::Graphql::Errors::ArgumentError, 'User not found!' raise ::Gitlab::Graphql::Errors::ArgumentError, 'User not found!'
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
override :create_list_params override :create_list_params
def create_list_params(args) def create_list_params(args)
......
...@@ -41,29 +41,29 @@ module EE ...@@ -41,29 +41,29 @@ module EE
end end
# Overrides API::BoardsResponses authorize_list_type_resource! # Overrides API::BoardsResponses authorize_list_type_resource!
# rubocop: disable CodeReuse/ActiveRecord
def authorize_list_type_resource! def authorize_list_type_resource!
# rubocop: disable CodeReuse/ActiveRecord
if params[:label_id] && !available_labels_for(board_parent).exists?(params[:label_id]) if params[:label_id] && !available_labels_for(board_parent).exists?(params[:label_id])
render_api_error!({ error: 'Label not found!' }, 400) render_api_error!({ error: 'Label not found!' }, 400)
end end
# rubocop: enable CodeReuse/ActiveRecord
if milestone_id = params[:milestone_id] if params[:milestone_id]
milestones = ::Boards::MilestonesFinder.new(board, current_user).execute milestones = ::Boards::MilestonesFinder.new(board, current_user).execute
unless milestones.find_by(id: milestone_id) unless milestones.id_in(params[:milestone_id]).exists?
render_api_error!({ error: 'Milestone not found!' }, 400) render_api_error!({ error: 'Milestone not found!' }, 400)
end end
end end
if assignee_id = params[:assignee_id] if params[:assignee_id]
users = ::Boards::UsersFinder.new(board, current_user).execute users = ::Boards::UsersFinder.new(board, current_user).execute
unless users.find_by(user_id: assignee_id) unless users.with_user(params[:assignee_id]).exists?
render_api_error!({ error: 'User not found!' }, 400) render_api_error!({ error: 'User not found!' }, 400)
end end
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# Overrides API::BoardsResponses list_creation_params # Overrides API::BoardsResponses list_creation_params
params :list_creation_params do params :list_creation_params do
......
...@@ -4,9 +4,10 @@ require 'spec_helper' ...@@ -4,9 +4,10 @@ require 'spec_helper'
RSpec.describe GroupMember do RSpec.describe GroupMember do
context 'scopes' do context 'scopes' do
let_it_be(:user_1) { create(:user) }
let_it_be(:user_2) { create(:user) }
it 'counts users by group ID' do it 'counts users by group ID' do
user_1 = create(:user)
user_2 = create(:user)
group_1 = create(:group) group_1 = create(:group)
group_2 = create(:group) group_2 = create(:group)
...@@ -25,6 +26,15 @@ RSpec.describe GroupMember do ...@@ -25,6 +26,15 @@ RSpec.describe GroupMember do
expect(described_class.of_ldap_type).to eq([group_member]) expect(described_class.of_ldap_type).to eq([group_member])
end end
end end
describe '.with_user' do
it 'returns requested user' do
group_member = create(:group_member, user: user_2)
create(:group_member, user: user_1)
expect(described_class.with_user(user_2)).to eq([group_member])
end
end
end end
describe '.access_level_roles' do describe '.access_level_roles' do
......
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