Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b3cd4ae2
Commit
b3cd4ae2
authored
Oct 08, 2020
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor to remove disable CodeReuse/ActiveRecord
when using board finders
parent
eb072743
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
12 deletions
+21
-12
app/models/members/group_member.rb
app/models/members/group_member.rb
+1
-0
ee/app/graphql/ee/mutations/boards/lists/create.rb
ee/app/graphql/ee/mutations/boards/lists/create.rb
+2
-4
ee/lib/ee/api/boards_responses.rb
ee/lib/ee/api/boards_responses.rb
+6
-6
spec/models/members/group_member_spec.rb
spec/models/members/group_member_spec.rb
+12
-2
No files found.
app/models/members/group_member.rb
View file @
b3cd4ae2
...
...
@@ -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?
...
...
ee/app/graphql/ee/mutations/boards/lists/create.rb
View file @
b3cd4ae2
...
...
@@ -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
.
w
here
(
user_id:
params
[
:assignee_id
]).
exists?
unless
users
.
w
ith_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
)
...
...
ee/lib/ee/api/boards_responses.rb
View file @
b3cd4ae2
...
...
@@ -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
...
...
spec/models/members/group_member_spec.rb
View file @
b3cd4ae2
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment