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
71feb757
Commit
71feb757
authored
Jun 20, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix-permissions' into 'master'
Fix permissions Fixes #1358
parents
c83004a0
0771109b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
25 deletions
+66
-25
app/models/project_team.rb
app/models/project_team.rb
+15
-4
spec/models/project_team_spec.rb
spec/models/project_team_spec.rb
+51
-21
No files found.
app/models/project_team.rb
View file @
71feb757
...
...
@@ -118,19 +118,30 @@ class ProjectTeam
end
def
guest?
(
user
)
find_tm
(
user
.
id
).
try
(
:access_fiel
d
)
==
Gitlab
::
Access
::
GUEST
max_tm_access
(
user
.
i
d
)
==
Gitlab
::
Access
::
GUEST
end
def
reporter?
(
user
)
find_tm
(
user
.
id
).
try
(
:access_fiel
d
)
==
Gitlab
::
Access
::
REPORTER
max_tm_access
(
user
.
i
d
)
==
Gitlab
::
Access
::
REPORTER
end
def
developer?
(
user
)
find_tm
(
user
.
id
).
try
(
:access_fiel
d
)
==
Gitlab
::
Access
::
DEVELOPER
max_tm_access
(
user
.
i
d
)
==
Gitlab
::
Access
::
DEVELOPER
end
def
master?
(
user
)
find_tm
(
user
.
id
).
try
(
:access_field
)
==
Gitlab
::
Access
::
MASTER
max_tm_access
(
user
.
id
)
==
Gitlab
::
Access
::
MASTER
end
def
max_tm_access
(
user_id
)
access
=
[]
access
<<
project
.
users_projects
.
find_by
(
user_id:
user_id
).
try
(
:access_field
)
if
group
access
<<
group
.
users_groups
.
find_by
(
user_id:
user_id
).
try
(
:access_field
)
end
access
.
compact
.
max
end
private
...
...
spec/models/project_team_spec.rb
View file @
71feb757
require
"spec_helper"
describe
ProjectTeam
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
group:
group
)
}
let
(
:master
)
{
create
(
:user
)
}
let
(
:reporter
)
{
create
(
:user
)
}
let
(
:guest
)
{
create
(
:user
)
}
let
(
:nonmember
)
{
create
(
:user
)
}
context
'personal project'
do
let
(
:project
)
{
create
(
:empty_project
)
}
before
do
project
.
team
<<
[
master
,
:master
]
project
.
team
<<
[
reporter
,
:reporter
]
project
.
team
<<
[
guest
,
:guest
]
end
describe
'members collection'
do
it
{
project
.
team
.
masters
.
should
include
(
master
)
}
it
{
project
.
team
.
masters
.
should_not
include
(
guest
)
}
it
{
project
.
team
.
masters
.
should_not
include
(
reporter
)
}
it
{
project
.
team
.
masters
.
should_not
include
(
nonmember
)
}
end
describe
'access methods'
do
it
{
project
.
team
.
master?
(
master
).
should
be_true
}
it
{
project
.
team
.
master?
(
guest
).
should
be_false
}
it
{
project
.
team
.
master?
(
reporter
).
should
be_false
}
it
{
project
.
team
.
master?
(
nonmember
).
should
be_false
}
end
end
context
'group project'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
group:
group
)
}
before
do
group
.
add_user
(
master
,
Gitlab
::
Access
::
MASTER
)
group
.
add_user
(
reporter
,
Gitlab
::
Access
::
REPORTER
)
group
.
add_user
(
guest
,
Gitlab
::
Access
::
GUEST
)
# Add group guest as master to this project
# to test project access priority over group members
# If user is a group and a project member - GitLab uses highest permission
# So we add group guest as master and add group master as guest
# to this project to test highest access
project
.
team
<<
[
guest
,
:master
]
project
.
team
<<
[
master
,
:guest
]
end
describe
'members collection'
do
it
{
project
.
team
.
reporters
.
should
include
(
reporter
)
}
it
{
project
.
team
.
masters
.
should
include
(
master
)
}
it
{
project
.
team
.
masters
.
should
include
(
guest
)
}
it
{
project
.
team
.
masters
.
should_not
include
(
reporter
)
}
...
...
@@ -27,10 +55,12 @@ describe ProjectTeam do
end
describe
'access methods'
do
it
{
project
.
team
.
reporter?
(
reporter
).
should
be_true
}
it
{
project
.
team
.
master?
(
master
).
should
be_true
}
it
{
project
.
team
.
master?
(
guest
).
should
be_true
}
it
{
project
.
team
.
master?
(
reporter
).
should
be_false
}
it
{
project
.
team
.
master?
(
nonmember
).
should
be_false
}
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