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
2ea5ef0b
Commit
2ea5ef0b
authored
Nov 21, 2016
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update ProjectTeam#fetch_members to use project authorizations
parent
747959a8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
68 deletions
+32
-68
app/models/project.rb
app/models/project.rb
+1
-0
app/models/project_team.rb
app/models/project_team.rb
+7
-53
changelogs/unreleased/fix-drop-project-authorized-for-user.yml
...elogs/unreleased/fix-drop-project-authorized-for-user.yml
+4
-0
db/fixtures/development/06_teams.rb
db/fixtures/development/06_teams.rb
+19
-14
spec/models/project_team_spec.rb
spec/models/project_team_spec.rb
+1
-1
No files found.
app/models/project.rb
View file @
2ea5ef0b
...
...
@@ -127,6 +127,7 @@ class Project < ActiveRecord::Base
has_many
:protected_branches
,
dependent: :destroy
has_many
:project_authorizations
,
dependent: :destroy
has_many
:authorized_users
,
through: :project_authorizations
,
source: :user
,
class_name:
'User'
has_many
:project_members
,
->
{
where
(
requested_at:
nil
)
},
dependent: :destroy
,
as: :source
alias_method
:members
,
:project_members
has_many
:users
,
through: :project_members
...
...
app/models/project_team.rb
View file @
2ea5ef0b
...
...
@@ -80,19 +80,19 @@ class ProjectTeam
alias_method
:users
,
:members
def
guests
@guests
||=
fetch_members
(
:guests
)
@guests
||=
fetch_members
(
Gitlab
::
Access
::
GUEST
)
end
def
reporters
@reporters
||=
fetch_members
(
:reporters
)
@reporters
||=
fetch_members
(
Gitlab
::
Access
::
REPORTER
)
end
def
developers
@developers
||=
fetch_members
(
:developers
)
@developers
||=
fetch_members
(
Gitlab
::
Access
::
DEVELOPER
)
end
def
masters
@masters
||=
fetch_members
(
:masters
)
@masters
||=
fetch_members
(
Gitlab
::
Access
::
MASTER
)
end
def
import
(
source_project
,
current_user
=
nil
)
...
...
@@ -185,59 +185,13 @@ class ProjectTeam
private
def
fetch_members
(
level
=
nil
)
project_members
=
project
.
memb
ers
group_members
=
group
?
group
.
members
:
[]
members
=
project
.
authorized_us
ers
members
=
members
.
where
(
project_authorizations:
{
access_level:
level
})
if
level
if
level
project_members
=
project_members
.
public_send
(
level
)
group_members
=
group_members
.
public_send
(
level
)
if
group
end
user_ids
=
project_members
.
pluck
(
:user_id
)
invited_members
=
fetch_invited_members
(
level
)
user_ids
.
push
(
*
invited_members
.
map
(
&
:user_id
))
if
invited_members
.
any?
user_ids
.
push
(
*
group_members
.
pluck
(
:user_id
))
if
group
User
.
where
(
id:
user_ids
)
members
end
def
group
project
.
group
end
def
project_shared_with_group?
project
.
invited_groups
.
any?
&&
project
.
allowed_to_share_with_group?
end
def
fetch_invited_members
(
level
=
nil
)
invited_members
=
[]
return
invited_members
unless
project_shared_with_group?
project
.
project_group_links
.
includes
(
group:
[
:group_members
]).
each
do
|
link
|
invited_group_members
=
link
.
group
.
members
if
level
numeric_level
=
GroupMember
.
access_level_roles
[
level
.
to_s
.
singularize
.
titleize
]
# If we're asked for a level that's higher than the group's access,
# there's nothing left to do
next
if
numeric_level
>
link
.
group_access
# Make sure we include everyone _above_ the requested level as well
invited_group_members
=
if
numeric_level
==
link
.
group_access
invited_group_members
.
where
(
"access_level >= ?"
,
link
.
group_access
)
else
invited_group_members
.
public_send
(
level
)
end
end
invited_members
<<
invited_group_members
end
invited_members
.
flatten
.
compact
end
end
changelogs/unreleased/fix-drop-project-authorized-for-user.yml
0 → 100644
View file @
2ea5ef0b
---
title
:
Use authorized projects in ProjectTeam
merge_request
:
author
:
db/fixtures/development/06_teams.rb
View file @
2ea5ef0b
Gitlab
::
Seeder
.
quiet
do
Group
.
all
.
each
do
|
group
|
User
.
all
.
sample
(
4
).
each
do
|
user
|
if
group
.
add_user
(
user
,
Gitlab
::
Access
.
values
.
sample
).
persisted?
print
'.'
else
print
'F'
require
'sidekiq/testing'
require
'./db/fixtures/support/serialized_transaction'
Sidekiq
::
Testing
.
inline!
do
Gitlab
::
Seeder
.
quiet
do
Group
.
all
.
each
do
|
group
|
User
.
all
.
sample
(
4
).
each
do
|
user
|
if
group
.
add_user
(
user
,
Gitlab
::
Access
.
values
.
sample
).
persisted?
print
'.'
else
print
'F'
end
end
end
end
Project
.
all
.
each
do
|
project
|
User
.
all
.
sample
(
4
).
each
do
|
user
|
if
project
.
team
<<
[
user
,
Gitlab
::
Access
.
values
.
sample
]
print
'.'
else
print
'F'
Project
.
all
.
each
do
|
project
|
User
.
all
.
sample
(
4
).
each
do
|
user
|
if
project
.
team
<<
[
user
,
Gitlab
::
Access
.
values
.
sample
]
print
'.'
else
print
'F'
end
end
end
end
...
...
spec/models/project_team_spec.rb
View file @
2ea5ef0b
...
...
@@ -118,7 +118,7 @@ describe ProjectTeam, models: true do
context
'group project'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
group:
group
)
}
let
!
(
:project
)
{
create
(
:empty_project
,
group:
group
)
}
it
'returns project members'
do
group_member
=
create
(
:group_member
,
group:
group
)
...
...
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