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
b933eef0
Commit
b933eef0
authored
Mar 16, 2022
by
Doug Stull
Committed by
Vitali Tatarintev
Mar 16, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow members added by user record to be found if existing
- allows existing members to see users by user record
parent
3f0faea1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
21 deletions
+37
-21
app/services/concerns/members/bulk_create_users.rb
app/services/concerns/members/bulk_create_users.rb
+6
-7
spec/support/shared_examples/models/member_shared_examples.rb
.../support/shared_examples/models/member_shared_examples.rb
+31
-14
No files found.
app/services/concerns/members/bulk_create_users.rb
View file @
b933eef0
...
@@ -47,16 +47,15 @@ module Members
...
@@ -47,16 +47,15 @@ module Members
end
end
end
end
if
user_ids
.
present?
# we should handle the idea of existing members where users are passed as users - https://gitlab.com/gitlab-org/gitlab/-/issues/352617
# the below will automatically discard invalid user_ids
# the below will automatically discard invalid user_ids
users
.
concat
(
User
.
id_in
(
user_ids
))
users
.
concat
(
User
.
id_in
(
user_ids
))
if
user_ids
.
present?
users
.
uniq!
# de-duplicate just in case as there is no controlling if user records and ids are sent multiple times
if
users
.
present?
# helps not have to perform another query per user id to see if the member exists later on when fetching
# helps not have to perform another query per user id to see if the member exists later on when fetching
existing_members
=
source
.
members_and_requesters
.
where
(
user_id:
user
_id
s
).
index_by
(
&
:user_id
)
# rubocop:disable CodeReuse/ActiveRecord
existing_members
=
source
.
members_and_requesters
.
where
(
user_id:
users
).
index_by
(
&
:user_id
)
# rubocop:disable CodeReuse/ActiveRecord
end
end
users
.
uniq!
# de-duplicate just in case as there is no controlling if user records and ids are sent multiple times
[
emails
,
users
,
existing_members
]
[
emails
,
users
,
existing_members
]
end
end
end
end
...
...
spec/support/shared_examples/models/member_shared_examples.rb
View file @
b933eef0
...
@@ -371,8 +371,7 @@ RSpec.shared_examples_for "bulk member creation" do
...
@@ -371,8 +371,7 @@ RSpec.shared_examples_for "bulk member creation" do
it
'returns a Member objects'
do
it
'returns a Member objects'
do
members
=
described_class
.
add_users
(
source
,
[
user1
,
user2
],
:maintainer
)
members
=
described_class
.
add_users
(
source
,
[
user1
,
user2
],
:maintainer
)
expect
(
members
).
to
be_a
Array
expect
(
members
.
map
(
&
:user
)).
to
contain_exactly
(
user1
,
user2
)
expect
(
members
.
size
).
to
eq
(
2
)
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_persisted
)
expect
(
members
).
to
all
(
be_persisted
)
end
end
...
@@ -394,20 +393,18 @@ RSpec.shared_examples_for "bulk member creation" do
...
@@ -394,20 +393,18 @@ RSpec.shared_examples_for "bulk member creation" do
end
end
context
'with de-duplication'
do
context
'with de-duplication'
do
it
'
with
the same user by id and user'
do
it
'
has
the same user by id and user'
do
members
=
described_class
.
add_users
(
source
,
[
user1
.
id
,
user1
,
user1
.
id
,
user2
,
user2
.
id
,
user2
],
:maintainer
)
members
=
described_class
.
add_users
(
source
,
[
user1
.
id
,
user1
,
user1
.
id
,
user2
,
user2
.
id
,
user2
],
:maintainer
)
expect
(
members
).
to
be_a
Array
expect
(
members
.
map
(
&
:user
)).
to
contain_exactly
(
user1
,
user2
)
expect
(
members
.
size
).
to
eq
(
2
)
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_persisted
)
expect
(
members
).
to
all
(
be_persisted
)
end
end
it
'
with
the same user sent more than once'
do
it
'
has
the same user sent more than once'
do
members
=
described_class
.
add_users
(
source
,
[
user1
,
user1
],
:maintainer
)
members
=
described_class
.
add_users
(
source
,
[
user1
,
user1
],
:maintainer
)
expect
(
members
).
to
be_a
Array
expect
(
members
.
map
(
&
:user
)).
to
contain_exactly
(
user1
)
expect
(
members
.
size
).
to
eq
(
1
)
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_persisted
)
expect
(
members
).
to
all
(
be_persisted
)
end
end
...
@@ -418,15 +415,35 @@ RSpec.shared_examples_for "bulk member creation" do
...
@@ -418,15 +415,35 @@ RSpec.shared_examples_for "bulk member creation" do
source
.
add_user
(
user1
,
:developer
)
source
.
add_user
(
user1
,
:developer
)
end
end
it
'supports existing users as expected'
do
it
'has the same user sent more than once with the member already existing'
do
expect
do
members
=
described_class
.
add_users
(
source
,
[
user1
,
user1
,
user2
],
:maintainer
)
expect
(
members
.
map
(
&
:user
)).
to
contain_exactly
(
user1
,
user2
)
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_persisted
)
end
.
to
change
{
Member
.
count
}.
by
(
1
)
end
it
'supports existing users as expected with user_ids passed'
do
user3
=
create
(
:user
)
user3
=
create
(
:user
)
expect
do
members
=
described_class
.
add_users
(
source
,
[
user1
.
id
,
user2
,
user3
.
id
],
:maintainer
)
members
=
described_class
.
add_users
(
source
,
[
user1
.
id
,
user2
,
user3
.
id
],
:maintainer
)
expect
(
members
.
map
(
&
:user
)).
to
contain_exactly
(
user1
,
user2
,
user3
)
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_persisted
)
end
.
to
change
{
Member
.
count
}.
by
(
2
)
end
expect
(
members
).
to
be_a
Array
it
'supports existing users as expected without user ids passed'
do
expect
(
members
.
size
).
to
eq
(
3
)
user3
=
create
(
:user
)
expect
do
members
=
described_class
.
add_users
(
source
,
[
user1
,
user2
,
user3
],
:maintainer
)
expect
(
members
.
map
(
&
:user
)).
to
contain_exactly
(
user1
,
user2
,
user3
)
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_a
(
member_type
))
expect
(
members
).
to
all
(
be_persisted
)
expect
(
members
).
to
all
(
be_persisted
)
end
.
to
change
{
Member
.
count
}.
by
(
2
)
end
end
end
end
...
...
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