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
99c02ed5
Commit
99c02ed5
authored
Aug 01, 2016
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only use RequestStore in ProjectTeam#max_member_access_for_user if it is active
parent
aa727434
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
42 deletions
+68
-42
app/models/project_team.rb
app/models/project_team.rb
+7
-2
spec/models/project_team_spec.rb
spec/models/project_team_spec.rb
+61
-40
No files found.
app/models/project_team.rb
View file @
99c02ed5
...
@@ -138,8 +138,13 @@ class ProjectTeam
...
@@ -138,8 +138,13 @@ class ProjectTeam
def
max_member_access_for_user_ids
(
user_ids
)
def
max_member_access_for_user_ids
(
user_ids
)
user_ids
=
user_ids
.
uniq
user_ids
=
user_ids
.
uniq
key
=
"max_member_access:
#{
project
.
id
}
"
key
=
"max_member_access:
#{
project
.
id
}
"
RequestStore
.
store
[
key
]
||=
{}
access
=
RequestStore
.
store
[
key
]
access
=
{}
if
RequestStore
.
active?
RequestStore
.
store
[
key
]
||=
{}
access
=
RequestStore
.
store
[
key
]
end
# Lookup only the IDs we need
# Lookup only the IDs we need
user_ids
=
user_ids
-
access
.
keys
user_ids
=
user_ids
-
access
.
keys
...
...
spec/models/project_team_spec.rb
View file @
99c02ed5
...
@@ -199,48 +199,69 @@ describe ProjectTeam, models: true do
...
@@ -199,48 +199,69 @@ describe ProjectTeam, models: true do
end
end
end
end
describe
"#max_member_access_for_users"
do
shared_examples_for
"#max_member_access_for_users"
do
|
enable_request_store
|
it
'returns correct roles for different users'
do
describe
"#max_member_access_for_users"
do
master
=
create
(
:user
)
before
do
reporter
=
create
(
:user
)
RequestStore
.
begin!
if
enable_request_store
promoted_guest
=
create
(
:user
)
end
guest
=
create
(
:user
)
project
=
create
(
:project
)
project
.
team
<<
[
master
,
:master
]
after
do
project
.
team
<<
[
reporter
,
:reporter
]
if
enable_request_store
project
.
team
<<
[
promoted_guest
,
:guest
]
RequestStore
.
end!
project
.
team
<<
[
guest
,
:guest
]
RequestStore
.
clear!
end
end
group
=
create
(
:group
)
it
'returns correct roles for different users'
do
group_developer
=
create
(
:user
)
master
=
create
(
:user
)
second_developer
=
create
(
:user
)
reporter
=
create
(
:user
)
project
.
project_group_links
.
create
(
promoted_guest
=
create
(
:user
)
group:
group
,
guest
=
create
(
:user
)
group_access:
Gitlab
::
Access
::
DEVELOPER
)
project
=
create
(
:project
)
group
.
add_master
(
promoted_guest
)
project
.
team
<<
[
master
,
:master
]
group
.
add_developer
(
group_developer
)
project
.
team
<<
[
reporter
,
:reporter
]
group
.
add_developer
(
second_developer
)
project
.
team
<<
[
promoted_guest
,
:guest
]
project
.
team
<<
[
guest
,
:guest
]
second_group
=
create
(
:group
)
project
.
project_group_links
.
create
(
group
=
create
(
:group
)
group:
second_group
,
group_developer
=
create
(
:user
)
group_access:
Gitlab
::
Access
::
MASTER
)
second_developer
=
create
(
:user
)
second_group
.
add_master
(
second_developer
)
project
.
project_group_links
.
create
(
group:
group
,
users
=
[
master
,
reporter
,
promoted_guest
,
guest
,
group_developer
,
second_developer
].
map
(
&
:id
)
group_access:
Gitlab
::
Access
::
DEVELOPER
)
expected
=
{
group
.
add_master
(
promoted_guest
)
master
.
id
=>
Gitlab
::
Access
::
MASTER
,
group
.
add_developer
(
group_developer
)
reporter
.
id
=>
Gitlab
::
Access
::
REPORTER
,
group
.
add_developer
(
second_developer
)
promoted_guest
.
id
=>
Gitlab
::
Access
::
DEVELOPER
,
guest
.
id
=>
Gitlab
::
Access
::
GUEST
,
second_group
=
create
(
:group
)
group_developer
.
id
=>
Gitlab
::
Access
::
DEVELOPER
,
project
.
project_group_links
.
create
(
second_developer
.
id
=>
Gitlab
::
Access
::
MASTER
group:
second_group
,
}
group_access:
Gitlab
::
Access
::
MASTER
)
second_group
.
add_master
(
second_developer
)
expect
(
project
.
team
.
max_member_access_for_user_ids
(
users
)).
to
eq
(
expected
)
users
=
[
master
,
reporter
,
promoted_guest
,
guest
,
group_developer
,
second_developer
].
map
(
&
:id
)
expected
=
{
master
.
id
=>
Gitlab
::
Access
::
MASTER
,
reporter
.
id
=>
Gitlab
::
Access
::
REPORTER
,
promoted_guest
.
id
=>
Gitlab
::
Access
::
DEVELOPER
,
guest
.
id
=>
Gitlab
::
Access
::
GUEST
,
group_developer
.
id
=>
Gitlab
::
Access
::
DEVELOPER
,
second_developer
.
id
=>
Gitlab
::
Access
::
MASTER
}
expect
(
project
.
team
.
max_member_access_for_user_ids
(
users
)).
to
eq
(
expected
)
end
end
end
end
end
describe
'#max_member_access_for_users with RequestStore'
do
it_behaves_like
"#max_member_access_for_users"
,
true
end
describe
'#max_member_access_for_users without RequestStore'
do
it_behaves_like
"#max_member_access_for_users"
,
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