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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
c6960ded
Commit
c6960ded
authored
Apr 21, 2017
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor add_users method for project and group
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
c76812c7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
53 additions
and
32 deletions
+53
-32
app/models/group.rb
app/models/group.rb
+1
-1
app/models/member.rb
app/models/member.rb
+16
-12
app/models/members/group_member.rb
app/models/members/group_member.rb
+0
-12
app/models/members/project_member.rb
app/models/members/project_member.rb
+2
-2
app/models/project_team.rb
app/models/project_team.rb
+2
-2
changelogs/unreleased/dz-cleanup-add-users.yml
changelogs/unreleased/dz-cleanup-add-users.yml
+4
-0
spec/controllers/projects/labels_controller_spec.rb
spec/controllers/projects/labels_controller_spec.rb
+1
-1
spec/models/member_spec.rb
spec/models/member_spec.rb
+25
-0
spec/models/members/group_member_spec.rb
spec/models/members/group_member_spec.rb
+2
-2
No files found.
app/models/group.rb
View file @
c6960ded
...
@@ -125,7 +125,7 @@ class Group < Namespace
...
@@ -125,7 +125,7 @@ class Group < Namespace
end
end
def
add_users
(
users
,
access_level
,
current_user:
nil
,
expires_at:
nil
)
def
add_users
(
users
,
access_level
,
current_user:
nil
,
expires_at:
nil
)
GroupMember
.
add_users
_to_group
(
GroupMember
.
add_users
(
self
,
self
,
users
,
users
,
access_level
,
access_level
,
...
...
app/models/member.rb
View file @
c6960ded
...
@@ -151,6 +151,22 @@ class Member < ActiveRecord::Base
...
@@ -151,6 +151,22 @@ class Member < ActiveRecord::Base
member
member
end
end
def
add_users
(
source
,
users
,
access_level
,
current_user:
nil
,
expires_at:
nil
)
return
[]
unless
users
.
present?
self
.
transaction
do
users
.
map
do
|
user
|
add_user
(
source
,
user
,
access_level
,
current_user:
current_user
,
expires_at:
expires_at
)
end
end
end
def
access_levels
def
access_levels
Gitlab
::
Access
.
sym_options
Gitlab
::
Access
.
sym_options
end
end
...
@@ -173,18 +189,6 @@ class Member < ActiveRecord::Base
...
@@ -173,18 +189,6 @@ class Member < ActiveRecord::Base
# There is no current user for bulk actions, in which case anything is allowed
# There is no current user for bulk actions, in which case anything is allowed
!
current_user
||
current_user
.
can?
(
:"update_
#{
member
.
type
.
underscore
}
"
,
member
)
!
current_user
||
current_user
.
can?
(
:"update_
#{
member
.
type
.
underscore
}
"
,
member
)
end
end
def
add_users_to_source
(
source
,
users
,
access_level
,
current_user:
nil
,
expires_at:
nil
)
users
.
each
do
|
user
|
add_user
(
source
,
user
,
access_level
,
current_user:
current_user
,
expires_at:
expires_at
)
end
end
end
end
def
real_source_type
def
real_source_type
...
...
app/models/members/group_member.rb
View file @
c6960ded
...
@@ -21,18 +21,6 @@ class GroupMember < Member
...
@@ -21,18 +21,6 @@ class GroupMember < Member
Gitlab
::
Access
.
sym_options_with_owner
Gitlab
::
Access
.
sym_options_with_owner
end
end
def
self
.
add_users_to_group
(
group
,
users
,
access_level
,
current_user:
nil
,
expires_at:
nil
)
self
.
transaction
do
add_users_to_source
(
group
,
users
,
access_level
,
current_user:
current_user
,
expires_at:
expires_at
)
end
end
def
group
def
group
source
source
end
end
...
...
app/models/members/project_member.rb
View file @
c6960ded
...
@@ -16,7 +16,7 @@ class ProjectMember < Member
...
@@ -16,7 +16,7 @@ class ProjectMember < Member
before_destroy
:delete_member_todos
before_destroy
:delete_member_todos
class
<<
self
class
<<
self
# Add users to project
team
s with passed access option
# Add users to projects with passed access option
#
#
# access can be an integer representing a access code
# access can be an integer representing a access code
# or symbol like :master representing role
# or symbol like :master representing role
...
@@ -39,7 +39,7 @@ class ProjectMember < Member
...
@@ -39,7 +39,7 @@ class ProjectMember < Member
project_ids
.
each
do
|
project_id
|
project_ids
.
each
do
|
project_id
|
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
add_users
_to_source
(
add_users
(
project
,
project
,
users
,
users
,
access_level
,
access_level
,
...
...
app/models/project_team.rb
View file @
c6960ded
...
@@ -50,8 +50,8 @@ class ProjectTeam
...
@@ -50,8 +50,8 @@ class ProjectTeam
end
end
def
add_users
(
users
,
access_level
,
current_user:
nil
,
expires_at:
nil
)
def
add_users
(
users
,
access_level
,
current_user:
nil
,
expires_at:
nil
)
ProjectMember
.
add_users
_to_projects
(
ProjectMember
.
add_users
(
[
project
.
id
]
,
project
,
users
,
users
,
access_level
,
access_level
,
current_user:
current_user
,
current_user:
current_user
,
...
...
changelogs/unreleased/dz-cleanup-add-users.yml
0 → 100644
View file @
c6960ded
---
title
:
Refactor add_users method for project and group
merge_request
:
10850
author
:
spec/controllers/projects/labels_controller_spec.rb
View file @
c6960ded
...
@@ -127,7 +127,7 @@ describe Projects::LabelsController do
...
@@ -127,7 +127,7 @@ describe Projects::LabelsController do
context
'group owner'
do
context
'group owner'
do
before
do
before
do
GroupMember
.
add_users
_to_group
(
group
,
[
user
],
:owner
)
GroupMember
.
add_users
(
group
,
[
user
],
:owner
)
end
end
it
'gives access'
do
it
'gives access'
do
...
...
spec/models/member_spec.rb
View file @
c6960ded
...
@@ -386,6 +386,31 @@ describe Member, models: true do
...
@@ -386,6 +386,31 @@ describe Member, models: true do
end
end
end
end
describe
'.add_users'
do
%w[project group]
.
each
do
|
source_type
|
context
"when source is a
#{
source_type
}
"
do
let!
(
:source
)
{
create
(
source_type
,
:public
,
:access_requestable
)
}
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:admin
)
{
create
(
:admin
)
}
it
'returns a <Source>Member objects'
do
members
=
described_class
.
add_users
(
source
,
[
user
],
:master
)
expect
(
members
).
to
be_a
Array
expect
(
members
.
first
).
to
be_a
"
#{
source_type
.
classify
}
Member"
.
constantize
expect
(
members
.
first
).
to
be_persisted
end
it
'returns an empty array'
do
members
=
described_class
.
add_users
(
source
,
[],
:master
)
expect
(
members
).
to
be_a
Array
expect
(
members
).
to
be_empty
end
end
end
end
describe
'#accept_request'
do
describe
'#accept_request'
do
let
(
:member
)
{
create
(
:project_member
,
requested_at:
Time
.
now
.
utc
)
}
let
(
:member
)
{
create
(
:project_member
,
requested_at:
Time
.
now
.
utc
)
}
...
...
spec/models/members/group_member_spec.rb
View file @
c6960ded
...
@@ -13,12 +13,12 @@ describe GroupMember, models: true do
...
@@ -13,12 +13,12 @@ describe GroupMember, models: true do
end
end
end
end
describe
'.add_users
_to_group
'
do
describe
'.add_users'
do
it
'adds the given users to the given group'
do
it
'adds the given users to the given group'
do
group
=
create
(
:group
)
group
=
create
(
:group
)
users
=
create_list
(
:user
,
2
)
users
=
create_list
(
:user
,
2
)
described_class
.
add_users
_to_group
(
described_class
.
add_users
(
group
,
group
,
[
users
.
first
.
id
,
users
.
second
],
[
users
.
first
.
id
,
users
.
second
],
described_class
::
MASTER
described_class
::
MASTER
...
...
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