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
Jérome Perrin
gitlab-ce
Commits
f0ba0018
Commit
f0ba0018
authored
Dec 28, 2016
by
Adam Niedzielski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache project authorizations even when user has access to zero projects
parent
0499431a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
7 deletions
+36
-7
app/services/users/refresh_authorized_projects_service.rb
app/services/users/refresh_authorized_projects_service.rb
+1
-1
changelogs/unreleased/26126-cache-even-when-no-projects.yml
changelogs/unreleased/26126-cache-even-when-no-projects.yml
+4
-0
spec/services/users/refresh_authorized_projects_service_spec.rb
...ervices/users/refresh_authorized_projects_service_spec.rb
+31
-6
No files found.
app/services/users/refresh_authorized_projects_service.rb
View file @
f0ba0018
...
...
@@ -74,7 +74,7 @@ module Users
# remove - The IDs of the authorization rows to remove.
# add - Rows to insert in the form `[user id, project id, access level]`
def
update_authorizations
(
remove
=
[],
add
=
[])
return
if
remove
.
empty?
&&
add
.
empty?
return
if
remove
.
empty?
&&
add
.
empty?
&&
user
.
authorized_projects_populated
User
.
transaction
do
user
.
remove_project_authorizations
(
remove
)
unless
remove
.
empty?
...
...
changelogs/unreleased/26126-cache-even-when-no-projects.yml
0 → 100644
View file @
f0ba0018
---
title
:
Cache project authorizations even when user has access to zero projects
merge_request
:
8327
author
:
spec/services/users/refresh_authorized_projects_service_spec.rb
View file @
f0ba0018
...
...
@@ -54,12 +54,37 @@ describe Users::RefreshAuthorizedProjectsService do
end
describe
'#update_authorizations'
do
it
'does nothing
when there are no rows to add and remove'
do
expect
(
user
).
not_to
receive
(
:remove_project_authorizations
)
expect
(
ProjectAuthorization
).
not_to
receive
(
:inser
t_authorizations
)
expect
(
user
).
not_to
receive
(
:set_authorized_projects_column
)
context
'
when there are no rows to add and remove'
do
it
'does not change authorizations'
do
expect
(
user
).
not_to
receive
(
:remove_projec
t_authorizations
)
expect
(
ProjectAuthorization
).
not_to
receive
(
:insert_authorizations
)
service
.
update_authorizations
([],
[])
service
.
update_authorizations
([],
[])
end
context
'when the authorized projects column is not set'
do
before
do
user
.
update!
(
authorized_projects_populated:
nil
)
end
it
'populates the authorized projects column'
do
service
.
update_authorizations
([],
[])
expect
(
user
.
authorized_projects_populated
).
to
eq
true
end
end
context
'when the authorized projects column is set'
do
before
do
user
.
update!
(
authorized_projects_populated:
true
)
end
it
'does nothing'
do
expect
(
user
).
not_to
receive
(
:set_authorized_projects_column
)
service
.
update_authorizations
([],
[])
end
end
end
it
'removes authorizations that should be removed'
do
...
...
@@ -84,7 +109,7 @@ describe Users::RefreshAuthorizedProjectsService do
it
'populates the authorized projects column'
do
# make sure we start with a nil value no matter what the default in the
# factory may be.
user
.
update
(
authorized_projects_populated:
nil
)
user
.
update
!
(
authorized_projects_populated:
nil
)
service
.
update_authorizations
([],
[[
user
.
id
,
project
.
id
,
Gitlab
::
Access
::
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