Commit b3cd4ae2 authored by Brett Walker's avatar Brett Walker

Refactor to remove disable CodeReuse/ActiveRecord

when using board finders
parent eb072743
......@@ -21,6 +21,7 @@ class GroupMember < Member
scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) }
scope :of_ldap_type, -> { where(ldap: true) }
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_destroy :update_two_factor_requirement, unless: :invite?
......
......@@ -19,7 +19,6 @@ module EE
private
# rubocop: disable CodeReuse/ActiveRecord
override :authorize_list_type_resource!
def authorize_list_type_resource!(board, params)
super
......@@ -27,7 +26,7 @@ module EE
if params[:milestone_id]
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!'
end
end
......@@ -35,12 +34,11 @@ module EE
if params[:assignee_id]
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!'
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
override :create_list_params
def create_list_params(args)
......
......@@ -41,29 +41,29 @@ module EE
end
# Overrides API::BoardsResponses authorize_list_type_resource!
# rubocop: disable CodeReuse/ActiveRecord
def authorize_list_type_resource!
# rubocop: disable CodeReuse/ActiveRecord
if params[:label_id] && !available_labels_for(board_parent).exists?(params[:label_id])
render_api_error!({ error: 'Label not found!' }, 400)
end
# rubocop: enable CodeReuse/ActiveRecord
if milestone_id = params[:milestone_id]
if params[:milestone_id]
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)
end
end
if assignee_id = params[:assignee_id]
if params[:assignee_id]
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)
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# Overrides API::BoardsResponses list_creation_params
params :list_creation_params do
......
......@@ -4,9 +4,10 @@ require 'spec_helper'
RSpec.describe GroupMember 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
user_1 = create(:user)
user_2 = create(:user)
group_1 = create(:group)
group_2 = create(:group)
......@@ -25,6 +26,15 @@ RSpec.describe GroupMember do
expect(described_class.of_ldap_type).to eq([group_member])
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
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