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
Tatuya Kamada
gitlab-ce
Commits
84e2be5a
Commit
84e2be5a
authored
Jun 15, 2016
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Turn Group#owners into a has_many association
This allows the owners to be eager loaded where needed.
parent
a4a85c26
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
app/models/group.rb
app/models/group.rb
+6
-4
spec/models/group_spec.rb
spec/models/group_spec.rb
+12
-0
No files found.
app/models/group.rb
View file @
84e2be5a
...
@@ -9,6 +9,12 @@ class Group < Namespace
...
@@ -9,6 +9,12 @@ class Group < Namespace
has_many
:group_members
,
dependent: :destroy
,
as: :source
,
class_name:
'GroupMember'
has_many
:group_members
,
dependent: :destroy
,
as: :source
,
class_name:
'GroupMember'
alias_method
:members
,
:group_members
alias_method
:members
,
:group_members
has_many
:users
,
->
{
where
(
members:
{
requested_at:
nil
})
},
through: :group_members
has_many
:users
,
->
{
where
(
members:
{
requested_at:
nil
})
},
through: :group_members
has_many
:owners
,
->
{
where
(
members:
{
access_level:
Gitlab
::
Access
::
OWNER
})
},
through: :group_members
,
source: :user
has_many
:project_group_links
,
dependent: :destroy
has_many
:project_group_links
,
dependent: :destroy
has_many
:shared_projects
,
through: :project_group_links
,
source: :project
has_many
:shared_projects
,
through: :project_group_links
,
source: :project
has_many
:notification_settings
,
dependent: :destroy
,
as: :source
has_many
:notification_settings
,
dependent: :destroy
,
as: :source
...
@@ -88,10 +94,6 @@ class Group < Namespace
...
@@ -88,10 +94,6 @@ class Group < Namespace
end
end
end
end
def
owners
@owners
||=
group_members
.
owners
.
includes
(
:user
).
map
(
&
:user
)
end
def
add_users
(
user_ids
,
access_level
,
current_user
=
nil
)
def
add_users
(
user_ids
,
access_level
,
current_user
=
nil
)
user_ids
.
each
do
|
user_id
|
user_ids
.
each
do
|
user_id
|
Member
.
add_user
(
self
.
group_members
,
user_id
,
access_level
,
current_user
)
Member
.
add_user
(
self
.
group_members
,
user_id
,
access_level
,
current_user
)
...
...
spec/models/group_spec.rb
View file @
84e2be5a
...
@@ -158,6 +158,18 @@ describe Group, models: true do
...
@@ -158,6 +158,18 @@ describe Group, models: true do
it
{
expect
(
group
.
has_master?
(
@members
[
:requester
])).
to
be_falsey
}
it
{
expect
(
group
.
has_master?
(
@members
[
:requester
])).
to
be_falsey
}
end
end
describe
'#owners'
do
let
(
:owner
)
{
create
(
:user
)
}
let
(
:developer
)
{
create
(
:user
)
}
it
'returns the owners of a Group'
do
group
.
add_owner
(
owner
)
group
.
add_developer
(
developer
)
expect
(
group
.
owners
).
to
eq
([
owner
])
end
end
def
setup_group_members
(
group
)
def
setup_group_members
(
group
)
members
=
{
members
=
{
owner:
create
(
:user
),
owner:
create
(
:user
),
...
...
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