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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
111ebe54
Commit
111ebe54
authored
Jul 06, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fork visibility level fix
parent
17446ff0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
106 additions
and
1 deletion
+106
-1
CHANGELOG
CHANGELOG
+1
-0
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+10
-0
app/helpers/visibility_level_helper.rb
app/helpers/visibility_level_helper.rb
+6
-0
app/views/projects/edit.html.haml
app/views/projects/edit.html.haml
+1
-1
app/views/shared/_visibility_radios.html.haml
app/views/shared/_visibility_radios.html.haml
+1
-0
lib/gitlab/visibility_level.rb
lib/gitlab/visibility_level.rb
+4
-0
spec/helpers/projects_helper_spec.rb
spec/helpers/projects_helper_spec.rb
+44
-0
spec/helpers/visibility_level_helper_spec.rb
spec/helpers/visibility_level_helper_spec.rb
+39
-0
No files found.
CHANGELOG
View file @
111ebe54
...
...
@@ -37,6 +37,7 @@ v 7.13.0 (unreleased)
- Correctly show anonymous authorized applications under Profile > Applications.
- Query Optimization in MySQL.
- Allow users to be blocked and unblocked via the API
- A fork can’t have a visibility level that is greater than the original project.
v 7.12.2
- Correctly show anonymous authorized applications under Profile > Applications.
...
...
app/helpers/projects_helper.rb
View file @
111ebe54
...
...
@@ -139,6 +139,16 @@ module ProjectsHelper
end
end
def
can_change_visibility_level?
(
project
,
current_user
)
return
false
unless
can?
(
current_user
,
:change_visibility_level
,
project
)
if
project
.
forked?
project
.
forked_from_project
.
visibility_level
>
Gitlab
::
VisibilityLevel
::
PRIVATE
else
true
end
end
private
def
get_project_nav_tabs
(
project
,
current_user
)
...
...
app/helpers/visibility_level_helper.rb
View file @
111ebe54
...
...
@@ -86,4 +86,10 @@ module VisibilityLevelHelper
def
default_snippet_visibility
current_application_settings
.
default_snippet_visibility
end
def
skip_level?
(
form_model
,
level
)
form_model
.
is_a?
(
Project
)
&&
form_model
.
forked?
&&
!
Gitlab
::
VisibilityLevel
.
allowed_fork_levels
(
form_model
.
forked_from_project
.
visibility_level
).
include?
(
level
)
end
end
app/views/projects/edit.html.haml
View file @
111ebe54
...
...
@@ -29,7 +29,7 @@
.col-sm-10
=
f
.
select
(
:default_branch
,
@repository
.
branch_names
,
{},
{
class:
'select2 select-wide'
})
=
render
'shared/visibility_level'
,
f:
f
,
visibility_level:
@project
.
visibility_level
,
can_change_visibility_level:
can
?
(
current_user
,
:change_visibility_level
,
@project
),
form_model:
@project
=
render
'shared/visibility_level'
,
f:
f
,
visibility_level:
@project
.
visibility_level
,
can_change_visibility_level:
can
_change_visibility_level?
(
@project
,
current_user
),
form_model:
@project
.form-group
=
f
.
label
:tag_list
,
"Tags"
,
class:
'control-label'
...
...
app/views/shared/_visibility_radios.html.haml
View file @
111ebe54
-
Gitlab
::
VisibilityLevel
.
values
.
each
do
|
level
|
-
next
if
skip_level?
(
form_model
,
level
)
.radio
-
restricted
=
restricted_visibility_levels
.
include?
(
level
)
=
form
.
label
"
#{
model_method
}
_
#{
level
}
"
do
...
...
lib/gitlab/visibility_level.rb
View file @
111ebe54
...
...
@@ -47,6 +47,10 @@ module Gitlab
def
valid_level?
(
level
)
options
.
has_value?
(
level
)
end
def
allowed_fork_levels
(
origin_level
)
[
PRIVATE
,
INTERNAL
,
PUBLIC
].
select
{
|
level
|
level
<=
origin_level
}
end
end
def
private?
...
...
spec/helpers/projects_helper_spec.rb
View file @
111ebe54
...
...
@@ -8,4 +8,48 @@ describe ProjectsHelper do
expect
(
project_status_css_class
(
"finished"
)).
to
eq
(
"success"
)
end
end
describe
"can_change_visibility_level?"
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:fork_project
)
do
fork_project
=
create
(
:forked_project_with_submodules
)
fork_project
.
build_forked_project_link
(
forked_to_project_id:
fork_project
.
id
,
forked_from_project_id:
project
.
id
)
fork_project
.
save
fork_project
end
let
(
:user
)
{
create
(
:user
)
}
it
"returns false if there are no approipriate permissions"
do
allow
(
helper
).
to
receive
(
:can?
)
{
false
}
expect
(
helper
.
can_change_visibility_level?
(
project
,
user
)).
to
be_falsey
end
it
"returns true if there are permissions and it is not fork"
do
allow
(
helper
).
to
receive
(
:can?
)
{
true
}
expect
(
helper
.
can_change_visibility_level?
(
project
,
user
)).
to
be_truthy
end
context
"forks"
do
it
"returns false if there are permissions and origin project is PRIVATE"
do
allow
(
helper
).
to
receive
(
:can?
)
{
true
}
project
.
update
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
expect
(
helper
.
can_change_visibility_level?
(
fork_project
,
user
)).
to
be_falsey
end
it
"returns true if there are permissions and origin project is INTERNAL"
do
allow
(
helper
).
to
receive
(
:can?
)
{
true
}
project
.
update
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
expect
(
helper
.
can_change_visibility_level?
(
fork_project
,
user
)).
to
be_truthy
end
end
end
end
spec/helpers/visibility_level_helper_spec.rb
View file @
111ebe54
...
...
@@ -72,4 +72,43 @@ describe VisibilityLevelHelper do
end
end
end
describe
"skip_level?"
do
describe
"forks"
do
let
(
:project
)
{
create
(
:project
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
}
let
(
:fork_project
)
{
create
(
:forked_project_with_submodules
)
}
before
do
fork_project
.
build_forked_project_link
(
forked_to_project_id:
fork_project
.
id
,
forked_from_project_id:
project
.
id
)
fork_project
.
save
end
it
"skips levels"
do
expect
(
skip_level?
(
fork_project
,
Gitlab
::
VisibilityLevel
::
PUBLIC
)).
to
be_truthy
expect
(
skip_level?
(
fork_project
,
Gitlab
::
VisibilityLevel
::
INTERNAL
)).
to
be_falsey
expect
(
skip_level?
(
fork_project
,
Gitlab
::
VisibilityLevel
::
PRIVATE
)).
to
be_falsey
end
end
describe
"non-forked project"
do
let
(
:project
)
{
create
(
:project
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
}
it
"skips levels"
do
expect
(
skip_level?
(
project
,
Gitlab
::
VisibilityLevel
::
PUBLIC
)).
to
be_falsey
expect
(
skip_level?
(
project
,
Gitlab
::
VisibilityLevel
::
INTERNAL
)).
to
be_falsey
expect
(
skip_level?
(
project
,
Gitlab
::
VisibilityLevel
::
PRIVATE
)).
to
be_falsey
end
end
describe
"Snippet"
do
let
(
:snippet
)
{
create
(
:snippet
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
}
it
"skips levels"
do
expect
(
skip_level?
(
snippet
,
Gitlab
::
VisibilityLevel
::
PUBLIC
)).
to
be_falsey
expect
(
skip_level?
(
snippet
,
Gitlab
::
VisibilityLevel
::
INTERNAL
)).
to
be_falsey
expect
(
skip_level?
(
snippet
,
Gitlab
::
VisibilityLevel
::
PRIVATE
)).
to
be_falsey
end
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