BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0aa7e3b2
Commit
0aa7e3b2
authored
Feb 07, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'refresh-permissions-when-moving-projects' into 'master'
Refresh authorizations when transferring projects See merge request !9029
parent
60f299b5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
3 deletions
+75
-3
group.rb
app/models/group.rb
+6
-1
namespace.rb
app/models/namespace.rb
+4
-0
transfer_service.rb
app/services/projects/transfer_service.rb
+15
-2
refresh-permissions-when-moving-projects.yml
...s/unreleased/refresh-permissions-when-moving-projects.yml
+4
-0
group_spec.rb
spec/models/group_spec.rb
+13
-0
namespace_spec.rb
spec/models/namespace_spec.rb
+7
-0
transfer_service_spec.rb
spec/services/projects/transfer_service_spec.rb
+26
-0
No files found.
app/models/group.rb
View file @
0aa7e3b2
...
...
@@ -197,7 +197,12 @@ class Group < Namespace
end
def
refresh_members_authorized_projects
UserProjectAccessChangedService
.
new
(
users_with_parents
.
pluck
(
:id
)).
execute
UserProjectAccessChangedService
.
new
(
user_ids_for_project_authorizations
).
execute
end
def
user_ids_for_project_authorizations
users_with_parents
.
pluck
(
:id
)
end
def
members_with_parents
...
...
app/models/namespace.rb
View file @
0aa7e3b2
...
...
@@ -194,6 +194,10 @@ class Namespace < ActiveRecord::Base
@parents
||=
parent
?
parent
.
parents
+
[
parent
]
:
[]
end
def
user_ids_for_project_authorizations
[
owner_id
]
end
private
def
repository_storage_paths
...
...
app/services/projects/transfer_service.rb
View file @
0aa7e3b2
...
...
@@ -25,9 +25,10 @@ module Projects
end
def
transfer
(
project
,
new_namespace
)
old_namespace
=
project
.
namespace
Project
.
transaction
do
old_path
=
project
.
path_with_namespace
old_namespace
=
project
.
namespace
old_group
=
project
.
group
new_path
=
File
.
join
(
new_namespace
.
try
(
:path
)
||
''
,
project
.
path
)
...
...
@@ -67,8 +68,11 @@ module Projects
project
.
old_path_with_namespace
=
old_path
SystemHooksService
.
new
.
execute_hooks_for
(
project
,
:transfer
)
true
end
refresh_permissions
(
old_namespace
,
new_namespace
)
true
end
def
allowed_transfer?
(
current_user
,
project
,
namespace
)
...
...
@@ -77,5 +81,14 @@ module Projects
namespace
.
id
!=
project
.
namespace_id
&&
current_user
.
can?
(
:create_projects
,
namespace
)
end
def
refresh_permissions
(
old_namespace
,
new_namespace
)
# This ensures we only schedule 1 job for every user that has access to
# the namespaces.
user_ids
=
old_namespace
.
user_ids_for_project_authorizations
|
new_namespace
.
user_ids_for_project_authorizations
UserProjectAccessChangedService
.
new
(
user_ids
).
execute
end
end
end
changelogs/unreleased/refresh-permissions-when-moving-projects.yml
0 → 100644
View file @
0aa7e3b2
---
title
:
Refresh authorizations when transferring projects
merge_request
:
author
:
spec/models/group_spec.rb
View file @
0aa7e3b2
...
...
@@ -294,4 +294,17 @@ describe Group, models: true do
expect
(
group
.
members_with_parents
).
to
include
(
master
)
end
end
describe
'#user_ids_for_project_authorizations'
do
it
'returns the user IDs for which to refresh authorizations'
do
master
=
create
(
:user
)
developer
=
create
(
:user
)
group
.
add_user
(
master
,
GroupMember
::
MASTER
)
group
.
add_user
(
developer
,
GroupMember
::
DEVELOPER
)
expect
(
group
.
user_ids_for_project_authorizations
).
to
include
(
master
.
id
,
developer
.
id
)
end
end
end
spec/models/namespace_spec.rb
View file @
0aa7e3b2
...
...
@@ -202,4 +202,11 @@ describe Namespace, models: true do
expect
(
group
.
parents
).
to
eq
([])
end
end
describe
'#user_ids_for_project_authorizations'
do
it
'returns the user IDs for which to refresh authorizations'
do
expect
(
namespace
.
user_ids_for_project_authorizations
).
to
eq
([
namespace
.
owner_id
])
end
end
end
spec/services/projects/transfer_service_spec.rb
View file @
0aa7e3b2
...
...
@@ -81,4 +81,30 @@ describe Projects::TransferService, services: true do
transfer_project
(
project
,
user
,
group
)
end
end
describe
'refreshing project authorizations'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:owner
)
{
project
.
namespace
.
owner
}
let
(
:group_member
)
{
create
(
:user
)
}
before
do
group
.
add_user
(
owner
,
GroupMember
::
MASTER
)
group
.
add_user
(
group_member
,
GroupMember
::
DEVELOPER
)
end
it
'refreshes the permissions of the old and new namespace'
do
transfer_project
(
project
,
owner
,
group
)
expect
(
group_member
.
authorized_projects
).
to
include
(
project
)
expect
(
owner
.
authorized_projects
).
to
include
(
project
)
end
it
'only schedules a single job for every user'
do
expect
(
UserProjectAccessChangedService
).
to
receive
(
:new
).
with
([
owner
.
id
,
group_member
.
id
]).
and_call_original
transfer_project
(
project
,
owner
,
group
)
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