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
Boxiang Sun
gitlab-ce
Commits
52733352
Commit
52733352
authored
May 24, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix forks creation when visibility level is restricted
parent
9a10205a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
1 deletion
+48
-1
CHANGELOG
CHANGELOG
+1
-0
app/services/projects/fork_service.rb
app/services/projects/fork_service.rb
+13
-1
lib/gitlab/visibility_level.rb
lib/gitlab/visibility_level.rb
+7
-0
spec/services/projects/fork_service_spec.rb
spec/services/projects/fork_service_spec.rb
+27
-0
No files found.
CHANGELOG
View file @
52733352
Please view this file on the master branch, on stable branches it's out of date.
Please view this file on the master branch, on stable branches it's out of date.
v 8.9.0 (unreleased)
v 8.9.0 (unreleased)
- Allow forking projects with restricted visibility level
- Redesign navigation for project pages
- Redesign navigation for project pages
- Use gitlab-shell v3.0.0
- Use gitlab-shell v3.0.0
- Changed the Slack build message to use the singular duration if necessary (Aran Koning)
- Changed the Slack build message to use the singular duration if necessary (Aran Koning)
...
...
app/services/projects/fork_service.rb
View file @
52733352
...
@@ -3,7 +3,7 @@ module Projects
...
@@ -3,7 +3,7 @@ module Projects
def
execute
def
execute
new_params
=
{
new_params
=
{
forked_from_project_id:
@project
.
id
,
forked_from_project_id:
@project
.
id
,
visibility_level:
@project
.
visibility_level
,
visibility_level:
allowed_
visibility_level
,
description:
@project
.
description
,
description:
@project
.
description
,
name:
@project
.
name
,
name:
@project
.
name
,
path:
@project
.
path
,
path:
@project
.
path
,
...
@@ -19,5 +19,17 @@ module Projects
...
@@ -19,5 +19,17 @@ module Projects
new_project
=
CreateService
.
new
(
current_user
,
new_params
).
execute
new_project
=
CreateService
.
new
(
current_user
,
new_params
).
execute
new_project
new_project
end
end
private
def
allowed_visibility_level
project_level
=
@project
.
visibility_level
if
Gitlab
::
VisibilityLevel
.
non_restricted_level?
(
project_level
)
project_level
else
Gitlab
::
VisibilityLevel
.
highest_allowed_level
end
end
end
end
end
end
lib/gitlab/visibility_level.rb
View file @
52733352
...
@@ -32,6 +32,13 @@ module Gitlab
...
@@ -32,6 +32,13 @@ module Gitlab
}
}
end
end
def
highest_allowed_level
restricted_levels
=
current_application_settings
.
restricted_visibility_levels
allowed_levels
=
self
.
values
-
restricted_levels
allowed_levels
.
max
||
PRIVATE
end
def
allowed_for?
(
user
,
level
)
def
allowed_for?
(
user
,
level
)
user
.
is_admin?
||
allowed_level?
(
level
.
to_i
)
user
.
is_admin?
||
allowed_level?
(
level
.
to_i
)
end
end
...
...
spec/services/projects/fork_service_spec.rb
View file @
52733352
...
@@ -42,6 +42,33 @@ describe Projects::ForkService, services: true do
...
@@ -42,6 +42,33 @@ describe Projects::ForkService, services: true do
expect
(
@to_project
.
builds_enabled?
).
to
be_truthy
expect
(
@to_project
.
builds_enabled?
).
to
be_truthy
end
end
end
end
context
"when project has restricted visibility level"
do
context
"and only one visibility level is restricted"
do
before
do
@from_project
.
update_attributes
(
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
INTERNAL
])
end
it
"creates fork with highest allowed level"
do
forked_project
=
fork_project
(
@from_project
,
@to_user
)
expect
(
forked_project
.
visibility_level
).
to
eq
(
Gitlab
::
VisibilityLevel
::
PUBLIC
)
end
end
context
"and all visibility levels are restricted"
do
before
do
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
,
Gitlab
::
VisibilityLevel
::
INTERNAL
,
Gitlab
::
VisibilityLevel
::
PRIVATE
])
end
it
"creates fork with private visibility levels"
do
forked_project
=
fork_project
(
@from_project
,
@to_user
)
expect
(
forked_project
.
visibility_level
).
to
eq
(
Gitlab
::
VisibilityLevel
::
PRIVATE
)
end
end
end
end
end
describe
:fork_to_namespace
do
describe
:fork_to_namespace
do
...
...
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